Articles, Blog

Shotgun – API Overview


Hi, this is Isaac, and I’m gonna give you a quick overview of how to use the Shotgun Python API. The Shotgun API is simple but powerful and lets you easily access all the data on your server. In this screencast, I will show you how to set up your Shotgun server for API access, download the Python API Class and then find a project create a Shot, update its status and then delete it. These four methods Find, Create, Update and Delete are the core of the API. First, we need to set up the Shotgun server for API access. You can do this by going to the “Scripts” page in the Admin area and creating a new script. It’s a good idea to create a separate script entity for each different pipeline script as it allows you to track the history of what the scripts are doing, and even turn off access to a particular script on the server side if it’s doing something wrong. Let’s create a script called api_test and copy the application key as we’re going to need that to connect in the Python script later. Now download the Shotgun Python API Class. You can find it on our support site in the API documentation forums. I’m using version 3 of the API in the screencast. Now switch to the terminal and go to the directory where you downloaded the Python API file and open a Python shell. Import the Shotgun Class and then connect to your server. For this you will need three pieces of information, the server URL, the script name, and the application key that we copied earlier. Now that you have the SG connection, you can call methods on it. Let’s find a project whose name is “Demo Project”. You can see that what we get back by default is a dictionary with two fields ‘type’ and ‘id’. You will see this data structure all through the API, as this is how we uniquely identify all the entities on your server and makes links between them. Now that we have a reference to the project let’s create a Shot inside it. I’ll use this out Shot code, “sh 001” and set its project field to the demo project. Again I get back a dictionary that has ‘type’ and ‘id’ so I can later reference the Shot. If I switch over to the browser you can see this Shot in the web UI. Okay, now let’s go back and change its status to IP using the update method. Update the Shot whose ID is the one I just created and set the “sg_status_list” field to “ip”. Alright, now let’s switch back to the browser and see if that worked. Okay, and finally, let’s show the delete function. Now switch back to the API and delete the Shot we just created. Alright, and switch back to the browser and you can see that it’s gone. You can check out the API documentation area in the forums for all the details on the API, and we’d love to hear your feedback on anything that could make it better, and that’s it for the API Overview, see you in the forums.

Leave a Reply

Your email address will not be published. Required fields are marked *