# API to get query field values

**URL:** <https://community.shotgridsoftware.com/t/api-to-get-query-field-values/11263>\
**Category:** Flow Production Tracking\
**Tags:** python-api\
**Created:** [January 14, 2021, 10:23am UTC](https://community.shotgridsoftware.com/t/api-to-get-query-field-values/11263 "2021-01-14T10:23:44Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![viktor\_petrov](https://sea1.discourse-cdn.com/shotgunsoftware/user_avatar/community.shotgridsoftware.com/viktor_petrov/32/1907_2.png) [@viktor\_petrov](https://community.shotgridsoftware.com/u/viktor_petrov)\
**Post date:** [January 14, 2021, 10:23am UTC](https://community.shotgridsoftware.com/t/api-to-get-query-field-values/11263/1 "2021-01-14T10:23:44Z")

</div>

Hello,

I’ve got a custom query type field created for the Shot entity. When I try to get the value of that field using the Shotgun Python API (shotgun.find\_one with the field name in the fields argument), it always comes back as None, even though it has a value on the Shotgun site. Is fetching query field values possible and if so - how is it done?

Thanks!

---

<div class="post-metadata">

**Author:** ![Kevin\_Lmr](https://avatars.discourse-cdn.com/v4/letter/k/c0e974/32.png) [@Kevin\_Lmr](https://community.shotgridsoftware.com/u/Kevin_Lmr)\
**Post date:** [January 14, 2021, 2:31pm UTC](https://community.shotgridsoftware.com/t/api-to-get-query-field-values/11263/2 "2021-01-14T14:31:50Z")

</div>

Yes, you can achieve this.

First, be sure to use the right field name:  
On a shot page, display the searched column, right clic on the header, configure field and there you’ll see the Field code. It’s usually different from the displayed name.

Then you can query this field like any other.

If this doesn’t help, please post your code. It will be easier to spot the issue.

Cheers

---

<div class="post-metadata">

**Author:** ![viktor\_petrov](https://sea1.discourse-cdn.com/shotgunsoftware/user_avatar/community.shotgridsoftware.com/viktor_petrov/32/1907_2.png) [@viktor\_petrov](https://community.shotgridsoftware.com/u/viktor_petrov)\
**Post date:** [January 14, 2021, 2:38pm UTC](https://community.shotgridsoftware.com/t/api-to-get-query-field-values/11263/3 "2021-01-14T14:38:18Z")

</div>

Hi @Kevin_Lmr

Thanks for your reply. What you’re describing doesn’t seem to work for me.

Here’s what I see on our Shotgun site:

 ![image](https://global.discourse-cdn.com/shotgunsoftware/original/2X/1/1b19f1f54f598615f59eec695c15666e767fdf0a.jpeg)

 ![image](https://global.discourse-cdn.com/shotgunsoftware/original/2X/e/ed8de731b0347e2cce92e36905c33c3fac47f70d.jpeg)

And here’s my Python code:

```
    shot = sg.find_one('Shot',
                       filters=[['id', 'is', shot_id]],
                       fields=['sg_latest_version_for_delivery'])
    print(shot['sg_latest_version_for_delivery'])

```

This returns None.

---

<div class="post-metadata">

**Author:** ![Kevin\_Lmr](https://avatars.discourse-cdn.com/v4/letter/k/c0e974/32.png) [@Kevin\_Lmr](https://community.shotgridsoftware.com/u/Kevin_Lmr)\
**Post date:** [January 14, 2021, 2:43pm UTC](https://community.shotgridsoftware.com/t/api-to-get-query-field-values/11263/4 "2021-01-14T14:43:23Z")

</div>

And what do you get if you print(shot) ?

---

<div class="post-metadata">

**Author:** ![viktor\_petrov](https://sea1.discourse-cdn.com/shotgunsoftware/user_avatar/community.shotgridsoftware.com/viktor_petrov/32/1907_2.png) [@viktor\_petrov](https://community.shotgridsoftware.com/u/viktor_petrov)\
**Post date:** [January 14, 2021, 2:48pm UTC](https://community.shotgridsoftware.com/t/api-to-get-query-field-values/11263/5 "2021-01-14T14:48:48Z")

</div>

This:

 ![image](https://global.discourse-cdn.com/shotgunsoftware/original/2X/8/88dcc50538bf23738cc1641dce05af5a390d4e7b.jpeg)

---

<div class="post-metadata">

**Author:** ![Kevin\_Lmr](https://avatars.discourse-cdn.com/v4/letter/k/c0e974/32.png) [@Kevin\_Lmr](https://community.shotgridsoftware.com/u/Kevin_Lmr)\
**Post date:** [January 14, 2021, 2:56pm UTC](https://community.shotgridsoftware.com/t/api-to-get-query-field-values/11263/6 "2021-01-14T14:56:51Z")

</div>

OK, just wanted to be sure that your query was working.  
And I assume you’ve double checked the shot id.

Does the authenticated user in the script can read this field?

---

<div class="post-metadata">

**Author:** ![viktor\_petrov](https://sea1.discourse-cdn.com/shotgunsoftware/user_avatar/community.shotgridsoftware.com/viktor_petrov/32/1907_2.png) [@viktor\_petrov](https://community.shotgridsoftware.com/u/viktor_petrov)\
**Post date:** [January 14, 2021, 3:00pm UTC](https://community.shotgridsoftware.com/t/api-to-get-query-field-values/11263/7 "2021-01-14T15:00:14Z")

</div>

Yes, it’s the same shot. Actually, reading query fields on any shot returns None for me.

I’m using an API Admin script to get the Shotgun instance that I’m using to fetch the shot, so it should be able to see everything.

---

<div class="post-metadata">

**Author:** ![Kevin\_Lmr](https://avatars.discourse-cdn.com/v4/letter/k/c0e974/32.png) [@Kevin\_Lmr](https://community.shotgridsoftware.com/u/Kevin_Lmr)\
**Post date:** [January 14, 2021, 3:09pm UTC](https://community.shotgridsoftware.com/t/api-to-get-query-field-values/11263/8 "2021-01-14T15:09:23Z")

</div>

Oh ok, sorry. I didn’t read the question properly then. I skip the “query” field part.  
Indeed, it’s also returning None on my test then.

Could you then post your query? How do you filter last version?  
Maybe we can achieve this with a more complete filter.

---

<div class="post-metadata">

**Author:** ![viktor\_petrov](https://sea1.discourse-cdn.com/shotgunsoftware/user_avatar/community.shotgridsoftware.com/viktor_petrov/32/1907_2.png) [@viktor\_petrov](https://community.shotgridsoftware.com/u/viktor_petrov)\
**Post date:** [January 14, 2021, 3:13pm UTC](https://community.shotgridsoftware.com/t/api-to-get-query-field-values/11263/9 "2021-01-14T15:13:08Z")

</div>

This is my query:

 ![image](https://global.discourse-cdn.com/shotgunsoftware/original/2X/9/97b3a0a62ff865555da6730abb0f889dddc62137.jpeg)

If you’re referring to re-creating the query for the version using the Python API - I already figured I could do that, but it’s just an extra step. I was hoping could be avoided, since the field on Shotgun should already contain a value or at least I hoped it could be forced to calculate the value for you in the response.

---

<div class="post-metadata">

**Author:** ![Kevin\_Lmr](https://avatars.discourse-cdn.com/v4/letter/k/c0e974/32.png) [@Kevin\_Lmr](https://community.shotgridsoftware.com/u/Kevin_Lmr)\
**Post date:** [January 14, 2021, 3:25pm UTC](https://community.shotgridsoftware.com/t/api-to-get-query-field-values/11263/10 "2021-01-14T15:25:21Z")

</div>

OK, then, there is nothing else I can do to help 😉

From the [documentation](http://developer.shotgunsoftware.com/python-api/usage_tips.html#shotgun-ui-fields-not-available-via-the-api):

## Shotgun UI fields not available via the API

Summary type fields like Query Fields and Pipeline Step summary fields are currently only available via the UI. Some other fields may not work as expected through the API because they are “display only” fields made available for convenience and are only available in the browser UI.

---

<div class="post-metadata">

**Author:** ![taiello](https://sea1.discourse-cdn.com/shotgunsoftware/user_avatar/community.shotgridsoftware.com/taiello/32/267_2.png) [@taiello](https://community.shotgridsoftware.com/u/taiello)\
**Post date:** [January 27, 2021, 2:40am UTC](https://community.shotgridsoftware.com/t/api-to-get-query-field-values/11263/11 "2021-01-27T02:40:30Z")

</div>

You can retrieve the configuration of a query field via the API using `sg.schema_field_read` and then pass that config into an `sg.find` or `sg.summarize` call.

In your case, you’d do:  
`my_field_config = sg.schema_field_read('Shot', 'sg_latest_version_for_delivery')['sg_latest_version_for_delivery']`

Then the configuration of the query field, including the filters and the intended format of the result, will be available as a `dict` in:  
`my_field_config['properties']`

You’d then need to pop keys out of that result and stuff them into an `sg.summarize()` call.

This general approach avoids having to duplicate your query config in your client code, allowing you to reconfigure the query field in the UI and have your code continue to work with it without having to refactor.

---

<div class="post-metadata">

**Author:** ![viktor\_petrov](https://sea1.discourse-cdn.com/shotgunsoftware/user_avatar/community.shotgridsoftware.com/viktor_petrov/32/1907_2.png) [@viktor\_petrov](https://community.shotgridsoftware.com/u/viktor_petrov)\
**Post date:** [January 27, 2021, 7:46am UTC](https://community.shotgridsoftware.com/t/api-to-get-query-field-values/11263/12 "2021-01-27T07:46:00Z")

</div>

This is great, thanks @taiello

---

<div class="post-metadata">

**Author:** ![frank](https://sea1.discourse-cdn.com/shotgunsoftware/user_avatar/community.shotgridsoftware.com/frank/32/247_2.png) [@frank](https://community.shotgridsoftware.com/u/frank)\
**Post date:** [October 13, 2021, 11:31pm UTC](https://community.shotgridsoftware.com/t/api-to-get-query-field-values/11263/13 "2021-10-13T23:31:57Z")

</div>

Is there an example for the final code? I am trying to do the exact same thing but am getting a bit lost in the return value of the schema.

---

<div class="post-metadata">

**Author:** ![Sriranjani](https://avatars.discourse-cdn.com/v4/letter/s/c77e96/32.png) [@Sriranjani](https://community.shotgridsoftware.com/u/Sriranjani)\
**Post date:** [December 8, 2022, 3:03pm UTC](https://community.shotgridsoftware.com/t/api-to-get-query-field-values/11263/14 "2022-12-08T15:03:08Z")

</div>

Can we have a copy of the code above please? Somehow I am not getting the result as expected.

---

<div class="post-metadata">

**Author:** ![Cameron](https://sea1.discourse-cdn.com/shotgunsoftware/user_avatar/community.shotgridsoftware.com/cameron/32/6682_2.png) [@Cameron](https://community.shotgridsoftware.com/u/Cameron)\
**Post date:** [October 8, 2023, 2:02pm UTC](https://community.shotgridsoftware.com/t/api-to-get-query-field-values/11263/15 "2023-10-08T14:02:29Z")

</div>

@taiello is there anything you can provide more specifically? I’m a little confused here. Thanks a ton in advance!

---

<div class="post-metadata">

**Author:** ![sbissonnette](https://sea1.discourse-cdn.com/shotgunsoftware/user_avatar/community.shotgridsoftware.com/sbissonnette/32/6060_2.png) [@sbissonnette](https://community.shotgridsoftware.com/u/sbissonnette)\
**Post date:** [December 12, 2023, 6:54pm UTC](https://community.shotgridsoftware.com/t/api-to-get-query-field-values/11263/16 "2023-12-12T18:54:08Z")

</div>

Having to use the schema of the query and feed it to a find/summarize is more of a workaround.

I feel the expected behavior of a simple `sg.find_one('Shot', [], ['my_query_field'])` would return the value. Returning “None” is completely pointless.

---

<div class="post-metadata">

**Author:** ![rneldner](https://sea1.discourse-cdn.com/shotgunsoftware/user_avatar/community.shotgridsoftware.com/rneldner/32/6292_2.png) [@rneldner](https://community.shotgridsoftware.com/u/rneldner)\
**Post date:** [August 21, 2024, 10:11pm UTC](https://community.shotgridsoftware.com/t/api-to-get-query-field-values/11263/17 "2024-08-21T22:11:04Z")

</div>

Hey everyone!

I had to build a solution to this problem with a project that I was working on recently. I remembered coming accross this thread and thought I would share what I came up with. I did my best to package up the functionality that I thought would be helpful to other developers.

[https://github.com/mbsurfer/shotgun-extensions](https://github.com/mbsurfer/shotgun-extensions)

Importing this package will give you access to new versions of the find and find\_one methods you would traditionally use with the ShotGun class.

**How it works**

After executing the relative find method, I check if any of the fileds requested are query fields. I then use the entity schema to construct additional queries and return the query values with the rest of the results. My goal was to make using these find functions as seamless as possible with the way they work now.

Expect these new methods to be slower than the standard find methods because of all the extra queries that need to be made, so please keep that in mind.

Feel free to reach out to me if you have any questions or suggestions.

---

<div class="post-metadata">

**Author:** ![Halil](https://sea1.discourse-cdn.com/shotgunsoftware/user_avatar/community.shotgridsoftware.com/halil/32/4697_2.png) [@Halil](https://community.shotgridsoftware.com/u/Halil)\
**Post date:** [August 21, 2024, 11:23pm UTC](https://community.shotgridsoftware.com/t/api-to-get-query-field-values/11263/18 "2024-08-21T23:23:52Z")

</div>

Hey @rneldner this is great thanks for sharing!

Semi-related, have you at all attempted to pull data from `PageSettings` to inspect filters in the web and then attempted to translate them at all? I haven’t done this myself but this repo is a good excuse to add this as another feature. Will let you know if I fork this and get something working but it won’t be anytime soon unfortunately…!

---

<div class="post-metadata">

**Author:** ![rneldner](https://sea1.discourse-cdn.com/shotgunsoftware/user_avatar/community.shotgridsoftware.com/rneldner/32/6292_2.png) [@rneldner](https://community.shotgridsoftware.com/u/rneldner)\
**Post date:** [August 22, 2024, 12:07am UTC](https://community.shotgridsoftware.com/t/api-to-get-query-field-values/11263/19 "2024-08-22T00:07:51Z")

</div>

You bet!

Unfortunately, I haven’t had to deal with pages as all, but I am curious on how similar the process might be. I was juest testing requesting a few pages directly from the API and I am not seeing any filter information being retruned. Have you been able to retrieve that info?

I am using the `GET /api/v1/entity/pages/:id` and the `GET /schema/pages/fields` routes.

---

<div class="post-metadata">

**Author:** ![patrickwolf](https://sea1.discourse-cdn.com/shotgunsoftware/user_avatar/community.shotgridsoftware.com/patrickwolf/32/3931_2.png) [@patrickwolf](https://community.shotgridsoftware.com/u/patrickwolf)\
**Post date:** [December 28, 2024, 12:10pm UTC](https://community.shotgridsoftware.com/t/api-to-get-query-field-values/11263/20 "2024-12-28T12:10:20Z")

</div>

> [@rneldner](#):
>
> After executing the relative find method, I check if any of the fileds requested are query fields. I then use the entity schema to construct additional queries and return the query values with the rest of the results. My goal was to make using these find functions as seamless as possible with the way they work now.

thank you for offering that to the community!

[Next page](https://community.shotgridsoftware.com/t/api-to-get-query-field-values/11263.md?page=2)
