I’m trying to use the Netlify API to deploy functions and I’m following this “Deploy via API” docs.
With File Digest method:
- Create a site and get the site id from response:
curl --request POST 'https://api.netlify.com/api/v1/sites' \
--header 'Authorization: Bearer $NETLIFY_TOKEN'
- Create a new deployment for that site with function metadata and the
deploy_id
from response:
curl --request POST 'https://api.netlify.com/api/v1/sites/d297fc64-1692-4146-b184-66975d507448/deploys' \
--header 'Authorization: Bearer $NETLIFY_TOKEN' \
--header 'Content-Type: application/json' \
--data-raw '{
"functions": {"hello-world": "deb21d35d1a9a876b01d67152bbf3f666a728653"}
}'
And it returned 200
response with required_functions
parameter as above.
- Upload the serviceless function using functions API:
curl --request PUT 'https://api.netlify.com/api/v1/deploys/60ff7b22a54bc2535f6754da/functions/hello-world?runtime=js' \
--header 'Content-Type: application/octet-stream' \
--header 'Authorization: Bearer $NETLIFY_TOKEN' \
--data-binary '@/Users/sri/test-netlify-fns/hello-world.js'
And it returns the following 400
response:
{ "errors": "Deploy has already been finalized." }
I tried using zip file instead of direct js file in the body, but it still returns the above error.
- I also tried uploading the function using files API:
curl --request PUT 'https://api.netlify.com/api/v1/deploys/60ff7b22a54bc2535f6754da/files/hello_world.js' \
--header 'Content-Type: application/octet-stream' \
--header 'Authorization: Bearer $NETLIFY_TOKEN' \
--data-binary '@/Users/sri/test-netlify-fns/hello-world.js'
And it returns the following 401
response (which is not a proper json):
{
"code": 401,
"message": "Access Denied: deploy must be in , not new"
}
{
"code": 401,
"message": "Access Denied: User does not have access"
}
I did try above request with same headers/data on different site (which has some static files) and it returns 200
response. So, it’s not a credential issue.
Can someone help me to figure what’s the issue here?