I’m trying to figure out how to query all active Projects and secondly query the Assets of a project, using the project name.
Below is a snippet of code demonstrating this exact feature in Python. However I would like to do this using the REST Api. I’ve attempted to look into the docs and create this query but have struggled to understand it. My goal is to use the rest api so i can place my queries in javascript.
tickets_getEntitiesProjects.py (2.2 KB)
Any help would be greatly appreciated. I’ve create a trial shotgun website to test this stuff one. Please be kind as I’m sharing my credentials for it.
################################################################################
# Imports
################################################################################
import os, sys, pprint
import shotgun_api3
################################################################################
# Variables
################################################################################
SERVER_PATH = 'https://somesite.shotgunstudio.com/'
SCRIPT_NAME = 'aname'
SCRIPT_KEY = 'somekey'
sg = shotgun_api3.Shotgun(SERVER_PATH, script_name=SCRIPT_NAME, api_key=SCRIPT_KEY)
################################################################################
# Methods
################################################################################
def getProjectEntitiesByCategory(project='', category=''):
'''
Returns a list of entities in the shotgun project VFXP.
'''
filters = [
['sg_category','is', category],
['project.Project.name','is', project]
]
fields = ['code', 'project']
results = sg.find('Asset', filters, fields)
results = sorted(results, key=lambda k: k['code'].lower())
return results
def getProjects(category=''):
'''
Description:
Returns a list of projects
'''
filters = [
['sg_status','is', 'active']
]
fields = ['name', 'project']
results = sg.find('Project', filters, fields)
return results
################################################################################
# Testing
################################################################################
if __name__ == '__main__':
results = getProjectEntitiesByCategory('VFXP', 'Application')
pprint.pprint(results, indent=4)
results = getProjects('Application')
pprint.pprint(results, indent=4)