Error deploying a function to netlify using Netlify API

Hi there,

I’m trying to deploy a function to Netlify using NetlifyAPI, but there was an “Initial file records don’t match the uploaded ones” error which I have no idea about.

Here’s what I’ve done:

  1. Create a new site using API
curl --location --request POST 'https://api.netlify.com/api/v1/sites' \
--header 'Authorization: Bearer xxx' \
--header 'Content-Type: application/json' \
--data-raw '{
    "name":"hello-world-1111"
}'

Response:

{
    "id": "d7d6dfb0-d116-4e80-a6c2-625f84a1e00e",
    "site_id": "d7d6dfb0-d116-4e80-a6c2-625f84a1e00e",
    "plan": "nf_team_dev",
    "name": "hello-world-1111",
    "sso_login": false,
    "url": "http://hello-world-1111.netlify.app",
    "admin_url": "https://app.netlify.com/sites/hello-world-1111",
    "deploy_url": "http://63835e99adf1a07070911039--hello-world-1111.netlify.app",
    "state": "current",
    "created_at": "2022-11-27T12:56:57.399Z",
    "updated_at": "2022-11-27T12:56:57.479Z",
    "user_id": "5ccd27cab98081949c79a700",
    "ssl": false,
    "ssl_url": "https://hello-world-1111.netlify.app",
...
}

  1. Run netlify functions:create to init a sample ts function using “hello-world” template in netlify CLI

  2. Run netlify build create a zip file

  3. Get the hash of the zip file by passing the file path to this function:

function checksumFile(path) {
  return new Promise(function (resolve, reject) {
    let hash = createHash('sha256').setEncoding('hex');
    fs.createReadStream(path)
      .once('error', reject)
      .pipe(hash)
      .once('finish', function () {
        resolve(hash.read());
      });
  });
}
  1. Create a deploy using API

Request:

curl --location --request POST 'https://api.netlify.com/api/v1/sites/d7d6dfb0-d116-4e80-a6c2-625f84a1e00e/deploys' \
--header 'authorization: Bearer xxxx' \
--data-raw '{"functions":{"helloo":"a0436a6b46585ebb5e59b98c5b2daa5633b37b0ddbf52c7f05ef1c7204c3e344"}}'

Res:

{
    "id": "63836616603c3c62e02c0231",
    "site_id": "d7d6dfb0-d116-4e80-a6c2-625f84a1e00e",
    "build_id": null,
    "state": "uploading",
    "name": "hello-world-1111",
    "url": "http://hello-world-1111.netlify.app",
    "ssl_url": "https://hello-world-1111.netlify.app",
    "admin_url": "https://app.netlify.com/sites/hello-world-1111",
    "deploy_url": "http://63836616603c3c62e02c0231--hello-world-1111.netlify.app",
    "deploy_ssl_url": "https://63836616603c3c62e02c0231--hello-world-1111.netlify.app",
    "created_at": "2022-11-27T13:28:54.108Z",
    "updated_at": "2022-11-27T13:28:54.326Z",
    "user_id": "5ccd27cab98081949c79a700",
    "error_message": null,
    "required": [],
    "required_functions": [
        "a0436a6b46585ebb5e59b98c5b2daa5633b37b0ddbf52c7f05ef1c7204c3e344"
    ],

...

}

  1. Finally uploading the ZIP file

Request:

curl --location --request PUT 'https://api.netlify.com/api/v1/deploys/63836616603c3c62e02c0231/functions/helloo?runtime=js' \
--header 'authorization: Bearer xxxx' \
--data-binary '@/Users/hughdo/Desktop/test/nextauth_netlify/functions-template/helloo.zip'

Response:

{
    "name": "helloo"
}
  1. There was no error returned but when I went to the deploys page, I saw this:

“Production: Initial file records don’t match the uploaded ones”

Note: I’ve tried several ways to create ZIP file such as: zip the whole folder(except node_modules) or use esbuild to build the function then zip it.

Does anyone know about this issue? Did I do something wrong?

Thanks in advance.

Hey @mhughdo,

I don’t see you doing anything wrong (except for missing the content-type header), however I tried it multiple times and it appears to fail too.

I’ve escalated this to the devs and would let you know once we have more info.

Thank you. I deleted the content-type header to make the command shorter but it’s there. Looking forward to hearing from you soon

Hey there, @mhughdo :wave:

I just wanted to follow up and let you know we have not forgotten about you! Thanks for your patience here. We will share more when we know more.

1 Like

Hi @mhughdo :wave:t6: , I want to thank you for your patience while we work to resolve this issue. Our team is still looking into this and the issue has been escalated accordingly. I will reach back out when we have more information to share. :smiling_face_with_three_hearts:

Hey @mhughdo,

This should now be fixed.

@ hrishikesh Hi. Thank you for letting me know. I can confirm that the error has been fixed.

Before that, I had to upload the package.json and .zip files to fix the error.

Hi @mhughdo :wave:t6: , thanks for coming back and confirming the error has be fixed. I appreciate it and for providing the temporary fix you used in the meantime. (:

Hi @SamO, no problem. Actually, it was fun trying to find the temporary fix.

1 Like