# API filter services in environment does not seem to work

**URL:** <https://forums.suse.com/t/api-filter-services-in-environment-does-not-seem-to-work/3626>\
**Category:** Rancher 1.x\
**Created:** [August 4, 2016, 12:51pm UTC](https://forums.suse.com/t/api-filter-services-in-environment-does-not-seem-to-work/3626 "2016-08-04T12:51:22Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![cabrinoob](https://sea2.discourse-cdn.com/flex022/user_avatar/forums.suse.com/cabrinoob/32/1343_2.png) [@cabrinoob](https://forums.suse.com/u/cabrinoob)\
**Post date:** [August 4, 2016, 12:51pm UTC](https://forums.suse.com/t/api-filter-services-in-environment-does-not-seem-to-work/3626/1 "2016-08-04T12:51:22Z")

</div>

Hi,  
I’am trying to use the API and searching a service by name in an environment.

So, in first, I get the environment like this :

> GET /v1/environment?name=myTestStack

which returns a JSON document with a “services” url like this :

> GET /v1/environments/1e22/services

This returns the services list in my stack. I just want to get only one by its name, so I tried to call :

> GET /v1/environments/1e22/services?name=myServiceName

But it still returns the whole list. The filter does not seem to work here. I tried calling the services endpoint with the same filter and it works, but when I apply it in /environments/1e22/services, it does’nt work.

Thank you for your help

---

<div class="post-metadata">

**Author:** ![denise](https://avatars.discourse-cdn.com/v4/letter/d/82dd89/32.png) [@denise](https://forums.suse.com/u/denise)\
**Post date:** [August 4, 2016, 4:00pm UTC](https://forums.suse.com/t/api-filter-services-in-environment-does-not-seem-to-work/3626/2 "2016-08-04T16:00:45Z")

</div>

API filtering is a known issue.

> <https://github.com/rancher/rancher/issues/5321>

> <https://github.com/rancher/rancher/issues/3847>

---

<div class="post-metadata">

**Author:** ![cabrinoob](https://sea2.discourse-cdn.com/flex022/user_avatar/forums.suse.com/cabrinoob/32/1343_2.png) [@cabrinoob](https://forums.suse.com/u/cabrinoob)\
**Post date:** [August 4, 2016, 5:58pm UTC](https://forums.suse.com/t/api-filter-services-in-environment-does-not-seem-to-work/3626/3 "2016-08-04T17:58:36Z")

</div>

Ok, thank you @denise. Do you have any idea when this problem will be fixed?

Because I need this to automatically updrade a service under an environment and to do this I though to catch the environment first, then list all services of this environment and filter by name to call the upgrade action.

Perhaps do you have another way to do this? Knowing that my CI/CD tool only works with names (not ids) and that the same service “toto” can appear in many enviroments (cattle stacks).

Thank you anyway.

---

<div class="post-metadata">

**Author:** ![vincent](https://sea2.discourse-cdn.com/flex022/user_avatar/forums.suse.com/vincent/32/7156_2.png) [@vincent](https://forums.suse.com/u/vincent)\
**Post date:** [August 4, 2016, 8:03pm UTC](https://forums.suse.com/t/api-filter-services-in-environment-does-not-seem-to-work/3626/4 "2016-08-04T20:03:57Z")

</div>

The problem is that nested resource URLs (services of environment 1s22) are essentially a different class of filter and using that takes precedence over the user-specified filters. That will be fixed eventually (along with the infuriatingly inconsistent naming of stack vs environment 😄).

In the meantime this is functionally equivalent:

$environments = `GET /v1/environments?name=myStack`  
$environmentId = $environments.data[0].id  
$services = `GET /v1/services?environmentId=${environmentId}&name=myServiceName`  
$service = $services.data[0]

---

<div class="post-metadata">

**Author:** ![cabrinoob](https://sea2.discourse-cdn.com/flex022/user_avatar/forums.suse.com/cabrinoob/32/1343_2.png) [@cabrinoob](https://forums.suse.com/u/cabrinoob)\
**Post date:** [August 4, 2016, 8:38pm UTC](https://forums.suse.com/t/api-filter-services-in-environment-does-not-seem-to-work/3626/5 "2016-08-04T20:38:08Z")

</div>

@vincent:you saved my Day 🙂  
Thank you

(Rancher ruleZ!!)
