Home > Enterprise >  Need help to understand the documentation of Sentry API
Need help to understand the documentation of Sentry API

Time:09-13

I am making an API request to the sentry API, like this:

_URL = "https://sentry.io/api/0/projects/aaaa-7y/aaaa/issues/"
headers = {'Authorization': 'Bearer 11111111111111111111111', 'Content-Type': 'application/json'}
params = {"statsPeriod":"24h", 'cursor':'100:-1:1'}

r = requests.get(url = _URL, headers = headers, params=params, verify=False) 
data = r.json()

and I realized that I am only getting 100 results despite I have more in the endpoint UI. According to the documentation, I should use the pagination: enter image description here

It sends this as HTTP header, not in response/JSON.

You need:

link = r.headers['Link']        # it raises error when `Link` doesn't exist

or safer

link = r.headers.get('Link')    # it gives `None` when `Link` doesn't exist

CodePudding user response:

Thanks for your support. For anyone's reference with Sentry's API, I ended up doing this to fetch data and paginate:

data_set=[]

    while r.links['next']['results'] == "true":
        r = requests.get(r.links['next']['url'], headers = headers, params=params, verify=False) 
        data = r.json()
        for req in data:
            data_set.append(req)
  • Related