API filter services in environment does not seem to work

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

1 Like

API filtering is a known issue.

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.

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 :smile:).

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]

@vincent:you saved my Day :slight_smile:
Thank you

(Rancher ruleZ!!)