API Search for Custom Attributes

Solved Locked
GD
Greg D
Schnuck Markets Inc

I am trying to search for devices using the REST API. Searching for things like  DeviceId, MACAddress, and Model are pretty straight forward. Howerver I don't understand how to search for CustomAttributes.

The API Reference shows: 

The custom attribute I want to search for looks like this:

I was thinking it should look like this, but it doesn't work:

CustomAttributes=[{'Name'}:{'Assigned Site Number'},{'Value'}:{'209'}]

Does Any have an example of what my filter parameter should look like?

Edited 5 years ago
SOTI MobiControl
ANSWERS
KK
Katha K
5 years ago

Assuming you are using the API GET devices/search, here's an example to find devices with value of customer attribute "test" set  to "1"

CustomAttribute['test'] = '1'

Note: you will need to double encode the above filter value -- CustomAttribute%255B%2527test%2527%255D%2520%253D%2520%25271%2527

Solution
GD
Greg D
5 years ago (edited 5 years ago)

Interesting the reference guide shows that it should be plural CustomAttributes

However the plural throws and error and yours is correct. Maybe the documentation should be changed?


Your example works, returning 200 response code on my server. Adapting it to my use case should be:

custom attribute "Assigned Site Number" is set to "209"

CustomAttribute['Assigned Site Number'] = '209'

CustomAttribute%255B%2527Assigned%2520Site%2520Number%2527%255D%2520%3D%2520%2527209%2527


It doesn't like the search:
KK
Katha K
5 years ago

If you are trying it out in the Swagger (API Documentation) page then you should only single encode the value

Try 

CustomAttribute%5B%27Assigned%20Site%20Number%27%5D%20=%20%27209%27

GD
Greg D
5 years ago

I finally got it to work! The last holdup was because the custom attribute I was searching is a numeric type. So, it was failing because of the quotes around 209. This is what the final working filter looks like:

CustomAttribute['Assigned Site Number'] = 209

Thanks for you help!