Shotgrid - python api- people users create

Hi Fellow enthusiasts,

have a simple question,
i can create shots , seq , assets through the api,

how do i add person to the people section in shotgrid using the api,
ex:
creating new name , email, permission and so forth, in the people section of shotgrid,
using the api

Thanks in advance

Hi @contain

You need to create a new HumanUser entity.

As detailed here, you will not be able to use a Script Name/API Key pair to activate or create an active user.

And to be able to authenticate with the API, you will need to define a Personal Access Token. As documented here.

Hoping this helps,

-Patrick

HI Patrick,

thanks for the info much apritiated,
would be great to know the command to create a person , with name, email , and user privilage
as in sg.create(‘Asset’) , is it sg.create(‘HumanUser’), and what would go in the data ,
since this person data , is located in a separate page called people ,

how would i add this data , to the person data using the api,
any pointers would be helpful

Thanks,

Hi @contain

Users are entities, the same way shots, takes, assets, etc. are entities. Everything is created/updated/deleted in a similar fashion with the create/update/delete method. Users are no different or special.

Entities will have specific constraints (e.g. for a HumanUser, you need to specify an email, first name and last name and such).

If there is anything missing, the error message should be verbose enough for you to deduce what is missing or what is wrong.

As for sample code, just search in the forums. You will surely find snippets of sample code.

-Patrick

Hi Patrick,

thx for the pointers , everything is working with the legacy login,
ecxept , unable to create the user , complains about HumanUser type, which i take to be the entityType, maybe i am passing the wrong entityType ?

so,
data = {

            "HumanUser": {"type": "HumanUser"},

            "first_name": firstName,

            "last_name": lastName,

            "email": emailAddress,

            "language": 'EnglishFrench',

        }

        sg.create('HumanUser', data)

gives me this error
shotgun_api3.shotgun.Fault: API create() HumanUser.HumanUser doesn’t exist:
{“field_name”=>“HumanUser”, “value”=>{“type”=>“HumanUser”}}

You are specifying the entity type in the sg.create command, so the HumanUser in your data dict is the problem. Remove it and try again

1 Like

thx ,

it runs , but does not create any users, in the people page in shotgun,
wondering if i am adding the token properly,

this is how i set the token key,
sg = shotgun_api3.Shotgun(SERVER_PATH, SCRIPT_NAME,TOKEN_NAME)

Try reading an existing HumanUser through the API to verify your script key is working.
Also printing out the returned HumanUser may help understand the structure needed for creating one.

How should i access through legacy login ,
should it be
sg = shotgun_api3.Shotgun(SERVER_PATH, USER_NAME,TOKEN_NAME) ?

cheers

See example here:
https://developer.shotgridsoftware.com/python-api/

thx for the doc ,
Patrick from the eralier post had mentioned it creating a human user would not be possible with the scriptkey, and can only done with access token

well i tried accessing a user,
filters = [['id ', ‘is’, 998]]
usr = sg.find(“HumanUser”, filters, [“name”])
print(usr)

and it complains
shotgun_api3.shotgun.Fault: API read() HumanUser.id doesn’t exist:
{“path”=>"id ", “relation”=>“is”, “values”=>[998]}

not sure if this is access issue or scriptkey / token issue ?

assets / shots and all those entities work without any problem with the scriptkey ,
its just creating human , reckon it does not like something in the scriptkey / token ,
not sure

I missed Patrick’s comment about PAT.
In that case you’ll need to use User-based Authentication
https://developer.shotgridsoftware.com/python-api/authentication.html#user-based-authentication
That should only impact User creation, not reading existing users.

In your find example above you may need to include ID in your returned fields, not just Name.
Possibly excluding ID is breaking your filter

tried returning id as well , giving me the same error , dont know how to progress with this ,
looks very simple , reckon i am missing something basic

I can’t help with the creation problem, but it looks like you have an extra space in the id string of the filter that is messing up the find.

>>> filters = [['id ', 'is', 998]]
>>> sg.find('HumanUser', filters, ['name'])
shotgun_api3.shotgun.Fault: API read() HumanUser.id  doesn't exist:
{"path"=>"id ", "relation"=>"is", "values"=>[998]}
>>> 
>>> filters = [['id', 'is', 998]]
>>> sg.find('HumanUser', filters, ['name'])
[]
1 Like

wow Carine, that was a great spot , yep it returned the user name ,

thanks for that,

now to need figure out creating the user bit

would be great if anyone could shed light on this human user creation script,
it runs it and no data is created in the people page

Did you try printing the return value of the create call ?
Also are you sure you don’t have some filters in the people page that would hide the newly created users ?

@contain

When you say: it does not create any users, I do not see them in the People page

2 things:

  1. creating users with a script name and API key will create users who are NOT enabled,
  2. you are likely using a filter on your People page, which does not show those de-activated users that you have created

I just created a user in 3 lines, succesfully:

from shotgun_api3 import Shotgun
sg = Shotgun('https://my.site.com/', login='my_login', password='my_password')
sg.create('HumanUser', {'firstname': 'Foo', 'lastname': 'Bar', 'email': 'a_valid_email@gmail.com'})

-Patrick

1 Like

just tried the same , creating a single user,
thanks Patrick,

now it complains about not authenticated, although i have set up the legacy token and passphrase,
just to clarify,
is the login , the same as login name when signing into shotgrid
and the password is it the password signing into shotgrid or the legacy token passphrase/password