Get all service variables for a device

Hi, we have a tool that uses the API that stopped functioning on ‘Get all service variables for a device’

Confirmed the device 2077257 has service vars defined and test with Postman with correct Authorisation. (other API calls work as before)

https://api.balena-cloud.com/v5/device_service_environment_variable?$filter=service_install/device%20eq%2077257

It returns empty:
{
“d”:
}

Thanks appreciate your help.
Anton

Hi there, I just double-checked and it should be working as expected. Can you make sure about the following:

  1. The authentication is valid
  2. The device actually has service variables defines
  3. Try using the v6 version of the endpoint

Let me know how it goes after you’ve tried these.

Thanks for your reply.

We have checked 1-3… all fine. Changing device name and update device env vars work fine using the other API endpoints… from the error message it seems to be a CORS issue:

This is our javascript GET function (used for other API GET calls that are fine)

async function getData(url = ‘’) {
// Default options are marked with *
const response = await fetch(url, {
method: ‘GET’, // *GET, POST, PUT, DELETE, etc.
mode: ‘cors’, // no-cors, *cors, same-origin
cache: ‘no-cache’, // *default, no-cache, reload, force-cache, only-if-cached
credentials: ‘same-origin’, // include, *same-origin, omit
headers: headers,
redirect: ‘follow’, // manual, *follow, error
referrerPolicy: ‘no-referrer’ // no-referrer, *no-referrer-when-downgrade, origin, origin-when-cross-origin, same-origin, strict-origin, strict-origin-when-cross-origin, unsafe-url
});
return response.json(); // parses JSON response into native JavaScript objects
}

Thanks,
Anton

Hey Anton,
it may just be a typing mistake, but you mentioned that the device id is 2077257 and that the URL that you are calling is https://api.balena-cloud.com/v5/device_service_environment_variable?$filter=service_install/device%20eq%2077257 be aware of the URL encoding for the empty space. At the end of the URL it should be device%20eq%202077257 missing a 20.
This would be the correct URL, also using v6 as Steve recommended:
https://api.balena-cloud.com/v6/device_service_environment_variable?$filter=service_install/device%20eq%202077257

If this still doesn’t work, make sure that the following API call works:
https://api.balena-cloud.com/v6/device(2077257)
that should return the devices Info, if it is empty, then just call
https://api.balena-cloud.com/v6/device to make sure that your device is there

Let us know if that helped