API find HumanUser by custom field

Hi All,

I need to get user info while searching a custom text field, but I cant get it working.

Searching using login work fine:

user = "mattrichardson"
# This finds User from login field
filters = [['login', 'is', user]]
userid = sg.find('HumanUser', filters)

print (userid)

But I have made a text based custom user field in the web interface called ‘UploadUser’ which I can’t seem to query using the same method.

Here’s the field that I made:
Capture

but when I try and query it I get this error:

user = "big.bad.boss"

# trying to search from UploadUser field
filters = [['UploadUser', 'is', user]]
userid = sg.find('HumanUser', filters)

print (userid)

shotgun_api3.shotgun.Fault: API read() HumanUser.UploadUser doesn't exist:
{"path"=>"UploadUser", "relation"=>"is", "values"=>["big.bad.boss"]}

I’m sure i just need to use a different search method, but i’m a bit stuck.

Thanks

M

Hey Matt,

The API uses the internal field code not the display name of the field. So I’d imagine your field’s internal code would be sg_uploaduser. For custom fields, SG creates the field code by prepending it with sg_ and then replacing any spaces or special chars with an underscore _.

You can double check the field code by any one of these methods:

  • looking at the Admin > Fields page if you have permissions.
  • right-click on the UploadUser column header on a People list page and select “Configure field…”. At the top it will show you the display name in the editable text box, and to the right it will have Field code: sg_somefield
  • Using the API, you can use the schema_field_read() function to get a list of the fields for HumanUser and inspect the results for the field codes. The output is quite verbose but useful.
  • On a People list page, if you click on the Fields button and select “Configure Columns…” if you hover over the field display names in the overlay, you will see their internal field codes displayed next to them as you hover.

There’s other places for this info, but that should get you unstuck.

Assuming this is a text field…

user = "big.bad.boss"

# trying to search from UploadUser field
filters = [['sg_uploaduser', 'is', user]]
userid = sg.find('HumanUser', filters)

print (userid)

cheers,
kp

3 Likes

thats fantastic - Thanks kp