### Upload Multipart - GET Request (Go net/http) Source: https://developers.shotgridsoftware.com/rest-api/index Provides a Go example using the 'net/http' package to make a GET request for multi-part uploads. It shows how to set headers and execute the request. ```go package main import ( "bytes" "net/http" ) func main() { headers := map[string][]string{ "Accept": []string{"application/json"}, "Authorization": []string{"Bearer {access-token}"}, } data := bytes.NewBuffer([]byte{jsonReq}) req, err := http.NewRequest("GET", "https://shotgunlocalhost.com/api/v1.1/entity/{entity}/{record_id}/_upload/multipart", data) req.Header = headers client := &http.Client{} resp, err := client.Do(req) // ... } ``` -------------------------------- ### Get Upload URLs and Response Example Source: https://developers.shotgridsoftware.com/rest-api/index Shows an example JSON response containing URLs for uploading files and getting the next part of a multi-part upload. This response is typically received after initiating an upload process. ```json { "links": { "upload": "https://yoursite.shotgunstudio.com/api/v1.1/entity/versions/1/sg_uploaded_movie/_upload?filename=logo.png&signature=OaHsK%2BrkZk5w1GxgxI3aNmJ0H3Y%3D&user_id=1&user_type=HumanUser&expiration=1532618412", "get_next_part": "/api/v1.1/entity/versions/1/sg_uploaded_movie/_upload/multipart?filename=logo.png&part_number=2×tamp=2019-04-16T21%3A23%3A36Z&upload_id=S.04OooF4_fxTPecfUd9XcifdgsduUH2.JEdk7vus4kswJj6l&upload_type=Attachment" } } ``` -------------------------------- ### Get User's Following List with Python Requests Source: https://developers.shotgridsoftware.com/rest-api/index This Python example demonstrates how to fetch the user's following list using the requests library. It sets up the necessary headers and makes a GET request to the API. ```python import requests headers = { 'Accept': 'application/json', 'Authorization': 'Bearer {access-token}' } r = requests.get('https://shotgunlocalhost.com/api/v1.1/entity/human_users/{user_id}/following', params={...}, headers = headers) print r.json() ``` -------------------------------- ### Get Followers using http.Client (Go) Source: https://developers.shotgridsoftware.com/rest-api/index Provides a Go example for fetching followers using the standard net/http package. It demonstrates creating a request, setting headers, and executing the request with a client. ```go package main import ( "bytes" "net/http" ) func main() { headers := map[string][]string{ "Accept": []string{"application/json"}, "Authorization": []string{"Bearer {access-token}"}, } data := bytes.NewBuffer([]byte{jsonReq}) req, err := http.NewRequest("GET", "https://shotgunlocalhost.com/api/v1.1/entity/{entity}/{record_id}/followers", data) req.Header = headers client := &http.Client{} resp, err := client.Do(req) // ... } ``` -------------------------------- ### Initiate Multipart Upload with Python (Requests) Source: https://developers.shotgridsoftware.com/rest-api/index This Python example uses the `requests` library to perform a GET request for multipart upload initiation. It demonstrates setting headers and passing query parameters effectively. ```python import requests headers = { 'Accept': 'application/json', 'Authorization': 'Bearer {access-token}' } r = requests.get('https://shotgunlocalhost.com/api/v1.1/entity/{entity}/{record_id}/{field_name}/_upload/multipart', params={ 'filename': 'string', 'upload_type': 'Attachment', 'timestamp': 'string', 'upload_id': 'string', 'part_number': '0' }, headers = headers) print r.json() ``` -------------------------------- ### Retrieve Site Schema using Go net/http Source: https://developers.shotgridsoftware.com/rest-api/index This Go example demonstrates fetching the site schema using the standard net/http package. It constructs an HTTP GET request with custom headers and executes it. ```go package main import ( "bytes" "net/http" ) func main() { headers := map[string][]string{ "Accept": []string{"application/json"}, "Authorization": []string{"Bearer {access-token}"}, } data := bytes.NewBuffer([]byte{jsonReq}) req, err := http.NewRequest("GET", "https://shotgunlocalhost.com/api/v1.1/schema", data) req.Header = headers client := &http.Client{} resp, err := client.Do(req) // ... } ``` -------------------------------- ### Get Followers using Guzzle (PHP) Source: https://developers.shotgridsoftware.com/rest-api/index Demonstrates fetching followers using Guzzle HTTP client in PHP. This example includes setting headers, making a GET request, and handling potential exceptions. ```php 'application/json', 'Authorization' => 'Bearer {access-token}', ); $client = new \GuzzleHttp\Client(); // Define array of request body. $request_body = array(); try { $response = $client->request('GET','https://shotgunlocalhost.com/api/v1.1/entity/{entity}/{record_id}/followers', array( 'headers' => $headers, 'json' => $request_body, ) ); print_r($response->getBody()->getContents()); } catch (\GuzzleHttp\Exception\BadResponseException $e) { // handle exception or api errors. print_r($e->getMessage()); } // ... ``` -------------------------------- ### Get Followers using RestClient (Ruby) Source: https://developers.shotgridsoftware.com/rest-api/index Provides a Ruby example for fetching followers using the 'rest-client' gem. It makes a GET request with specified headers and parses the JSON response. ```ruby require 'rest-client' require 'json' headers = { 'Accept' => 'application/json', 'Authorization' => 'Bearer {access-token}', 'params' => { } } result = RestClient.get 'https://shotgunlocalhost.com/api/v1.1/entity/{entity}/{record_id}/followers', headers p JSON.parse(result) ``` -------------------------------- ### Retrieve Webhook Details using Go HTTP Client Source: https://developers.shotgridsoftware.com/rest-api/index Provides a Go example for retrieving webhook details using the net/http package. It constructs a GET request with specified headers. ```go package main import ( "bytes" "net/http" ) func main() { headers := map[string][]string{ "Accept": []string{"application/json"}, "Authorization": []string{"Bearer {access-token}"}, } data := bytes.NewBuffer([]byte{jsonReq}) req, err := http.NewRequest("GET", "https://shotgunlocalhost.com/api/v1.1/webhook/hooks/{record_uuid}", data) req.Header = headers client := &http.Client{} resp, err := client.Do(req) // ... }) ``` -------------------------------- ### List Webhook Deliveries with Python Requests Source: https://developers.shotgridsoftware.com/rest-api/index An example using Python's requests library to fetch webhook deliveries. It demonstrates setting headers and parameters for the GET request and printing the JSON response. ```python import requests headers = { 'Accept': 'application/json', 'Authorization': 'Bearer {access-token}' } r = requests.get('https://shotgunlocalhost.com/api/v1.1/webhook/hooks/{hook_id}/deliveries', params={}, headers = headers) print r.json() ``` -------------------------------- ### ShotGrid SchemaEntitiesResponse Example Source: https://developers.shotgridsoftware.com/rest-api/index An example of the SchemaEntitiesResponse, which lists various entities available in the ShotGrid API and their visibility. ```json { "data": { "ActionMenuItem": { "name": { "value": "Action Menu Item", "editable": false }, "visible": { "value": true, "editable": false } }, "ApiUser": { "name": { "value": "Script", "editable": false }, "visible": { "value": true, "editable": false } }, "ApiUserProjectConnection": { "name": { "value": "Api User Project Connection", "editable": false }, "visible": { "value": true, "editable": false } }, "AppWelcomeUserConnection": { "name": { "value": "App Welcome User Connection", "editable": false }, "visible": { "value": true, "editable": false } }, "Asset": { "name": { "value": "Asset", "editable": false }, "visible": { "value": true, "editable": false } } }, "links": { "self": "/api/v1.1/schema" } } ``` -------------------------------- ### Read Record Relationship using Go Source: https://developers.shotgridsoftware.com/rest-api/index Provides a Go example for fetching record relationships using the net/http package. This illustrates making authenticated GET requests in Go. ```go package main import ( "bytes" "net/http" ) func main() { headers := map[string][]string{ "Accept": []string{"application/json"}, "Authorization": []string{"Bearer {access-token}"}, } data := bytes.NewBuffer([]byte{jsonReq}) req, err := http.NewRequest("GET", "https://shotgunlocalhost.com/api/v1.1/entity/{entity}/{record_id}/relationships/{related_field}", data) req.Header = headers client := &http.Client{} resp, err := client.Do(req) // ... } ``` -------------------------------- ### ShotGrid Batch Request Body Example Source: https://developers.shotgridsoftware.com/rest-api/index Illustrates the structure of the JSON request body for batch operations. It shows an example of creating a project with specific fields. ```json { "requests": [ { "request_type": "create", "entity": "Project", "data": { "code": "new project" }, "options": { "fields": [ "code" ] } } ] } ``` -------------------------------- ### Retrieve Entity Data using Go Source: https://developers.shotgridsoftware.com/rest-api/index Provides a Go example for making a GET request to the ShotGrid REST API to retrieve entity data. It demonstrates setting up HTTP headers and making the request using the http client. ```go package main import ( "bytes" "net/http" ) func main() { headers := map[string][]string{ "Accept": []string{"application/json"}, "Authorization": []string{"Bearer {access-token}"}, } data := bytes.NewBuffer([]byte{jsonReq}) req, err := http.NewRequest("GET", "https://shotgunlocalhost.com/api/v1.1/entity/{entity}", data) req.Header = headers client := &http.Client{} resp, err := client.Do(req) // ... } ``` -------------------------------- ### Example Response for Note Thread Contents Source: https://developers.shotgridsoftware.com/rest-api/index An example of a successful (200 OK) response when retrieving thread contents for a Note entity. It includes sample data for notes and replies within the thread. ```json { "data": [ { "type": "Note", "id": 1, "content": "Hello, this is my note", "created_at": "2006-04-10T14:19:57Z", "created_by": null }, { "type": "Reply", "id": 1, "content": "admin reply", "user": { "id": 8, "name": "Admin User", "type": "HumanUser", "image": null }, "created_at": "2007-04-10T14:19:57Z" } ], "links": { "self": "/api/v1.1/entity/notes/1/thread_contents" } } ``` -------------------------------- ### Example Access Token Response Source: https://developers.shotgridsoftware.com/rest-api/index This is an example JSON response received after successfully requesting an access token using client credentials. It includes the token type, the access token itself, its expiration time, and a refresh token. ```json { "token_type": "Bearer", "access_token": "eyJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJsb2NhbGhvc3Q6ODg4OCIsImF1ZCI6ImxvY2FsaG9zdDo4ODg4IiwiZXhwIjoxNTE5OTY0MDUxLCJpYXQiOjE1MTk5NjA0NTEsInBheWxvYWQiOiJFeGFtcGxlIHRva2VuISJ9.HEpJCzma9ftj-hfbR3HySoLsGHs2mH0qyHGLOVOmjzI", "expires_in": 3600, "refresh_token": "eyJhbGciOiJIUzI1NiJ9.eyJqdGkiOiJiN2JmMGMzMi00MWM5LTExZTgtODJkMi0wMjQyYWMxOTAwMDgiLCJpc3MiOiJsb2NhbGhvc3Q6ODg4OCIsImF1ZCI6ImxvY2FsaG9zdDo4ODg4L2FwaS92MS9hdXRoL2FjY2Vzc190b2tlbiIsImV4cCI6MTUyNDUyNDMyNiwiaWF0IjoxNTIzOTE5NTI2LCAiZGF0YSI6ICJub3RfaW5mb19mb3JfeW91In0=.z1TxS33vaVOpywxGe5E2NREG3id1Q8b5wxPcF84qG60" } ``` -------------------------------- ### Initiate Multipart Upload with Go Source: https://developers.shotgridsoftware.com/rest-api/index This Go example illustrates initiating a multipart upload to ShotGrid using the standard `net/http` package. It shows how to set up the request with appropriate headers. ```go package main import ( "bytes" "net/http" ) func main() { headers := map[string][]string{ "Accept": []string{"application/json"}, "Authorization": []string{"Bearer {access-token}"}, } data := bytes.NewBuffer([]byte{jsonReq}) req, err := http.NewRequest("GET", "https://shotgunlocalhost.com/api/v1.1/entity/{entity}/{record_id}/{field_name}/_upload/multipart", data) req.Header = headers client := &http.Client{} resp, err := client.Do(req) // ... } ``` -------------------------------- ### Authenticate with ShotGrid REST API using Go Source: https://developers.shotgridsoftware.com/rest-api/index Shows a Go example for authenticating with the ShotGrid REST API using the `net/http` package. It demonstrates setting headers and making the POST request. ```go package main import ( "bytes" "net/http" ) func main() { headers := map[string][]string{ "Content-Type": []string{"application/x-www-form-urlencoded"}, "Accept": []string{"application/json"}, } data := bytes.NewBuffer([]byte{jsonReq}) req, err := http.NewRequest("POST", "https://shotgunlocalhost.com/api/v1.1/auth/access_token", data) req.Header = headers client := &http.Client{} resp, err := client.Do(req) // ... } ``` -------------------------------- ### Upload Multipart - GET Request (Java URLConnection) Source: https://developers.shotgridsoftware.com/rest-api/index Shows a Java example using URLConnection to perform a GET request for multi-part uploads. It demonstrates setting request method and reading the response. ```java URL obj = new URL("https://shotgunlocalhost.com/api/v1.1/entity/{entity}/{record_id}/_upload/multipart?filename=string&upload_type=Attachment×tamp=string&upload_id=string&part_number=0"); HttpURLConnection con = (HttpURLConnection) obj.openConnection(); con.setRequestMethod("GET"); int responseCode = con.getResponseCode(); BufferedReader in = new BufferedReader( new InputStreamReader(con.getInputStream())); String inputLine; StringBuffer response = new StringBuffer(); while ((inputLine = in.readLine()) != null) { response.append(inputLine); } in.close(); System.out.println(response.toString()); ``` -------------------------------- ### Get ShotGrid API Version with Java Source: https://developers.shotgridsoftware.com/rest-api/index Provides a Java example for retrieving the ShotGrid API version using HttpURLConnection. It sets the request method to GET and reads the response from the input stream. ```java URL obj = new URL("https://shotgunlocalhost.com/api/v1.1/"); HttpURLConnection con = (HttpURLConnection) obj.openConnection(); con.setRequestMethod("GET"); int responseCode = con.getResponseCode(); BufferedReader in = new BufferedReader( new InputStreamReader(con.getInputStream())); String inputLine; StringBuffer response = new StringBuffer(); while ((inputLine = in.readLine()) != null) { response.append(inputLine); } in.close(); System.out.println(response.toString()); ``` -------------------------------- ### Go for Hierarchy Search Source: https://developers.shotgridsoftware.com/rest-api/index Shows how to perform a hierarchy search using Go's net/http package. This example demonstrates creating a POST request, setting headers, and executing the request. ```go package main import ( "bytes", "net/http", ) func main() { headers := map[string][]string{ "Content-Type": []string{"application/json"}, "Accept": []string{"application/json"}, "Authorization": []string{"Bearer {access-token}"}, } data := bytes.NewBuffer([]byte{jsonReq}) req, err := http.NewRequest("POST", "https://shotgunlocalhost.com/api/v1.1/hierarchy/_search", data) req.Header = headers client := &http.Client{} resp, err := client.Do(req) // ... } ``` -------------------------------- ### Retrieve Site Schema using Python Requests Source: https://developers.shotgridsoftware.com/rest-api/index This Python example uses the Requests library to get the site schema. It defines the required headers and makes a GET request, printing the JSON response. ```python import requests headers = { 'Accept': 'application/json', 'Authorization': 'Bearer {access-token}' } r = requests.get('https://shotgunlocalhost.com/api/v1.1/schema', params={}, headers = headers) print r.json() ``` -------------------------------- ### Execute Batch Operations via Go http.Client Source: https://developers.shotgridsoftware.com/rest-api/index Demonstrates batch operations using Go's standard http client. It shows setting headers and performing the POST request. ```go package main import ( "bytes" "net/http" ) func main() { headers := map[string][]string{ "Content-Type": []string{"application/json"}, "Accept": []string{"application/json"}, "Authorization": []string{"Bearer {access-token}"}, } data := bytes.NewBuffer([]byte{jsonReq}) req, err := http.NewRequest("POST", "https://shotgunlocalhost.com/api/v1.1/entity/_batch", data) req.Header = headers client := &http.Client{} resp, err := client.Do(req) // ... } ``` -------------------------------- ### Upload Multipart - GET Request (PHP Guzzle) Source: https://developers.shotgridsoftware.com/rest-api/index Provides a PHP example using the Guzzle HTTP client to make a GET request for multi-part uploads. It includes setting headers and handling potential exceptions. ```php 'application/json', 'Authorization' => 'Bearer {access-token}', ); $client = new \GuzzleHttp\Client(); // Define array of request body. $request_body = array(); try { $response = $client->request('GET','https://shotgunlocalhost.com/api/v1.1/entity/{entity}/{record_id}/_upload/multipart', array( 'headers' => $headers, 'json' => $request_body, ) ); print_r($response->getBody()->getContents()); } catch (\GuzzleHttp\Exception\BadResponseException $e) { // handle exception or api errors. print_r($e->getMessage()); } // ... ``` -------------------------------- ### Create ShotGrid Webhook with Go Source: https://developers.shotgridsoftware.com/rest-api/index An example in Go showing how to create a ShotGrid webhook using the net/http package. It constructs a POST request with appropriate headers and sends it to the API. ```go package main import ( "bytes" "net/http" ) func main() { headers := map[string][]string{ "Content-Type": []string{"application/json"}, "Accept": []string{"application/json"}, "Authorization": []string{"Bearer {access-token}"}, } data := bytes.NewBuffer([]byte{jsonReq}) req, err := http.NewRequest("POST", "https://shotgunlocalhost.com/api/v1.1/webhook/hooks", data) req.Header = headers client := &http.Client{} resp, err := client.Do(req) // ... } ``` -------------------------------- ### Read Note Thread Contents with Java Source: https://developers.shotgridsoftware.com/rest-api/index Provides a Java example for retrieving note thread contents using HttpURLConnection. It sets the request method to GET, retrieves the response code, and reads the input stream to get the content. ```java URL obj = new URL("https://shotgunlocalhost.com/api/v1.1/entity/notes/{record_id}/thread_contents"); HttpURLConnection con = (HttpURLConnection) obj.openConnection(); con.setRequestMethod("GET"); int responseCode = con.getResponseCode(); BufferedReader in = new BufferedReader( new InputStreamReader(con.getInputStream())); String inputLine; StringBuffer response = new StringBuffer(); while ((inputLine = in.readLine()) != null) { response.append(inputLine); } in.close(); System.out.println(response.toString()); ``` -------------------------------- ### Assign Subscriptions via Go Source: https://developers.shotgridsoftware.com/rest-api/index Go language example for assigning user subscriptions using the net/http package. It sets up headers, creates a POST request with a JSON buffer, and sends it. ```go package main import ( "bytes" "net/http" ) func main() { headers := map[string][]string{ "Content-Type": []string{"application/json"}, "Accept": []string{"application/json"}, "Authorization": []string{"Bearer {access-token}"}, } data := bytes.NewBuffer([]byte{jsonReq}) req, err := http.NewRequest("POST", "https://shotgunlocalhost.com/api/v1.1/subscription_seat/user_subscriptions", data) req.Header = headers client := &http.Client{} resp, err := client.Do(req) // ... } ``` -------------------------------- ### Get ShotGrid API Version with Ruby Source: https://developers.shotgridsoftware.com/rest-api/index Provides an example of fetching the ShotGrid API version using Ruby's 'rest-client' and 'json' gems. It constructs the necessary headers and makes a GET request, then parses the JSON response. ```ruby require 'rest-client' require 'json' headers = { 'Accept' => 'application/json', 'params' => { } } result = RestClient.get 'https://shotgunlocalhost.com/api/v1.1/', headers p JSON.parse(result) ``` -------------------------------- ### Example API Response (JSON) Source: https://developers.shotgridsoftware.com/rest-api/index A sample JSON response structure for a successful API request, demonstrating paginated data and links for navigation. ```json { "data": [ { "id": 82, "type": "Project", "attributes": { "name": "Demo Project" }, "relationships": { "users": [ { "id": 19, "name": "Artist 1", "type": "HumanUser" }, { "id": 18, "name": "Artist 2", "type": "HumanUser" } ], "created_by": { "id": 24, "name": "Flow Production Tracking Support", "type": "HumanUser" } }, "links": { "self": "/api/v1.1/projects/82" } } ], "links": { "self": "/api/v1.1/projects?page%5Bnumber%5D=2&page%5Bsize%5D=500", "next": "/api/v1.1/projects?page%5Bnumber%5D=3&page%5Bsize%5D=500", "prev": "/api/v1.1/projects?page%5Bnumber%5D=1&page%5Bsize%5D=500" } } ``` -------------------------------- ### Get Schema with Locale Header (JavaScript/jQuery) Source: https://developers.shotgridsoftware.com/rest-api/index Provides a JavaScript example using jQuery's AJAX method to make a GET request for the API schema, enabling localization via the 'Locale: auto' header. This is suitable for web applications. ```javascript var headers = { 'Accept':'application/json', 'Authorization':'Bearer {access-token}', 'Locale':'auto' }; $.ajax({ url: 'https://yoursite.shotgunstudio.com/api/v1.1/schema', method: 'get', headers: headers, success: function(data) { console.log(JSON.stringify(data)); } }); ``` -------------------------------- ### Get Schema with Locale URL Parameter (JavaScript/jQuery) Source: https://developers.shotgridsoftware.com/rest-api/index Shows a JavaScript example using jQuery's AJAX method to make a GET request for the API schema, enabling localization by including '?locale=auto' in the URL. This approach is straightforward for web clients. ```javascript var headers = { 'Accept':'application/json', 'Authorization':'Bearer {access-token}' }; $.ajax({ url: 'https://yoursite.shotgunstudio.com/api/v1.1/schema?locale=auto', method: 'get', headers: headers, success: function(data) { console.log(JSON.stringify(data)); } }); ``` -------------------------------- ### Read one record (Shell) Source: https://developers.shotgridsoftware.com/rest-api/index Example of fetching a single entity record by its ID using a GET request with cURL. Requires the access token. ```Shell curl -X GET https://api.shotgrid.io/v1/entity/PROJECT/123 \ -H "Authorization: Bearer YOUR_ACCESS_TOKEN" ``` -------------------------------- ### List Webhooks via Go net/http Source: https://developers.shotgridsoftware.com/rest-api/index A Go language example for retrieving webhooks using the standard net/http package. It constructs a request with specified headers and executes it using an HTTP client. ```go package main import ( "bytes" "net/http" ) func main() { headers := map[string][]string{ "Accept": []string{"application/json"}, "Authorization": []string{"Bearer {access-token}"}, } data := bytes.NewBuffer([]byte{jsonReq}) req, err := http.NewRequest("GET", "https://shotgunlocalhost.com/api/v1.1/webhook/hooks", data) req.Header = headers client := &http.Client{} resp, err := client.Do(req) // ... } ``` -------------------------------- ### Follow Entity using Go net/http Source: https://developers.shotgridsoftware.com/rest-api/index Shows how to follow an entity using Go's net/http package. It constructs a POST request with specified headers and data, then executes it using an HTTP client. ```go package main import ( "bytes" "net/http" ) func main() { headers := map[string][]string{ "Content-Type": []string{"application/json"}, "Accept": []string{"application/json"}, "Authorization": []string{"Bearer {access-token}"}, } data := bytes.NewBuffer([]byte{jsonReq}) req, err := http.NewRequest("POST", "https://shotgunlocalhost.com/api/v1.1/entity/human_users/{user_id}/follow", data) req.Header = headers client := &http.Client{} resp, err := client.Do(req) // ... } ``` -------------------------------- ### Requesting Access Token (Python) Source: https://developers.shotgridsoftware.com/rest-api/index Provides a Python example using the `requests` library to get an access token. This is a common method for server-side integrations. ```Python import requests url = "https://api.shotgrid.io/v1/oauth2/token" data = { "grant_type": "client_credentials", "client_id": "YOUR_CLIENT_ID", "client_secret": "YOUR_CLIENT_SECRET" } headers = { "Content-Type": "application/x-www-form-urlencoded" } response = requests.post(url, data=data, headers=headers) access_token = response.json().get("access_token") print(f"Access Token: {access_token}") ``` -------------------------------- ### Read Site Preferences (PHP) Source: https://developers.shotgridsoftware.com/rest-api/index Get site preferences in PHP using Guzzle HTTP client. This example demonstrates setting headers and handling potential API errors. ```php 'application/json', 'Authorization' => 'Bearer {access-token}', ); $client = new \GuzzleHttp\Client(); // Define array of request body. $request_body = array(); try { $response = $client->request('GET','https://shotgunlocalhost.com/api/v1.1/preferences', array( 'headers' => $headers, 'json' => $request_body, ) ); print_r($response->getBody()->getContents()); } catch (\GuzzleHttp\Exception\BadResponseException $e) { // handle exception or api errors. print_r($e->getMessage()); } // ... ``` -------------------------------- ### Upload file using Go Source: https://developers.shotgridsoftware.com/rest-api/index Shows how to upload a file to ShotGrid using Go's `net/http` package. This example demonstrates creating a new request, setting headers, and executing the request with an HTTP client. ```go package main import ( "bytes" "net/http" ) func main() { headers := map[string][]string{ "Accept": []string{"application/json"}, "Authorization": []string{"Bearer {access-token}"}, } data := bytes.NewBuffer([]byte{jsonReq}) req, err := http.NewRequest("GET", "https://shotgunlocalhost.com/api/v1.1/entity/{entity}/{record_id}/_upload", data) req.Header = headers client := &http.Client{} resp, err := client.Do(req) // ... } ``` -------------------------------- ### Create ShotGrid Webhook with Ruby Source: https://developers.shotgridsoftware.com/rest-api/index Provides a Ruby example for creating a ShotGrid webhook using the 'rest-client' and 'json' gems. It demonstrates how to configure headers and send a POST request. ```ruby require 'rest-client' require 'json' headers = { 'Content-Type' => 'application/json', 'Accept' => 'application/json', 'Authorization' => 'Bearer {access-token}', 'params' => { } } body = { } result = RestClient.post 'https://shotgunlocalhost.com/api/v1.1/webhook/hooks', body, headers p JSON.parse(result) ``` -------------------------------- ### ShotGrid API - Search Records (Go) Source: https://developers.shotgridsoftware.com/rest-api/index This Go example shows how to perform a search request to the ShotGrid API using the net/http package. It configures headers and sends the request. ```go package main import ( "bytes" "net/http" ) func main() { headers := map[string][]string{ "Content-Type": []string{"application/vnd+shotgun.api3_array+json"}, "Accept": []string{"application/json"}, "Authorization": []string{"Bearer {access-token}"}, } data := bytes.NewBuffer([]byte{jsonReq}) req, err := http.NewRequest("POST", "https://shotgunlocalhost.com/api/v1.1/entity/{entity}/_search", data) req.Header = headers client := &http.Client{} resp, err := client.Do(req) // ... } ``` -------------------------------- ### List Webhook Deliveries with Java HttpURLConnection Source: https://developers.shotgridsoftware.com/rest-api/index A Java example for retrieving webhook deliveries using HttpURLConnection. It sets the request method to GET, reads the response, and prints it to standard output. ```java URL obj = new URL("https://shotgunlocalhost.com/api/v1.1/webhook/hooks/{hook_id}/deliveries"); HttpURLConnection con = (HttpURLConnection) obj.openConnection(); con.setRequestMethod("GET"); int responseCode = con.getResponseCode(); BufferedReader in = new BufferedReader( new InputStreamReader(con.getInputStream())); String inputLine; StringBuffer response = new StringBuffer(); while ((inputLine = in.readLine()) != null) { response.append(inputLine); } in.close(); System.out.println(response.toString()); ``` -------------------------------- ### Read Site Preferences (Go) Source: https://developers.shotgridsoftware.com/rest-api/index Make a GET request to fetch site preferences in Go. This snippet shows how to set headers and create an HTTP client for the request. ```go package main import ( "bytes" "net/http" ) func main() { headers := map[string][]string{ "Accept": []string{"application/json"}, "Authorization": []string{"Bearer {access-token}"}, } data := bytes.NewBuffer([]byte{jsonReq}) req, err := http.NewRequest("GET", "https://shotgunlocalhost.com/api/v1.1/preferences", data) req.Header = headers client := &http.Client{} resp, err := client.Do(req) // ... } ``` -------------------------------- ### Get Upload URL for Field Source: https://developers.shotgridsoftware.com/rest-api/index This section provides code examples for retrieving an upload URL for a specific field within ShotGrid. It's crucial for initiating file uploads to the platform. ```python import os from shotgun_api3 import Shotgun # ShotGrid connection server_address = os.environ.get('SHOTGUN_SERVER') script_name = os.environ.get('SHOTGUN_SCRIPT_NAME') api_key = os.environ.get('SHOTGUN_API_KEY') sg = Shotgun(server_address, script_name=script_name, api_key=api_key) # Upload details entity_type = "CustomNonProjectEntity01" record_id = 1 field_name = "my_custom_field" file_name = "test.jpg" # Get upload URL result = sg.call_api( "/api/v1/entity/{}/upload_url".format(entity_type.lower() + "s"), "POST", { "entity_type": entity_type, "id": record_id, "field_name": field_name, "upload_filename": file_name, }, ) print(result) ``` -------------------------------- ### Create Record via Go Source: https://developers.shotgridsoftware.com/rest-api/index Create a new entity record using Go's net/http package. This snippet shows how to set up headers, create a request body, and perform the POST request. ```go package main import ( "bytes" "net/http" ) func main() { headers := map[string][]string{ "Content-Type": []string{"application/json"}, "Accept": []string{"application/json"}, "Authorization": []string{"Bearer {access-token}"}, } data := bytes.NewBuffer([]byte{jsonReq}) req, err := http.NewRequest("POST", "https://shotgunlocalhost.com/api/v1.1/entity/{entity}", data) req.Header = headers client := &http.Client{} resp, err := client.Do(req) // ... } ``` -------------------------------- ### Read One Field Schema (Python) Source: https://developers.shotgridsoftware.com/rest-api/index Provides a Python example using the requests library to get field schema details, including setting authorization and accept headers for the API call. ```python import requests headers = { 'Accept': 'application/json', 'Authorization': 'Bearer {access-token}' } r = requests.get('https://shotgunlocalhost.com/api/v1.1/schema/{entity}/fields/{field_name}', params={ }, headers = headers) print r.json() ``` -------------------------------- ### List Webhooks via Ruby RestClient Source: https://developers.shotgridsoftware.com/rest-api/index Provides a Ruby example using the RestClient gem to fetch webhook data. It sets up the necessary headers, including authorization, and parses the JSON response. ```ruby require 'rest-client' require 'json' headers = { 'Accept' => 'application/json', 'Authorization' => 'Bearer {access-token}', 'params' => { } } result = RestClient.get 'https://shotgunlocalhost.com/api/v1.1/webhook/hooks', headers p JSON.parse(result) ``` -------------------------------- ### Retrieve Schema Fields using Go Source: https://developers.shotgridsoftware.com/rest-api/index A Go example demonstrating how to make a GET request to the Shotgun API to retrieve schema fields. It sets up headers and uses `http.Client` to execute the request. ```go package main import ( "bytes" "net/http" ) func main() { headers := map[string][]string{ "Accept": []string{"application/json"}, "Authorization": []string{"Bearer {access-token}"}, } data := bytes.NewBuffer([]byte{jsonReq}) req, err := http.NewRequest("GET", "https://shotgunlocalhost.com/api/v1.1/schema/{entity}/fields", data) req.Header = headers client := &http.Client{} resp, err := client.Do(req) // ... } ``` -------------------------------- ### List Webhook Deliveries with Go net/http Source: https://developers.shotgridsoftware.com/rest-api/index Demonstrates how to fetch webhook deliveries using Go's standard net/http package. It constructs a GET request with appropriate headers and executes it using an HTTP client. ```go package main import ( "bytes" "net/http" ) func main() { headers := map[string][]string{ "Accept": []string{"application/json"}, "Authorization": []string{"Bearer {access-token}"}, } data := bytes.NewBuffer([]byte{jsonReq}) req, err := http.NewRequest("GET", "https://shotgunlocalhost.com/api/v1.1/webhook/hooks/{hook_id}/deliveries", data) req.Header = headers client := &http.Client{} resp, err := client.Do(req) // ... } ``` -------------------------------- ### Retrieve Entity Record with Python Source: https://developers.shotgridsoftware.com/rest-api/index This Python example uses the 'requests' library to make a GET request to the ShotGrid API for retrieving an entity record. It configures headers and prints the JSON response. ```python import requests headers = { 'Accept': 'application/json', 'Authorization': 'Bearer {access-token}' } r = requests.get('https://shotgunlocalhost.com/api/v1.1/entity/{entity}/{record_id}', params={}, headers = headers) print r.json() ``` -------------------------------- ### Summarize Entity via Go (net/http) Source: https://developers.shotgridsoftware.com/rest-api/index An example in Go using the net/http package to send a POST request for summarizing entity data. It constructs the request with headers and a buffer for the body. ```go package main import ( "bytes" "net/http" ) func main() { headers := map[string][]string{ "Content-Type": []string{"application/vnd+shotgun.api3_array+json"}, "Accept": []string{"application/json"}, "Authorization": []string{"Bearer {access-token}"}, } data := bytes.NewBuffer([]byte{jsonReq}) req, err := http.NewRequest("POST", "https://shotgunlocalhost.com/api/v1.1/entity/{entity}/_summarize", data) req.Header = headers client := &http.Client{} resp, err := client.Do(req) // ... } ``` -------------------------------- ### Retrieve Schema Fields using Ruby Source: https://developers.shotgridsoftware.com/rest-api/index Provides a Ruby example using the `rest-client` and `json` gems to make a GET request to the Shotgun API for schema field information. Includes necessary headers. ```ruby require 'rest-client' require 'json' headers = { 'Accept' => 'application/json', 'Authorization' => 'Bearer {access-token}', 'params' => { } } result = RestClient.get 'https://shotgunlocalhost.com/api/v1.1/schema/{entity}/fields', headers p JSON.parse(result) ``` -------------------------------- ### ShotGrid API Batch Create Request Example Source: https://developers.shotgridsoftware.com/rest-api/index Demonstrates how to create a new 'Project' entity in ShotGrid using a batch request. This JSON payload includes a single 'create' request with project details. ```json { "requests": [ { "request_type": "create", "entity": "Project", "data": { "code": "my_new_project", "name": "My New Project" } } ] } ``` -------------------------------- ### Make POST request to /hierarchy/_expand using Go net/http Source: https://developers.shotgridsoftware.com/rest-api/index Provides a Go example for sending a POST request to the ShotGrid REST API's /hierarchy/_expand endpoint using the standard 'net/http' package. It configures request headers and prepares the request body. This is a fundamental way to make HTTP requests in Go. ```go package main import ( "bytes" "net/http" ) func main() { headers := map[string][]string{ "Content-Type": []string{"application/json"}, "Accept": []string{"application/json"}, "Authorization": []string{"Bearer {access-token}"}, } data := bytes.NewBuffer([]byte{jsonReq}) req, err := http.NewRequest("POST", "https://shotgunlocalhost.com/api/v1.1/hierarchy/_expand", data) req.Header = headers client := &http.Client{} resp, err := client.Do(req) // ... } ``` -------------------------------- ### Upload Multipart - GET Request (Python Requests) Source: https://developers.shotgridsoftware.com/rest-api/index Demonstrates initiating a multi-part upload using Python's 'requests' library. It shows how to set headers and pass query parameters for the request. ```python import requests headers = { 'Accept': 'application/json', 'Authorization': 'Bearer {access-token}' } r = requests.get('https://shotgunlocalhost.com/api/v1.1/entity/{entity}/{record_id}/_upload/multipart', params={ 'filename': 'string', 'upload_type': 'Attachment', 'timestamp': 'string', 'upload_id': 'string', 'part_number': '0' }, headers = headers) print r.json() ``` -------------------------------- ### Get User's Following List with Go HTTP Client Source: https://developers.shotgridsoftware.com/rest-api/index This Go program demonstrates how to retrieve a user's following list using the standard net/http package. It constructs the request with appropriate headers. ```go package main import ( "bytes", "net/http", ) func main() { headers := map[string][]string{ "Accept": []string{"application/json"}, "Authorization": []string{"Bearer {access-token}"}, } data := bytes.NewBuffer([]byte{jsonReq}) req, err := http.NewRequest("GET", "https://shotgunlocalhost.com/api/v1.1/entity/human_users/{user_id}/following", data) req.Header = headers client := &http.Client{} resp, err := client.Do(req) // ... } ``` -------------------------------- ### Get User's Following List with jQuery AJAX Source: https://developers.shotgridsoftware.com/rest-api/index This example shows how to fetch the list of followed entities using jQuery's AJAX method. It configures the request with the correct URL, method, and headers. ```javascript var headers = { 'Accept':'application/json', 'Authorization':'Bearer {access-token}' }; $.ajax({ url: 'https://shotgunlocalhost.com/api/v1.1/entity/human_users/{user_id}/following', method: 'get', headers: headers, success: function(data) { console.log(JSON.stringify(data)); } }) ``` -------------------------------- ### Get Schema with Locale URL Parameter (Python) Source: https://developers.shotgridsoftware.com/rest-api/index Shows a Python example using the 'requests' library to retrieve the API schema with localization enabled by adding '?locale=auto' to the URL. This is a common and effective method for localization. ```python import requests headers = { 'Accept': 'application/json', 'Authorization': 'Bearer {access-token}' } r = requests.get('https://yoursite.shotgunstudio.com/api/v1.1/schema?locale=auto', params = {}, headers = headers) print r.json() ``` -------------------------------- ### Initiate Multipart Upload with Curl Source: https://developers.shotgridsoftware.com/rest-api/index This snippet demonstrates how to initiate a multipart upload to ShotGrid using the `curl` command-line tool. It specifies the endpoint, required headers including authorization, and query parameters for the upload. ```shell curl -X GET https://shotgunlocalhost.com/api/v1.1/entity/{entity}/{record_id}/{field_name}/_upload/multipart?filename=string&upload_type=Attachment×tamp=string&upload_id=string&part_number=0 \ -H 'Accept: application/json' \ -H 'Authorization: Bearer {access-token}' ``` ```http GET https://shotgunlocalhost.com/api/v1.1/entity/{entity}/{record_id}/{field_name}/_upload/multipart?filename=string&upload_type=Attachment×tamp=string&upload_id=string&part_number=0 HTTP/1.1 Host: shotgunlocalhost.com Accept: application/json ``` -------------------------------- ### Get Schema with Locale Header (Python) Source: https://developers.shotgridsoftware.com/rest-api/index Shows a Python example using the 'requests' library to fetch the API schema with localization enabled via the 'Locale: auto' header. This is a common approach for server-side integrations. ```python import requests headers = { 'Accept': 'application/json', 'Authorization': 'Bearer {access-token}', 'Locale': 'auto' } r = requests.get('https://yoursite.shotgunstudio.com/api/v1.1/schema', params = {}, headers = headers) print r.json() ```