Share
Explore

Workshop - Shotgrid API

Do you have python installed? Python 3.11 is a must! Use a package installer like Pypi
Install the shotgrip api:
Install the missing packages
Two ways of connecting to the data api, scripts or user login

Create a script connection
from shotgun_api3.shotgun import Shotgun
SG: Shotgun
SG = Shotgun("https://dae-vfx.shotgrid.autodesk.com", script_name="connect", api_key="sqpzhcmlsv5zvwjz_cfveHjlj")
Use random function to verify authentication: SG.schema_entity_read()
When connection is established, let’s do our first API database query:
filters = [['id', ‘is', 12369]]
SG.find(’Version’, filters)

Expand the query with extra data fields
filters = [['id', 'is', 12369]]
fields = [’user', sg_first_frame', sg_duration', ‘sg_last_frame’, ‘description’]
SG.find(’Version’, filters, fields)

Use nested data fields
filters = [['id', 'is', 12369]]
fields = [’user.HumanUser.email']
SG.find(’Version’, filters, fields)

Notice the notation of entities as dicts: Now change the filter
filters = [['sg_task’, 'is', {’type’: ‘Task’, ‘id’: 9688}]]
fields = [’code']
SG.find(’Version’, filters, fields)

Limit the return to one entity:
filters = [['sg_task’, 'is', {’type’: ‘Task’, ‘id’: 9688}]]
fields = [’code']
SG.find_one(’Version’, filters, fields)

Notice the version code, add a sorting:
order = [{'field_name': 'code', 'direction': 'desc'}]
SG.find_one('Version', filters, fields, order)

Create a version
Upload a thumbnail
Do so under your own user login: Apply the user authentication

Want to print your doc?
This is not the way.
Try clicking the ⋯ next to your doc name or using a keyboard shortcut (
CtrlP
) instead.