Hi, since yesterday I’ve been getting the following error while using the js-client
in a Node application:
JSONHTTPError: Unprocessable Entity
at parseResponse (REDACTED/api/node_modules/netlify/src/methods/response.js:13:11)
at processTicksAndRejections (node:internal/process/task_queues:94:5)
at async callMethod (REDACTED/api/node_modules/netlify/src/methods/index.js:33:26)
at async Object.updateSiteEnvironmentVariables (REDACTED/api/modules/netlify-client.js:54:18)
at async Object.generateSitePreview (REDACTED/api/business/netlify.js:43:25)
at async REDACTED/api/functions/sites.js:38:36
at async runRequest (REDACTED/@middy/core/index.js:86:26) {
status: 422,
json: { errors: { path: [Array] } }
}
What I’m trying to do there is update my site’s environment variables (which has already work in other cases) before triggering a build, all through the API. Right now I get that error, which I don’t understand why.
The request I’m sending is:
await client.updateSite({
site_id,
body: {
repo: {
env: env_vars
},
build_settings: {
env: env_vars
}
},
});
The name of the site is: sandbox-direct-primate-6193de57e34fc84858e34d98.netlify.app
Thank you
Hi @GonzaloHirschToptal,
Just to confirm, are you able to do this without JSClient
, that is using simple node-fetch
?
I haven’t tried using node-fetch
, we are using the js-client
from Netlify. In order to use node-fetch
I’d have to change our setup.
I’m just looking to confirm if the same thing works with node-fetch
at the moment - so just to isolate the source of error - if it’s the JSClient or something else.
So a simple test would possibly work too - no need to rewrite the entire thing.
Just tried it, and I got the same error. The only thing is that I can see a better error, which is { errors: { path: [ 'is invalid' ] } }
.
In case you need the url of the request, it’s:
url: 'https://api.netlify.com/api/v1/sites/b7697821-daf3-4d43-9829-dda57150b70f',
status: 422,
statusText: 'Unprocessable Entity',
From what I see, the url is correct, and the ID is too.
If I remove the repo
property from the request body (leaving only the build_settings
), it goes through properly, but my environment variables are not updated.
I had assumed it was the repo
that’s causing problems, because the repo
object is probably not supposed to be updated via the API. Also, I checked the UI and it uses only the build_settings
object:
If that works for the UI, it should work for the fetch call too as it’s basically doing the same thing.
How exactly did you add the environment variables?
@hrishikesh I realized, after removing the repo
, that I was making a mistake with how I was sending the environment variables. It works now that I made a correction.
I included repo
because it was detailed in the API docs, so it might be best to update the docs with the properties we can actually change. It’s not the first time I’ve been sending properties that are ignored or throw errors but are detailed in the Open API docs.
Thanks for the support