Tag Automation Capabilities

In the SG Python API, we have the capability of uploading an attachment to an entity and specifying tags, but I can’t find any way to batch upload assets and assign tags to them through the code.
Let’s say I have a constants file:

def sg():
    return shotgun_utils.get_shotgun_api_object()

SG_CONNECTOR = sg()
CUSTOM_ENTITY = "CustomEntity01"
PROJECT_ID = 100

And I call the connector with the batch info:

for things in directory:
  asset_dict = {
              "code": name,
              "sg_location": path_name,
              "sg_project_name": project_name,
              "project": {"type":"Project","id": constants.PROJECT_ID},
              "sg_category": category,
              }
   self.asset_list.append({"request_type": "create", "entity_type": constants.CUSTOM_ENTITY, "data": asset_dict})

...
constants.SG_CONNECTOR.batch(asset_list)

In that asset_dict, I’d like to be able to specify a set of tags to upload the assets with through batch. Is this possible to do?

Tags are a field on an entity, so you could just add it to your asset_dict

for things in directory:
  asset_dict = {
              "code": name,
              "sg_location": path_name,
              "sg_project_name": project_name,
              "project": {"type":"Project","id": constants.PROJECT_ID},
              "sg_category": category,
              "TAG_FIELD_CODE": [list_of_tag_dicts]
              }
   self.asset_list.append({"request_type": "create", "entity_type": constants.CUSTOM_ENTITY, "data": asset_dict})

...
constants.SG_CONNECTOR.batch(asset_list)
1 Like

Also, perhaps worth noting that it looks like (you may already know this but I’m being pedantic since you didn’t mention it directly) you’re using a wrapper for the Python API, so as long as the batch call works under the wrapper the same way that it should for the API, you’ll be okay, but obvs you’d want to test that out to make sure :slight_smile:

1 Like

Thank you for responding! I have yet to see anything on how to properly format Tags for SG–
So to be clear, “TAG_FIELD_CODE”: [list_of_tag_dicts]
Would list_of_tag_dicts contain dictionaries with the tag name and project ID? or is it just a list of strings to upload as a tag?

I appreciate the help!

I’m not sure what wrapper you are using for the api so I can’t precisely answer that.

But normally you’d have to give the api a list of dictonaries:

[{"type": "Tag", "id": 1000},{"type": "Tag", "id": 1001},{"type": "Tag", "id": 1002}]

etc.

2 Likes