Query devices by tags
I've been asked this question https://github.com/hashicorp/go-discover/pull/52 about tags. If it was possible to query the API for devices with certain tags. I can't find anything in the API doc cc// @jacobsmith928 @mberrueta
curl '../api/devices?with_tag=Hello' for a single tag curl '../api/devices?with_tags=Hello,bye' for multiple ones
@mberrueta it does not seem to be working
$curl -X GET --header 'Accept: application/json' --header 'X-Auth-Token: [token]' 'https://api.packet.net/projects/93125c2a-8b78-4d4f-a3c4-7367d6b7cca8/devices?with_tag=test01' | jq '.devices | length'
8
It returns list of 8 devices where it should be returning only 2 (see the screenshot)

sorry my bad, is without the with_
curl '../api/devices?tag=test01'
or
curl '../api/devices?tags=test01,test02'
Confirmed!!!
curl -X GET --header 'Accept: application/json' --header 'X-Auth-Token: [token]' 'https://api.packet.net/projects/93125c2a-8b78-4d4f-a3c4-7367d6b7cca8/devices?tag=test01' | jq '.devices | length'
2
But not with two tags:
$ curl -X GET --header 'Accept: application/json' --header 'X-Auth-Token: [token]' 'https://api.packet.net/projects/93125c2a-8b78-4d4f-a3c4-7367d6b7cca8/devices?tags=test01,test03' | jq '.devices | length'
8
It should have returned 4
it's an or and probably you need an and
I played with | and & but it didn't seem to work as expected.
curl -X GET --header 'Accept: application/json' --header 'X-Auth-Token: [token]' 'https://api.packet.net/projects/93125c2a-8b78-4d4f-a3c4-7367d6b7cca8/devices?tag=test01&test03' | jq '.devices | length'
2
Expected result is 4 devices I also tried using tags instead of tag and the API returned all devices (count 8)
created a request in jira, will go back here as soon as it's done
Hi @mberrueta, do we know if this has been resolved?
hi @patrickdevivo not yet, it still on the backlog
@jasmingacic can you test now
GET /projects/id/devices?tags[]=test01&tags[]=test02
this should get only with both tags
@mberrueta Is there a reason or requirement for the brackets in the query parameter key name? I'm not aware of any obvious problems with the approach (other than possibly having to encode the characters), but it does feel a little atypical and unnecessary with URI query parameters.
not sure why it allow with [] but you can call
GET /projects/id/devices?tags[]=test01&tags[]=test02
or without
GET /projects/id/devices?tag=test01&tag=test02
@jasmingacic @t0mk any thoughts on how this should be implemented?
We could potentially add a QueryParams field to the ListOptions struct, which is a list of query params that get passed through to the request, to support this in a generic way.
An "issue" with that is we'd have a generic way of passing query params, but only for .List(...) and not for other calls, which might feel a little asymmetric/incomplete
I'd go with ListOptions for all functions like Get and List, and I would remove GetExtra.
https://coderwall.com/p/uh8kiw/pass-arrays-objects-via-querystring-the-rack-rails-way
is why the param[]