Hi i am trying to update a set of sites to build from a different branch via the API.
Should this work?:
const payload =
{
"branch": "main",
"allowed_branches": [
"main"
],
"skip_prs": null
}
;
const neltifyEditSiteRes = await fetch(`${netlifyAPIBaseUrl}/sites/${site_id}`, {
method: 'PUT',
headers: {
'Content-Type': 'application/json',
Authorization: `Bearer ${netlifyAccessToken}`,
body: JSON.stringify(payload),
},
});
I have tried both PUT
and PATCH
both return with no errors but the site is not updated?
1 Like
Seems like you’re putting the body in headers. Does moving that outside change things or was this a copy/paste error when typing on the forums?
@hrishikesh thank you, sorry for the confusion that was a Copy Paste error…
I have also found the issues:
i need to wrap the payload in a build_settings
object:
const payload = {
"build_settings": {
"branch": "main",
"allowed_branches": [
"main"
],
"skip_prs": null
}
};
const neltifyEditSiteRes = await fetch(`${netlifyAPIBaseUrl}/sites/${site_id}`, {
method: 'PATCH',
headers: {
'Content-Type': 'application/json',
Authorization: `Bearer ${netlifyAccessToken}`,
},
body: JSON.stringify(payload),
});
1 Like