No records matched on File Upload via Digest Deploy API

Site name: webase-test.netlify.app

Hey guys! First timer here! Excited to be working on an integration with WeBase [1] and Netlify!

Currently doing everything through the API. I am following the documentation here: Get started with the Netlify API | Netlify Docs

I start by creating a deploy:

POST https://api.netlify.com/api/v1/sites/5d713f3e-5c43-40b0-a705-5915911492ee/deploys

Sending this as the body:

{"files"=>{"/index.html"=>"a7a12da81336a3b36e58c720dd3c2c69ae5029da", "/home-ae89e0e2-8356-4f62-a171-163475c29300.html"=>"a7a12da81336a3b36e58c720dd3c2c69ae5029da", "/assets/application.css"=>"efba3e5593fa6314922a1de5d81348cdf1bf6a17", "/assets/apps.css"=>"dedb59b0be1857fbdc789394cd44ade71b8b7011", "/assets/websites.css"=>"3c8c0b46f9619c23aba78d27490f5f042a2d81e2", "/assets/pattern.css"=>"ea8d77b0ffc7fdc095e3dba87782d63e6331331c"}, "draft"=>false}

I get a 200 back with an deploy ID.

Next I try to upload this files. This is where I hit an issue. I upload 5 files (I skip one because it is the same file). And the first 4 uploads seem to fail

I am doing a PUT to:

https://api.netlify.com/api/v1/deploys/5fb01594c40d47a86f572674/files/index.html

with the contents of the file as the body.

Each request fails except for the last one with the following message:

{“code”=>422, “message”=>“No records matched”}

The last one… in this case the PUT to:

https://api.netlify.com/api/v1/deploys/5fb01594c40d47a86f572674/files/assets/pattern.css

Always succeeds.

It is making me think there is an issue with the order. But I am really not sure. The content of the body of the file upload is the same string I use to create the SHA1 digest that I send when creating the deployment.

It just seems odd that the last one works and the others ones fail. Also I can’t see anything in the Build console on the Netlify site.

Any tips or pointers here? Would love to see a fully running site that is 100% automated through the API!

Thank you for any help! Happy Saturday!

–harris

[1] https://www.webase.com

The more I think about this the more I think the contents of the file I use for the SHA1 digest has to be different from the file contents I am uploading.

I will refactor the integration to test this and let you know how it goes!

–harris

Hey @harris-at-webase,
Please keep us posted! Also wanted to share this blog post in case it’s useful in addition to the docs:

Ok…got the site published. But my CSS is not loading. Here is where I uploaded the application.css file:

Uploaded page to: https://api.netlify.com/api/v1/deploys/5fb12aefc40d47894a572a9b/files/assets/application.css,

SHA: 45b3c81c8bebb048ea1bbe4e42c750daffbeef63

The response is a 200:

parsed_response={“id”=>“assets/application.css,”, “path”=>“assets/application.css,”, “sha”=>“45b3c81c8bebb048ea1bbe4e42c750daffbeef63”, “mime_type”=>"", “size”=>158811}

But you can see the application.css file is not being found when you load the site here:

Any ideas? Is it a problem trying to host the CSS in a folder like this?

href="/assets/application.css"

Ideas?

Might be helpful to point out that when I viewed the site, I could see the files in the explorer however, only pattern.css had any content, and it was also the only one that worked?
All the others had no content and did not work.

I’m having a similar issue when I do the POST request to https://api.netlify.com/api/v1/sites/:site_id/deploys

I place the files in the body of the call like docs say to do

{
"files":{
   "/index.html":"bbc833bfbb64ec792f262d940fe27ebaebae01a4",
   "/first.html": "c5045de396718f8bed7d275a5db66889f8ba8fcb",
   "/second.html": "60a485665b50c25c0ac83b23417ac588421c6bb6",
   "/third.html": "9b780b93bf552555404bc5b13951fa568a005904"
}

}

In my response I get

  {
    "id": "5fb42dc5579f7a191c8945db",
    "site_id": "8640475d-9f19-4d34-b47f-5a0a19351f5f",
    "build_id": null,
    "state": "new",
    "name": "tender-lalande-6e744f",
    "url": "http://tender-lalande-6e744f.netlify.app",
    "ssl_url": "https://tender-lalande-6e744f.netlify.app",
    "admin_url": "https://app.netlify.com/sites/tender-lalande-6e744f",
    "deploy_url": "http://5fb42dc5579f7a191c8945db--tender-lalande-6e744f.netlify.app",
    "deploy_ssl_url": "https://5fb42dc5579f7a191c8945db--tender-lalande-6e744f.netlify.app",
    "created_at": "2020-11-17T20:08:37.230Z",
    "updated_at": "2020-11-17T20:08:37.285Z",
    "user_id": "5f472bba5c2911c32b69b797",
    "error_message": null,
    "required": [],
    "required_functions": null,
    "commit_ref": null,
    "review_id": null,
    "branch": null,
    "commit_url": null,
    "skipped": null,
    "locked": null,
    "log_access_attributes": {
        "type": "firebase",
        "url": "https://netlify-builds4.firebaseio.com/deploys/5fb42dc5579f7a191c8945db/log",
        "endpoint": "https://netlify-builds4.firebaseio.com",
        "path": "/deploys/5fb42dc5579f7a191c8945db/log",
        "token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ2IjowLCJpYXQiOjE2MDU2NDM3MTcsImQiOnsidWlkIjoiIn19.HQ5v-JTK12J4hf6U3S4YK8_WyEy1QQn1S6ab35PFcS0"
    },
    "title": null,
    "review_url": null,
    "published_at": null,
    "context": "production",
    "deploy_time": null,
    "available_functions": [],
    "screenshot_url": null,
    "site_capabilities": {
        "title": "Netlify Team Free",
        "asset_acceleration": true,
        "form_processing": true,
        "cdn_propagation": "partial",
        "build_node_pool": "buildbot-external-ssd",
        "domain_aliases": true,
        "secure_site": false,
        "prerendering": true,
        "proxying": true,
        "ssl": "custom",
        "rate_cents": 0,
        "yearly_rate_cents": 0,
        "ipv6_domain": "cdn.makerloop.com",
        "branch_deploy": true,
        "managed_dns": true,
        "geo_ip": true,
        "split_testing": true,
        "id": "nf_team_dev",
        "cdn_tier": "reg"
    },
    "committer": null,
    "skipped_log": null,
    "manual_deploy": true,
    "file_tracking_optimization": true,
    "plugin_state": "none",
    "has_edge_handlers": false
}

shouldn’t the state key have a value of “uploading” and the required key have a list of the shasums I need to upload?

if I try and do a PUT request with a file I get {“code”=>422, “message”=>“No records matched”} same response as OP.

Is it possible that the files with those SHA’s are already uploaded (even if not on your site - if I upload a file with:

<html>Hello World</html>

then you won’t need to upload the same one on your site - our system does not require them to be re-uploaded and we would not report them as needed in the response.

It seems like you’ve removed the site in the meantime so I can’t check it out after the fact, but if you’re still struggling and wanted to include 4 files that wouldn’t upload I can verify if they’re already in the system or no and potentially help debug.

i’m sorry but I can’t create a “SHA1” in javascript with view, do you have an idea how to do it?
and it’s possible to explain the 422 error

I would try using this NPM package: GitHub - emn178/js-sha1: A simple SHA1 hash function for JavaScript supports UTF-8 encoding.

Something like this:

let hash = sha1.create();
hash.update(STRING_FILE_CONTENTS_HERE);
let hashedFileContents = hash.hex();

I hope this helps.

–harris

1 Like