Getting Asset name from entity ID

Hi All,

I am trying to get the name of asset using entity ID. I have daemon running which grabs the change in a entity field. The output is as below :

{‘attribute_name’: ‘sg_status_list’,
‘created_at’: datetime.datetime(2023, 10, 31, 15, 30, 12, tzinfo=<shotgun_api3.lib.sgtimezone.LocalTimezone object at 0x00000220041D28C0>),
‘entity’: {‘id’: 3468, ‘name’: ‘Art’, ‘type’: ‘Task’},
‘event_type’: ‘Shotgun_Task_Change’,
‘id’: 481322,
‘meta’: {‘attribute_name’: ‘sg_status_list’,
‘entity_id’: 3468,
‘entity_type’: ‘Task’,
‘field_data_type’: ‘status_list’,
‘new_value’: ‘ip’,
‘old_value’: ‘fin’,
‘type’: ‘attribute_change’},
‘project’: {‘id’: 70, ‘name’: ‘Demo: Animation’, ‘type’: ‘Project’},
‘session_uuid’: ‘88b497d0-77ca-11ee-83cd-0242ac110004’,
‘type’: ‘EventLogEntry’,
‘user’: {‘id’: 88, ‘name’: ‘huhu’, ‘type’: ‘HumanUser’}}

Now that I have above output as “event” dict I want to grab asset name and change the status of “model” or “rig” or “texture” dept to “wip”.

i have done following code :

asset_name = sg.find(‘Asset’, [[‘project’, ‘is’, {‘type’: ‘Project’, ‘id’: 70}], [‘entity’, ‘is’, {‘type’: ‘Step’, ‘id’: 3468, ‘name’: ‘Art’}]])

Giving following error :

Traceback (most recent call last):
File “d:\shotgrid\shotgrid_event_creator\”, line 617, in
asset_name = sg.find(‘Asset’, [[‘project’, ‘is’, {‘type’: ‘Project’, ‘id’: 70}], [‘entity’, ‘is’, {‘type’: ‘Task’, ‘id’: 3468, ‘name’: ‘Art’}]])
File “C:\Users\zabronic\AppData\Local\Programs\Python\Python310\lib\site-packages\shotgun_api3\”, line 1057, in find
result = self._call_rpc(“read”, params)
File “C:\Users\zabronic\AppData\Local\Programs\Python\Python310\lib\site-packages\shotgun_api3\”, line 3423, in _call_rpc
File “C:\Users\zabronic\AppData\Local\Programs\Python\Python310\lib\site-packages\shotgun_api3\”, line 3740, in _response_errors
raise Fault(sg_response.get(“message”, “Unknown Error”))
shotgun_api3.shotgun.Fault: API read() Asset.entity doesn’t exist:
“values”=>[{“type”=>“Step”, “id”=>3468, “name”=>“Art”}]}

A slightly different approach would work by querying the Task since the Asset is linked to the Task and not the other way around. Try something like this,

result = sg.find_one("Task", [['id', 'is', 3468]], ['entity'])
1 Like


Thanks for the solution. One more query of mine was, once I get the asset name then I need to change the status of some other step, like, model or rig or texture. Means to say can we find id of a particular task from entity name, for example “Alice”. Can you suggest code for it?

Second query is : Can we list out tasks/steps for a particular project?

Yes, for the first query you don’t specifically need the asset name, just use the entity. Continuing from above, if you use asset_entity = result['entity'] you can run a query like this,

asset_entity = result['entity']
# Get the task id for the "model" task
task_entity = sg.find_one("Task", [["content", "is", "model"], ["entity", "is", asset_entity]])

I’m not sure what you’re asking for in the second query. All the task entities of a project, or the list of task names available in a project?

Hey ,
First of all thanks for the code snippet.
And ya, all the task available for a project. Coz every project can have different set of task names for Asset, Sequence and Task. Actually I want to populate a combo-box with task names and ID on selection of a project.

Hey Sir,

with the help of your code I am now able to create a code which gives me all the tasks names. Following is the code that worked for me :
result = sg.find(“Task”, [[‘project’, ‘is’, {‘type’: ‘Project’, ‘id’: 70}]], [‘content’, ‘id’, ‘type’, ‘entity’])

Hi TJVoll,

I am new to SG coding and want some good stuff, may be its a document or videos you can suggest me to go through. I need to develop a better understanding what goes under the hood of SG workflow. What are entities, tasks, task-templates…etc means to SG.

I have gone through the docs as per my need, but that’s not the correct way to deep dive. So kindly request you to suggest some good reading or videos to learn.

Best Regards,

I think you’re going about it the right way. Try to tackle problems and ask questions when you hit a wall. In my experience, it’s really only by doing that you gain a fundamental understanding of what’s going on.
The Shotgrid documentation isn’t bad. Sometimes it’s difficult to find what you’re looking for but there is definitely some very helpful stuff.

If you haven’t yet, dig into some of the Toolkit documentation. I would suggest looking at the Development chapter of the Integrations Guides, as a start - Help

1 Like


Thanks a lot for your suggestion. I will continue as you have suggested. And of-course I will go ahead with SG TK and webhooks as soon as I get confident enough with simple filters and fields. And as I get to a dead end, I will post my queries here in this awesome platform.

Thanks a lot for you motivation, one more time.

Best Regards,