Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Example of how to query a large number of entities when paging is required.
import requests
import pprint
import json
import os
site_url = os.environ["SHOTGUN_SITE_URL"] # ie: https://foobar.shotgunstudio.com
headers = {
"Accept": "application/json",
"Content-Type": "application/x-www-form-urlencoded"
}
resp = requests.post(
"{0}{1}".format(site_url, "/api/v1/auth/access_token"),
data=dict(
username=os.environ["SHOTGUN_SITE_USERNAME"], # ie: jeff
password=os.environ["SHOTGUN_SITE_PASSWORD"], # your user's Shotgun password...
grant_type="password",
),
headers=headers,
)
resp_data = resp.json()
token = resp_data["access_token"]
headers = {
"Accept": "application/json",
"Authorization": "Bearer {0}".format(token),
}
resp = requests.get(
"{0}{1}".format(site_url, "/api/v1/entity/tasks"),
params=dict(
fields=["id"],
),
headers=headers,
)
raw_resp = resp.json()
tasks = raw_resp["data"]
while raw_resp["data"]:
resp = requests.get(
"{0}{1}".format(site_url, raw_resp["links"]["next"]),
headers=headers,
)
raw_resp = resp.json()
tasks.extend(raw_resp["data"])
pprint.pprint(tasks)
print "Num Assets: %s" % len(tasks)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment