Create Icon entity through the api

Hi I’m in the process of migrating one project from a shotgun site to another sg site (political reasons).
And in my source sg site, we have a lot of custom status with custom icons, in order to not create them by hand, I 'm doing a little loop in python to copy the custom status with their icons from one site to the other.

sg.create(‘Icon’, {‘name’: sourceIcon[‘name’], ‘image_data’: sourceIcon[‘image_data’]})

But I got the following error:
shotgun_api3.shotgun.Fault: API create() CRUD ERROR #7: Entity of type Icon cannot be created by this user. Rule: API Admin – PermissionRule 691: DENY create_entity FOR entity_type => Icon

If it is not possible with python, can I do this with the rest api? Thanks!

hi @macbeth,

Sorry for the late response. It is permission error. API user doesn’t allow to create Icon. I tried to use human user to run the script. It works. I don’t what data you used for sourceIcon['image_data']. If it is a image path like sg.create(‘Icon’, {‘name’: ‘new_icon_name’, ‘image_data’: ‘a.jpg’}), after you run the script, shotgun site would be crashed.

The correct way to use this api is

sg.create('Icon', {'name': 'New Icon 99', 'icon_type': 'custom_status', 'display_type': 'image', 'image_data': '<hex_encoded_16px_wide_jpg>'}).

May I ask what is your use case? We will decide to disable this dangers api or update document.

Thanks

Loney

Hi! Thanks! Will use the user as you suggested, I am migrating one project to another shotgun site, so I’m taking the string hex code from another icon entity just from another site, so it should work.

I saw a post from a guy who tried the same.

Oh my goodness, thanks for testing the API with a HumanUser @jing.liu this is definitely going to come in handy. Thanks @macbeth for tagging my previous post!

It would seem that the reason we are looking for ways to create Icons through the API is because of the one (1) icon upload limit through the web-UI.

I was just looking for a feasible way to import a library of icons (100+) which we could use to expand our creative expression through statuses.

@jing.liu - Is it realistic to ask for a multi-file upload option for creating ‘custom’ icons?

Hi @davidma,

Yes, it support batch create icons. Batch API Reference

This is a sample code.

batch_data = []

data1 = {'name': 'New Icon 99', 'icon_type': 'custom_status', 'display_type': 'image', 'image_data': '<hex_encoded_16px_wide_jpg>'}
data2 = {'name': 'New Icon 99', 'icon_type': 'custom_status', 'display_type': 'image', 'image_data': '<hex_encoded_16px_wide_jpg>'}

batch_data.append({"request_type": "create", "entity_type": "Icon", "data": data1})
batch_data.append({"request_type": "create", "entity_type": "Icon", "data": data2})

sg.batch(batch_data)

Hope it is helpful.

Loney

Thank you for the reply - Though I’m a little confused about this thread.

In your previous posting, you mentioned that:

API user doesn’t allow to create Icon

Meaning that I would need to use a HumanUser connection credential.
Though:

I don’t what data you used for sourceIcon['image_data'] . If it is a image path like sg.create(‘Icon’, {‘name’: ‘new_icon_name’, ‘image_data’: ‘a.jpg’}) , after you run the script, shotgun site would be crashed.

The correct way to use this api is

sg.create('Icon', {'name': 'New Icon 99', 'icon_type': 'custom_status', 'display_type': 'image', 'image_data': '<hex_encoded_16px_wide_jpg>'}) .

That suggests to me that I would need to pre-convert the image I wanted to use:
C:/path/to/icon.png to a hex-encoded 16px wide jpg and use data similar to what I’ve found in other icons:

{'cached_display_name': 'New Icon 98',
 'display_type': 'image',
 'html': None,
 'icon_type': 'custom_status',
 'id': 98,
 'image_data': 'iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAMAAAAoLQ9TAAAABGdBTUEAALGP\nC/xhBQAAAAFzUkdCAK7OHOkAAAAgY0hSTQAAeiUAAICDAAD5/wAAgOkAAHUw\nAADqYAAAOpgAABdvkl/FRgAAAUFQTFRF////4eHh19fXwsLCvb29y8vL7e3t\nnp6esrKy8/PzycnJ0NDQu7u7v7+/8vLy+/v6urq6xsbG8vHz1dXVzc3Menp6\nkJCQlZaVl5eXk5OTlZWVpKSkpqamqKio2dnZxcXFxMTE39/f4uLk1tbX09PT\n+Pj48PDwzs7P0tLT3Nzc8fHx5ubn0dHR09PSgYGBLCwsRUVFhISEvLy8YWFh\nTU1Ng4ODZGRkCwsLvLy80dHRJiYmT09PhISEoqKidXV1iYmJAwMDAgICUVFR\nQkJCTExMNzc3EBAQFRUVHh4eyMjIFhYWw8PDw8PDsbGxGRkZISEigoGFu7u7\nubm5BAQEMTExXl5eEBAQgICAICAgZ2dnnZ2dEBAR4eHjoKCgDg4OIiIix8fI\nyMjHfX19Ozs8Ozs7gICB1tbWAAAAAQEB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ZGRkCwsLvLy80dHRJiYmT09PhISEoqKidXV1iYmJAwMDAgICUVFR\nQkJCTExMNzc3EBAQFRUVHh4eyMjIFhYWw8PDw8PDsbGxGRkZISEigoGFu7u7\nubm5BAQEMTExXl5eEBAQgICAICAgZ2dnnZ2dEBAR4eHjoKCgDg4OIiIix8fI\nyMjHfX19Ozs8Ozs7gICB1tbWAAAAAQEBAwME////uIU6FAAAAGd0Uk5TAAAA\nAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEiT\nhRcEYm8zkOoYGNh+YlByWdj+r5SMv8e5wRrjOQNE6N2NLwT6wE3oI9eWN/kR\nTPPrLA90pad2ClEPq+gAAAABYktHRACIBR1IAAAACXBIWXMAAAsTAAALEwEA\nmpwYAAAAsklEQVQY02NgQAeMTHr6BobMLKxsRsYmpuwcDJxm6enp5hbMXJZW\nQIY1N4NNOgjY8vDagRn2DA4gytHJ2cUVLODG4A6iMtJhwIPB0ysdCWR6M/D5\n+PrBuP4BgfwMAoJBwTCBECFhEQZRsVC4hjBxCUkGKelwuIAVIzcrg4wsSwRM\nIJJBTo5BXkExCsqPjlFSVmZQUeFWjY0D8eMT1NQ1NBg0gUArMSk5JTVNW0dX\nRQXD9wAArUB1Md3OWgAAACV0RVh0ZGF0ZTpjcmVhdGUAMjAxNS0wMS0xNVQx\nOToxMTo0NCswMDowMF8+S4sAAAAldEVYdGRhdGU6bW9kaWZ5ADIwMTUtMDEt\nMTVUMTk6MTE6NDQrMDA6MDAuY/M3AAAAAElFTkSuQmCC\n',
 'uuid': '58737146-9cea-11e4-9405-00259000f98e'}

I’m aware of the batch API commands, though what I was asking about was the ability (in the web UI) to select multiple images to upload.

Now… (shifting gears) - based on this latest example you provided, it would seem I could use a filepath to a .png image for the image_data field?

I haven’t been able to find any documentation for uploading images to the Icon entity.


TL;DR

@jing.liu - Can I use 'image_data' : 'C:/path/to/icon.png' as a valid argument through a HumanUser shotgun connection to create these Icon Entities?

I hope you understand the need for clarity - The last thing I want to do is crash our shotgun server.

Hi @davidma,

Sorry for the confusing. It is my bad. I just quickly test batch create. You still need to create icon use HumanUser. And the api is same.

sg.create('Icon', {'name': 'New Icon 99', 'icon_type': 'custom_status', 'display_type': 'image', 'image_data': '<hex_encoded_16px_wide_jpg>'})

What is your server url? I could help to delete the icon to fix the server problem.

I don’t think it is possible. But it is useful feature. Would you mind to submit a new feature request?

Thanks

Loney

@davidma,

I update the original post.

Thanks

Loney

Oh, there’s no problem with any of our current icons, the codeblock was from an SG query on an Icon which was uploaded through the webUI

Do you have a recommendation for how best to generate the acceptable <hex_encoded_16px_wide_jpg> from a png file?

Hi @davidma

There is nothing special for png file. This is the code I used.

img_b64 = base64.b64encode(open("16x16_jpg_png_file", "rb").read()).decode('utf-8')

Loney