Listing orders gets 100 orders only

Hello,

When I try to get a list of all our orders using

url = "https://services.sentinel-hub.com/api/v1/dataimport/orders"

response = oauth.get(url)
response.raise_for_status()

print(len(response.json()['data']))

I always get only 100 orders. Is there a way to get the next 100 orders or get all orders all at once?

Hi Karim,

Referring to our API Reference documentation you can add the count query parameter to your request to list all your orders. By setting a large number to the upper limit to the number of items to retrieve you should be able to list all your orders in the response.

Hi William,

By setting count to any number larger than 100, I get the following response:

{'error': {'status': 400,
  'reason': 'Bad Request',
  'message': "Query parameter 'count' must be at most 100.",
  'code': 'COMMON_BAD_PAYLOAD'}}

However thank you for your response, by referring to the API docs, I found that I can get the next page of 100 orders by setting the parameter viewtoken to 100, 200, …

Hi Karim,

Yes, there will be limits on the results ‘count’ depending on the endpoint. To aid you in the future, I have attached the below code that shows how you list your results.

# get first 100 orders

resp = requests.get('https://services.sentinel-hub.com/api/v1/dataimport/orders', headers=headers).json()

# print out the number of hits and the "links" field of the response

print(len(resp['...']))

resp['links']

# nextToken was "100" in the previous response

# so we use that as the "viewtoken" query parameter to get the next page

resp = requests.get('https://services.sentinel-hub.com/api/v1/dataimport/orders?viewtoken=100', headers=headers).json()

print(len(resp['...']))

resp['links']

Naturally, if you have fewer than 100 orders then you can change the viewtoken parameter to a lower number such as 10.

Hope that this code will be useful to you and others in the future.

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.