In case you missed the announcement: The Alteryx One Fall Release is here! Learn more about the new features and capabilities here
ACT NOW: The Alteryx team will be retiring support for Community account recovery and Community email-change requests Early 2026. Make sure to check your account preferences in my.alteryx.com to make sure you have filled out your security questions. Learn more here
Start Free Trial

Alteryx Designer Desktop Discussions

Find answers, ask questions, and share expertise about Alteryx Designer Desktop and Intelligence Suite.

Python API call ?

Hamder83
11 - Bolide

Hi 

I know this is not directly alteryx related.

but I dont know were else to ask.

We have an API we are using a lot, we also have an UI. But using the UI we can only extract 10.000 records at the time.
There is no limit on the api.

I have found a small piece of code - but i need to add a nextpagetoken.

My code looks like this:

login_url = 'https://api.ubsend.io/v1/auth/login'
username = 'xxxxx'
password = 'xxxxx'
omitClaims = "true"

session = requests.Session()
session.headers['Accept'] = "application/json; charset=UTF-8"

response = session.post(
login_url,
json={'username': username, 'password': password},
headers={'VERSION': '3'},
)
response.raise_for_status()
response_data = response.json()
print(response_data)





This gives me the AccessToken.

Then I call:


getevents = 'https://api.ubsend.io/v1/reporting/shipments?'
data ={'client_id': 13490, 'created_after': '2020-05-01T00:00', 'created_before': '2021-05-02T00:00'}
req.prepare_url(getevents, data)

events = requests.get(req.url,
headers={'Authorization' : 'Bearer ' + response_data['accessToken'], 'Content-Type': 'application/json'}
)
events.json()

Which returns:

 'nextPageToken': 'NjA4ZDc3YzNkMjBjODgyYjBhMWVkMTVkLDE2MTk4ODM5NzA3MDE='}


So I want to loop my script - until nextPageToken is blank ....



Any thoughts?

1 REPLY 1
BrandonB
Alteryx
Alteryx

You can do this in Python as well, but you can leverage an iterative macro to accomplish the same thing. Please see this post as reference: https://community.alteryx.com/t5/Alteryx-Designer-Discussions/Iterative-macro-for-API-pagination-ret... 

Labels
Top Solution Authors