How to use Event API?

I’m trying to make a script using the Event API, but I can’t get it to work. The reason for using it, is that I need to monitor some events on my gateways. I have used the documentation found here

https://www.thethingsindustries.com/docs/reference/api/events/
https://www.thethingsindustries.com/docs/getting-started/events/

I’m able to get it to work with a curl command

curl https://tenant.eu1.cloud.thethings.industries/api/v3/events -X POST -H "Authorization: Bearer NNSXS.XXXXXX" -H "Accept: text/event-stream" --data '{"identifiers":[{"gateway_ids":{"gateway_id":"gw139"}}]}'

Since I want to store some of the events in a database, I have tried to set up a flow in Node-RED and also using a python script with no success.

The python script looks like this

import requests

auth_token = 'NNSXS.XXXXXX'

header = {'Authorization': 'Bearer ' + auth_token,
          'Accept': 'text/event-stream'}

payload = '{"identifiers":[{"gateway_ids":{"gateway_id":"gw139"}}]}'

url = 'https://tenant.eu1.cloud.thethings.industries/api/v3/events'
response = requests.post(url, headers=header, data=payload)
print(response.json())

After doing a little bit of research it looks like I need something called a SSE client, but after trying to use that in python and Node-RED - I still can’t get it to work.

Does anybody have any experience with this or can point me in the right direction :slight_smile: ?