ramigs
September 25, 2019, 7:44pm
1
Hello all,
I’m trying to create a build hook through the API, using netlify/js-client
,
from a Node.js console script.
I’m calling netlify.createSiteBuildHook()
and its successfully creating the
hook.
try {
result = await netlify.createSiteBuildHook({
site_id: 'SITE_ID',
title: 'Build from function',
branch: 'master'
});
console.log(result);
} catch (e) {
console.log(e);
}
However, title
and branch
parameters seem to be ignored, as the hook in the
UI is created with empty name and branch.
Also, in the response, both fields are returned null
.
This is the intercepted payload of the request and response:
"scope": "https://api.netlify.com:443",
"method": "POST",
"path": "/api/v1/sites/SITE_ID/build_hooks",
"body": "",
"status": 201,
"response": {
"title": null,
"branch": null,
"url": "https://api.netlify.com/build_hooks/SITE_ID",
"created_at": "2019-09-25T19:12:01.829Z",
"id": "5d8bbc018b502a88aa760ed0",
"site_id": "SITE_ID",
"msg": "POST https://api.netlify.com/build_hooks/5d8bbc018b502a88aa760ed0 to trigger a build"
},
Is this a possible bug or am I calling the method the wrong way?
Thanks!
fool
October 1, 2019, 5:54pm
2
I can’t speak to writing code directly against that client, or whether that is a bug, but you can take a look at how our API does it when you create one using the guidance here:
Last reviewed by Netlify Support: December 2022
Did you know that Netlify has an extensive public API ? Anything that you configure in our Admin UI at https://app.netlify.com is managed using this same API, and you’re welcome to use it to create and configure your site(s) and perform most other operations on your account.
We have an article on API Usage in our official documentation which shows how to do some common tasks like deploying your site and configuring it in great detail. It also talk…
If that doesn’t seem to match the client, then yup, I’d file a bug against the js-client for our tools team to take a look at!
ramigs
October 1, 2019, 11:01pm
3
Thanks @fool .
I’ll investigate further and open the issue, in case it’s a bug.
Thanks @ramigs . Opening an issue is the best way to get that fixed if there is a bug.
ramigs
October 5, 2019, 7:44pm
5
I’ve figured this out.
There’s no issue, it was a misunderstanding on my part regarding how the client
expects to receive path parameters vs body parameters.
This is the correct version of the code:
result = await netlify.createSiteBuildHook({
site_id : siteId,
body : {
title : title,
branch : branch
}
});
Working as expected. Thanks!