Skip to content

Instantly share code, notes, and snippets.

@thebeeland
Created October 25, 2019 00:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thebeeland/602f1589e134e28410e05832b5b4f157 to your computer and use it in GitHub Desktop.
Save thebeeland/602f1589e134e28410e05832b5b4f157 to your computer and use it in GitHub Desktop.
An example of how to make use of pagination with Shotgun's rest api when doing a POST
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 = {
"Content-Type": "application/vnd+shotgun.api3_array+json",
"Accept": "application/json",
"Authorization": "Bearer {0}".format(token),
}
request_body = json.dumps({
"filters": [
["project.Project.name", "in", ["Big Buck Bunny"]]
],
"fields":["id", "content"]
})
resp = requests.post(
"{0}{1}".format(site_url, "/api/v1/entity/tasks/_search"),
data=request_body,
headers=headers,
)
raw_resp = resp.json()
tasks = raw_resp["data"]
while raw_resp["data"]:
resp = requests.post(
"{0}{1}".format(site_url, raw_resp["links"]["next"]),
data=request_body,
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