500 Internal Server Error when setting Env Vars via API

Currently having issues with using the Netlify API (via Node wrapper) to update environment variables across a site network that deploys from the same project with a few env vars changed. Looking to make this process programmatic to streamline things, and can do everything except for update the environment variables on existing installs - getting 500 internal server error.

This is what I’m sending over:

const result = await client.updateEnvVar({
  account_id: 'my id here',
  site_id: 'correct site id here',
  key: 'BUILD_ENV',
  body: {
    key: 'BUILD_ENV',
    scopes: [ 'builds', 'functions', 'runtime', 'post-processing' ],
    values: [ { value: "locations", context: "all" } ]
  }
})

One of the most recent error_ids was: ac2a04ab-e47a-4c9b-94ee-be7f722e9740.

Thanks!

Hey @verystack ! The updateEnvVar endpoint can only be used if you are using the newer version of Environment Variables (as opposed to the “classic” version – see the docs about this here). Can you confirm if you are using the newer version on your site? That might account for these errors. Let us know!

Am on the new Env Vars experience on all affected sites

Hey @verystack,

We’ve raised this with the devs. It turns out, there’s something unexpected going on when performing that operation. We’ll let you know as we have more info.

Hey @verystack ,

Our developers believe this is because you’re using the PUT endpoint to update a key that doesn’t exist. Could you try creating the env var before updating it and let us know if you run into the same error?