API docs for uploading worker module incorrect

According to the docs for uploading a worker module, bindings should be directly placed on the root metadata object:

{
  "main_module": "worker.js",
  "some_binding": "stuff"
}

However, from testing it appears that bindings need to be placed in a specific "bindings" format instead:

{
  "main_module": "worker.js",
  "bindings": [{
    "type": "plain_text",
    "name": "some_binding",
    "text": "stuff
  }]
}

Could the docs for this be updated? It also appears other fields e.g. compatibility_date, compatibility_flags, usage_model, etc. are not yet included in the docs.

Hi.

I am trying also to use the Cloudflare API to upload a worker module especially only the second-file.js
module but i allways get this error messages !

Can somebody tell me what are the right values for uploading just the second-file.js module
using the Cloudflare api and curl on the origin server.

This curl values here do not work !

curl -X PUT “https://api.cloudflare.com/client/v4/accounts/XXXX/workers/scripts/module-worker-01
-H “X-Auth-Email: [email protected]
-H “Authorization: Bearer XXXXXXX”
-H “Content-Type: multipart/form-data”
–form ‘“second-file.js”=@./SecondModule.js;type=application/javascript+module’

{
“result”: null,
“success”: false,
“errors”: [
{
“code”: 10021,
“message”: “Uncaught TypeError: Main module name is not present in bundle.\n”
}
],
“messages”:
}

curl -X PUT “https://api.cloudflare.com/client/v4/accounts/XXXX/workers/scripts/module-worker-01
-H “X-Auth-Email: [email protected]
-H “Authorization: Bearer XXXXXXX”
-H “Content-Type: multipart/form-data”
–form ‘“main.js”=null’
–form ‘“second-file.js”=@./SecondModule.js;type=application/javascript+module’

{
“result”: null,
“success”: false,
“errors”: [
{
“code”: 10021,
“message”: “could not read content for part metadata”
}
],
“messages”:
}

Have also tried to use the other api call just to upload a worker module without that
i need send a unchanged main module to be overwritten but it does not work too

curl -X PUT “https://api.cloudflare.com/client/v4/accounts/XXXX/workers/scripts/second-module-01
-H “X-Auth-Email: [email protected]
-H “Authorization: Bearer XXXXXXX”
-H “Content-Type: application/javascript+module”
–data “export let TestServiceWorker = ''TestSeviceWorker”

{
“result”: null,
“success”: false,
“errors”: [
{
“code”: 10001,
“message”: “workers.api.error.content_type”
}
],
“messages”:
}

I need a posibility to upload a second worker module without to send a unchanged main worker module.
Thanks in advance for the help solving this problem.

I know this is quite late, but just in case anyone else is reading: I don’t think that is possible at the moment, all files must be uploaded again for each deployment.

just wonder anyone from cf team could update the doc

You can open is issue to add to/update the Cloudflare documentation @mark123456