# Shotgrid API filtering Tasks

**URL:** <https://community.shotgridsoftware.com/t/shotgrid-api-filtering-tasks/15918>\
**Category:** Pipeline Integrations\
**Tags:** python-api\
**Created:** [September 6, 2022, 7:52am UTC](https://community.shotgridsoftware.com/t/shotgrid-api-filtering-tasks/15918 "2022-09-06T07:52:04Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![pw\_simon](https://avatars.discourse-cdn.com/v4/letter/p/58956e/32.png) [@pw\_simon](https://community.shotgridsoftware.com/u/pw_simon)\
**Post date:** [September 6, 2022, 7:52am UTC](https://community.shotgridsoftware.com/t/shotgrid-api-filtering-tasks/15918/1 "2022-09-06T07:52:04Z")

</div>

Hello!

I’m having troubles querying Tasks in a specific Pipeline step. I’m using the following code, which should return all Tasks in of the specific Shot in a specific Sequence in a specific Project. The returned tasks should be in Animation Pipeline Step, or named Previs01.  
However this only returns the Previs01 while there are obviously other Tasks in Animation Pipeline Step.  
I also tried some variation, but I could only get ALL the tasks or none of them. Any helpful ideas?  
(Smaller problem, but also annoys me: the ‘step’ field is not returned.)

```auto
        tasks = sg.find("Task", [
            ['project.Project.name', 'is', project_name],
            ['entity.Shot.sg_sequence.Sequence.code', 'is', sequence_code],
            ['entity.Shot.code', 'is', shot_code],
            {
                "filter_operator": "any",
                "filters": [
                    ['step.Step.code', 'is', 'Animation'],
                    ['content', 'is', 'Previs01']
                ]
            }

        ], ['id', 'step', 'content'])

```

---

<div class="post-metadata">

**Author:** ![pw\_simon](https://avatars.discourse-cdn.com/v4/letter/p/58956e/32.png) [@pw\_simon](https://community.shotgridsoftware.com/u/pw_simon)\
**Post date:** [September 6, 2022, 9:32am UTC](https://community.shotgridsoftware.com/t/shotgrid-api-filtering-tasks/15918/2 "2022-09-06T09:32:02Z")

</div>

Actually it seems like querying by Pipline step doesn’t work at all. Were there any changes recently in SG API or what am I missing?

---

<div class="post-metadata">

**Author:** ![michaelsherwood](https://avatars.discourse-cdn.com/v4/letter/m/dec6dc/32.png) [@michaelsherwood](https://community.shotgridsoftware.com/u/michaelsherwood)\
**Post date:** [September 6, 2022, 11:50am UTC](https://community.shotgridsoftware.com/t/shotgrid-api-filtering-tasks/15918/3 "2022-09-06T11:50:05Z")

</div>

Hi Simon,

I’ve run your query on my end and can confirm that it is working correctly.

It’s possible that your issue may be caused by your Task entities not being linked to the “Animation” Pipeline Step or perhaps there’s a possibility that you have multiple Pipeline Step entities that are labelled “Animation”, this could cause the query to be trying to get the incorrect Pipeline Step.

In order to test this, would you be able to get the ID of the “Animation” Pipeline Step that you are wanting to retrieve and then update your query to filter by the Pipeline Step ID instead of the Pipeline Step Code?

```auto
tasks = sg.find("Task", [
            ['project.Project.name', 'is', project_name],
            ['entity.Shot.sg_sequence.Sequence.code', 'is', sequence_code],
            ['entity.Shot.code', 'is', shot_code],
            {
                "filter_operator": "any",
                "filters": [
                    ['step.Step.id', 'is', animation_step_id],
                    ['content', 'is', 'Previs01']
                ]
            }

        ], ['id', 'step', 'content'])

```

---

<div class="post-metadata">

**Author:** ![pw\_simon](https://avatars.discourse-cdn.com/v4/letter/p/58956e/32.png) [@pw\_simon](https://community.shotgridsoftware.com/u/pw_simon)\
**Post date:** [September 7, 2022, 8:16am UTC](https://community.shotgridsoftware.com/t/shotgrid-api-filtering-tasks/15918/4 "2022-09-07T08:16:42Z")

</div>

Hello Michael!  
Thanks for the reply. Using the id doesn’t yield better results neither, I’ve already tried that.  
Maybe this is an issue with our Shotgrid somehow, I just don’t know how…

---

<div class="post-metadata">

**Author:** ![Ricardo\_Musch](https://sea1.discourse-cdn.com/shotgunsoftware/user_avatar/community.shotgridsoftware.com/ricardo_musch/32/405_2.png) [@Ricardo\_Musch](https://community.shotgridsoftware.com/u/Ricardo_Musch)\
**Post date:** [September 7, 2022, 9:08am UTC](https://community.shotgridsoftware.com/t/shotgrid-api-filtering-tasks/15918/5 "2022-09-07T09:08:04Z")

</div>

Best way to troubleshot now is to explicitly try a find\_one for a task that you know should show up in the results, with the field names from your filter.

See if the output is as required.

---

<div class="post-metadata">

**Author:** ![pw\_simon](https://avatars.discourse-cdn.com/v4/letter/p/58956e/32.png) [@pw\_simon](https://community.shotgridsoftware.com/u/pw_simon)\
**Post date:** [September 16, 2022, 12:49pm UTC](https://community.shotgridsoftware.com/t/shotgrid-api-filtering-tasks/15918/6 "2022-09-16T12:49:10Z")

</div>

Thanks for the replies!  
Unfortunately more important tasks came up, so I’ll continue with this later.

---

<div class="post-metadata">

**Author:** ![pw\_simon](https://avatars.discourse-cdn.com/v4/letter/p/58956e/32.png) [@pw\_simon](https://community.shotgridsoftware.com/u/pw_simon)\
**Post date:** [September 21, 2022, 7:31am UTC](https://community.shotgridsoftware.com/t/shotgrid-api-filtering-tasks/15918/7 "2022-09-21T07:31:48Z")

</div>

I tried both of your suggestions, and I’ve got some strange results:

As I stated above, filtering with id doesn’t solve this for me: it results ALL the possible tasks, not just the ones for the filtered step.

As for the find\_one: I can find the task, but if I add ‘step’ for the fields, it’s just ignored. I won’t get back the task’s step in any way. I double checked: the Task entity has a field with field code ‘step’.

I have no idea why this is happening. 😕

---

<div class="post-metadata">

**Author:** ![Ricardo\_Musch](https://sea1.discourse-cdn.com/shotgunsoftware/user_avatar/community.shotgridsoftware.com/ricardo_musch/32/405_2.png) [@Ricardo\_Musch](https://community.shotgridsoftware.com/u/Ricardo_Musch)\
**Post date:** [September 21, 2022, 10:12am UTC](https://community.shotgridsoftware.com/t/shotgrid-api-filtering-tasks/15918/8 "2022-09-21T10:12:06Z")

</div>

I have tried this as well and cannot replicate your problem.

Best to put a ticket in with support in this case!

[Contact Customer Support | Autodesk Knowledge Network](https://knowledge.autodesk.com/contact-support)

---

<div class="post-metadata">

**Author:** ![pw\_simon](https://avatars.discourse-cdn.com/v4/letter/p/58956e/32.png) [@pw\_simon](https://community.shotgridsoftware.com/u/pw_simon)\
**Post date:** [September 22, 2022, 11:31am UTC](https://community.shotgridsoftware.com/t/shotgrid-api-filtering-tasks/15918/9 "2022-09-22T11:31:21Z")

</div>

Feels stupid, but the problem lied in the script users’ insufficient permissions: couldn’t see the Tasks’ Pipeline Step fields.

Case closed.
