Hello Colleagues!
I’m trying to do the following things using Netlify Rest API:
- Link my existing Githb Repo that has a Gatsby Starter to Netlify
- Deploy that Repo on Netlify
Here is what I do:
- Authorize and receive the required auth “Code” from netlify
- Fire a POST request to get my deploy_key ID:
await axios.post(
https://api.netlify.com/api/v1/deploy_keys?access_token=${code}
)
- I make another POST request to link my GitHub repo with Netlify:
Here is the “payload” that I pass:
{
“repo”: {
“provider”: “github”,
“id”: “201622405”,
“repo”: “VasilyMur/defeated-sparkling-mice”,
“repo_url”: ''url",
“private”: false,
“branch”: “master”,
“cmd”: “gatsby build”,
“dir”: “public/”,
“deploy_key_id”: “1111111111111111” <<< id that I get from the previous call
}
}
What happens next?
Well, I get a response where I receive confirmation that the Site has been created:
{ id: ‘1111111-1111-1111-1111-11111111111’,
site_id: ‘1111111-1111-1111-1111-11111111111’,
build_id: ‘111111111111111111111111’,
state: ‘current’,
name: ‘distracted-torvalds-e27774’,
url: ‘url’,
…
}
- Then I finally make a GET request using my Netlify Auth Code (passing the SITE_ID from the previous step):
api.netlify.com/api/v1/sites/${site_id}/deploys?access_token=${code}`
Here I receive status: 200 as well a bunch of other data like: site_id, url, branch and some other stuff.
The I visit my Netlify Admin and see “Deploy failed”.
PM: git ref refs/heads/master does not exist or you do not have permission
So… does it mean I need to get AUTH token from Github and Pass it?
Where should I pass it? Should I add it as a Payload in my “deploys” call somehow??
Please advise me on the right steps I should take in order to finally deploy my site from Github Repo using Netlify’s Rest API.
Thanks in advance!
Regards,
Vasily