Cannot deploy function via API (tried all solutions)

I am using the Netlify API from within a serverless Node.js Google Cloud function. I have successfully gotten both .zip file deployment as well as file digest deployment working and it’s great!

The only problem I’m having is that I cannot get the digest for the functions to work…

My function has 0 third-party dependencies and the only import is the native https module.

async function createFileDigestDeployForSite(netlifyToken, fileDigests, functionDigests) {
  try {
    const response = await
        files: fileDigests,
        functions: functionDigests
        headers: {
          Authorization: `Bearer ${netlifyToken}`,
    console.log('Digest created:',;
  } catch (error) {
    console.error('Error creating file digest:', error.message);

I’m using zip-a-folder 3rd party library to perform the zip operation.

This is immensely frustrating because the OpenAPI spec and docs offer no real-world example of deploying functions through the API. In fact, one must refer to both the OpenAPI schema as well as this additional document here Deploy functions | Netlify Docs just to know that it has to be a zip file.

When I send the functions digest in the request body I just get back a deploy response with NO required_functions and then a 404 when I try to upload the function itself.

It seems many others have had difficulty with this so can you please make an example request for this.

Since the zip-it-and-ship-it is ESM only, I cannot use it in my code and I also do not think this is the issue.

It’s frustrating that someone had a long thread and after multiple back and forth the docs were barely updated with only a sentence or two and it took the support team 10 months to reply. I do not have 10 months to wait as we are launching a product on Netlify and need this working ASAP as advertised in the documentation.

I can 100% confirm that the data is being sent correctly:

  "files": {
    "/asset-manifest.json": "e0d898ce652aaa94be3c22559d0fbf5b9ce41d61",
    "/favicon.ico": "1120538c77ad1f28a89243b4b53fe2ac16cc3bc6",
    "/index.html": "bdbd0c7b70ede3b153bd73cfc930d052dd64bea6",
    "/logo192.png": "7f4f2d68782a7fafceda84554ecab9b489877500",
    "/logo512.png": "46915f9d02694ed49bfc7a9534947684103dc3fe",
    "/manifest.json": "4e0afe7f81a71f41366cd7859ca34776b8107923",
    "/robots.txt": "044ce68f83ee8543475fea16f6e3a73d28a1c6d5",
    "/static/css/main.d0e2702b.css": "c5b010c3f49c1b6543ba86c6bf4cb4e98f8e75d8",
    "/static/css/": "5b33791169a49805f65b2272c8ecac76be31f78a",
    "/static/js/787.a3103ff7.chunk.js": "b4a563ff2b09c23d0958b09b9daa54bc7c8cc5cb",
    "/static/js/": "6cf539ae9acc2149040c690dccbcccff0758d01a",
    "/static/js/main.e8400d06.js": "c9998ed7668f841ee80488957f49fa436c4bfdf8",
    "/static/js/main.e8400d06.js.LICENSE.txt": "ed76601ac7c48241737b4c55b230a8f6cec38c13",
    "/static/js/": "a72d338ad044979a93543123cbded64a606783ab"
  "functions": {
    "query": "13a5d1fbdc70a2d070f8419203ab825c9b9c6a81bfe89d6708566ffad379c998"

But I don’t get required_functions in the digest, it appears this functionality is broken. I have spent over 24 hours on this so I’d really appreciate a reply, I’m on the Pro plan.

Here is the response after submitting the digest to the /sites endpoint.

Digest created: {
>    id: 'd6418924-1ea5-4629-af5b-a398c861af21',
>    deploy_id: '649f4c5150d4bf42d17df750',
>    subdomain: 'enchanting-donut-71d5ea',
>    url: '',
>    state: 'new',
>    required: []
>  }

It appears that the endpoint does not work for uploading functions. This really should be documented in the API / docs since this link says you can send the digest directly when you create a site to avoid two HTTP requests.

In fact, this doesn’t work at all for functions as I previously noted. It appears to only work in a two step process of first creating the site and then creating a deploy. If someone had simply documented this, I could have saved hours of my own time, and avoided opening a support ticket. As a software engineer… very annoying.

I can’t confirm it is working right away but I am seeing the required_functions key in the response now.

Ok, after swapping to the two step process of creating a site and only then uploading the digest afterward… I try to upload the zip file of the required function. I’ve tried both in a (1) Postman request (2) Node.js axios request.

I’m getting a 500 Internal Server Error with the message unexpected status code from Functions Origin: 400

I can’t find any reference to this on the forums.

Due to your number of posts and your progress on this issue, the answer to your last response starts towards the end (you can find it with a bold heading). The rest of the post aims to clarify the rest of the things you’ve raised in this thread.

Points to address:

There are 2 problems in your setup. Please note that this could take a few back-n-forth, and if you’re not mentally prepared for this, it’s just going to lead to frustration on your end.

Problem #1 - Incorrect endpoint:

(you have figured it out towards the end, but I thought I’ll mention it for anyone else to find)

You’re using the wrong endpoint. The endpoint is (documented here)

Problem #2 - Invalid zip:

Generating a correct zip is not as simple as just putting the JS/TS file inside a zip. Even if you’re not using any dependencies, the code needs to be bundled! Try using a simple code like (in ESM mode, with node_bundler as esbuild (as required for ESM code):

export async function handler() {
  return {
    body: 'Hello world!',
    headers: {
      'content-type': 'text/plain'
    statusCode: 200

and using Netlify CLI to bundle it locally. You can then see the generated zip is not as simple. The deploy would probably work though even if you submit an invalid zip, but your function might fail to run.

However, if you’re using everything default (in CJS mode), it should work fine.

The Open API specification is auto-generated from a YAML file, I believe. I think it doesn’t offer a way to provide examples, though I could be wrong on that.

You can skip the Open API spec to read about API deploys. The Netlify Documentation has far more information.

Reason mentioned in Problem #1.

I had put a basic example here: Cant figure out how to make put request using fetch in javascript - Support - Netlify Support Forums, but I haven’t shown functions in there. Deploying manually via API and that too functions, is a very rarely-used use-case, so we (support team) did not invest much in writing Support Guides for it as opposed to much more common issues for which the Support Team has written vaious guides. This is also partly because, API deploys can be done in many ways. I can write a guide in JavaScript, but someone else can come saying they want in Python, someone might want in Java, etc. It’s not possible to do that. Even then, I’ll try to keep one guide ready when I get a chance.

Unfortunately, that is a part of your problem.

Please don’t provide wrong information. The Support team replied as per normal expected timings. The bug was identified and posted to the devs within 3 days, which we consider fast enough on public forums. Those speeds might not meet your expectations, but that’s as fast as we can be right now. The actual bug, however took a year to be fixed, only because it was a very minor impact. The problem in the thread you linked was only when uploading functions without uploading any files. This has nothing to do with your case.

Again, you’re holding it wrong, I’m afraid.

To clarify, forums don’t have any response time guarantee. We try to be as fast as possible, without any assurance. In the helpdesk, we try to get back to Pro tier within 3 to 4 days (though most responses are faster than that). Furthermore, the post is only 17 hours old right now. You might have spent 24 hours before posting, but unfortunately that cannot be used to count our response time.

Incorrect endpoint.

You’re right.

It talks about deploying via ZIP. In the docs you’ve linked we have not mentioned you can create and deploy in the same API call for deploying via file-digest. Sorry to say, but there’s a chace you might have assumed some things and thus, it did not work as expected.

This has been mentioned in the docs under File digest method. Quoting:

We recommend using a digest including a file path and SHA1 for each item. This method also allows you to upload serverless functions, however serverless functions should use SHA256 instead.

Answer to the last response here

This could be very much due to the invalid zip that you’re generating. If you share the response headers that could include a request ID of some kind, we can check our logs for that.

Thank you for your detailed response.

  1. Nowhere is it mentioned that you have to use the endpoint to upload functions.

When creating a new site, you can include a file digest or a ZIP file straight away, to save an HTTP request.

Please amend the documentation so that it says that you cannot upload functions through this endpoint. To create a great developer experience, I shouldn’t have to “figure it out” as you stated.

  1. I actually did test the bundling of my function using the command netlify build and it bundled the function into a zip with no other file contents apart from [FUNCTION_NAME].js so I’ve already investigated this. There is no difference between me using the zip-it-and-ship-it package. There is a way I could add ESM support to use the package directly but it affects other parts of my setup and I have no desire to. As I explained my function has zero third-part dependencies. I used Postman to upload the zip file created by netlify build and the operation is still failing with the same error.

  2. The OpenAPI schema says to send the response body (which is meant to be a zip) as application/octet-stream which I have seen others become confused about and I was as well. Reading the OpenAPI schema doesn’t say anything about this. The documentation simply says that the file should be zipped before uploading without specifying how to bundle it either using netlify build.

  3. The OpenAPI schema does support examples, since the Netlify API is not a massive API I would encourage your team to invest the time to add examples (you can add a single inline example or multiple examples to each endpoint). While this may take you a few days to do, it will likely result in far less tickets being opened here and actually save you time and effort.

  4. I am willing to create an end-to-end documentation guide for how to use the API manually if I am assigned credit and you can help me past this last impasse.

  5. For the time being I have swapped to using automatic branch deploys since this seems to be better supported but my wish was to do everything programatically as part of a reproducible pipeline without doing anything in the Netlify UI.

  6. The 500/400 error message I posted regarding my attempts to upload the zip files is uninformative and unhelpful. Please have the 500 error that it turn references the Functions 400 Bad Request error actually try to report some information.

  7. I will try again with a request ID and reference it in the next message.

It’s mentioned above the section you’re quoting:

With the specifics for Functions listed here:

You’re right. I edited my response above to say what I meant. I’m used to using ESM in my projects, so I just tried with the values I was using instead of the defaults. If you’re using a JS file in CJS format, simply adding it to zip should work.

That’s about zip file method, which you’re not supposed to use for functions.

It’s mentioned above the section you’re quoting:

I am not referring to the fact that the File digest method documentation text says that you can upload serverless functions. I am referring to the fact that:

When creating a new site, you can include a file digest or a ZIP file straight away, to save an HTTP request.

Does not make it clear enough that you cannot upload functions through the sites endpoint to save an HTTP request. Do you understand the nuance?

That’s about zip file method, which you’re not supposed to use for functions.

Actually I was referring to Netlify API documentation which is absolutely used for function upload. I am not referring to the zip file method of uploading files.

To explain my use case:

  1. A user clicks “Deploy Site” in my own web application.
  2. A site is created
  3. The function and file digest is used to create a deploy.
  4. The deploy response returns required_functions and required.
  5. Any missing files are uploaded to Netlify using the appropriate endpoints.
  6. Environment variables specific to each user are set at a site level.
  7. A subdomain is created for the customer at

Since the automatic branch subdomain deployments seems to be an easier solution I have moved towards that. The only issue I’m having there is that I’m unsure of at what point in the deployment process the environment variables need to be set. My current intention is to use a webhook for Deploy succeeded to update the environment variables at a branch level (which is supported in documentation) once Netlify responds to the new branch on Github. The steps look like this, though I realize this might be a tangent from the original issue which I still desire to resolve. I assume that having a separate Git branch for each customer might just be a better solution in general since we can easily update it for them and everything will be tracked in version control.

  1. User clicks “Deploy Site” in my own web application
  2. The backend uses a Github access token to create a new branch reference
  3. Once the Netlify automatic subdomain branch deployment is complete, send a webhook to my backend handler endpoint.
  4. Add environment variables at branch level.

I’d personally recommend creating a separate site from each branch as in the long run, that would probably be easier to manage. But if you wish to do it all on the current site, you can also create variables for the branch before creating a branch on GitHub, so you can skip that webhook part. The payload would look:

context: "branch"
context_parameter: "branch-name"
value: "bar"

Thanks, that is great to know, I really appreciate it. I’d still like to resolve the original issue but since I am time and effort constrained at the moment I think I will folllow the automatic deploy approach which offers more benefits and seems more robust given the number of customers using it vs the manual uploads.

I will re-attempt the manual upload when I have time and will update this thread after re-reading your responses and trying again.

Sounds great. We will pick up the discussion then! Good luck with your launch!

@hrishikesh Everything is working well, however I’m using a Netlify serverless function with function-scoped branch context based API keys for OpenAI. This is then safely passed to my server (server - server) without exposing it to the client-side code.

The API requests can take some time to execute (particularily on a cold start to my own server). I see the current limit is 10 seconds. I’m definitely going to need this increased to the Pro tier maximum of 26 seconds as I’ve seen mentioned elsewhere.

I believe that this should suffice (a chat response longer than this is pretty useless anyway) but in the event that I need even more can you let me know the pricing privately? From my experience AWS Lambda has a timeout of 15 minutes.

The other option is to make the request asynchronous and post the result to a websocket when it is done.

Let me know if you’d prefer me to open another issue.

Anything about 26 seconds would need a background function, so it would be async.


On average it is taking 15 seconds for the cold function to warm-up. Could you increase to the limit for the Pro plan? I just sent an email to support. As we have more usage on our platform, this delay will fall because there will always be a function instance running, but we need this for launch of our product in the first few weeks to months.

Hey @scrumptious_monkey ,

We’ve raised functions timeout and responded in your helpdesk ticket.