So, I thought I had the answer for you, as I went down the Makefile / bash script deployment route a while ago. Unfortunately, I only use the workers/script/$scriptname endpoint with the metadata.json automagically configuring the KV stores to attach. There might be some additional configuration options in metadata.json, but I’ve not used it yet.
Probably not much help, and I can’t seem to find the API docs that specify the metadata format right now.
Thanks for trying though,
its surprising to me that they didn’t do this, i mean the only reason i tried this platform was the simplicity of writing piece of javascript and getting it deployed running.
I’m sure they will add it in future.
My usecase is to deploy customer submitted potentially malicious javascript in a sandbox environment not in my backend…
I’m gonna try to use these v8 workers myself lets see if its easy enough
I just found this thread as I was about to open my own on the same topic. I’m surprised to see this functionality to be missing. For my use case, being able to deploy a worker using curl is a must, even though Wrangler is awesome. I solved this for me by writing a Node package for deploying a script to Workers (with KV support) without the use of Wrangler. It uses the same APIs as the “Quick Edit” web UI for Workers does. It requires filling in a few values to secrets.json for it to function. At the moment I don’t plan on automating getting these values (which could be done by logging in in the script and obtaining them, however, it would get complicated with 2FA pretty quick).
So either at some point it was there, or was supposed to be there, but they didn’t get to it, or someone thought was there when it wasn’t or it is actually there, just impossible to find documentation for?
Awesome, thanks @olivergrant! I’ll be the last person to dispute my garbage searching skills, still seems to be somewhat well-hidden to me though. Anyway I’m just glad to see this actually exists. I’ve updated my library above to use this API, but it’s so simple it’s not even necessary to have it anymore. Would be cool if the endpoint for listing workers could return the worker URL, too. As it stands, the subdomain of workers.dev is not something which can be obtained using the API, correct?
Edit: I should also add that the OP’s problem with the API is not a thing anymore with the current API.
Indeed creates a worker, but it’s not deployed. How do I toggle on the deploy thing just like the UI allows? I’m using workers.dev. I thought I should add a route but the endpoint for that is curl -X POST https://api.cloudflare.com/client/v4/zones/$ZONE_ID/workers/routes and a workers.dev subdomain is zoneless as far as I understand.
(sorry about the multiple-posting, wish I found the preview pane before…)
Here’s some javascript code that contains examples of deploying to workers and workers.dev, including sites, kv bindings, kv namespaces, routes, and environment variables.
Above workarounds unfortunately don’t work anymore. Is there any way to deploy a worker through the API? I’m so confused as to why there is nothing about this in the documentation.
Is this possible? Nothing in this thread seems to work. Deploying the code via API is possible, but is it possible to publish to workers.dev via the API?
Edit: Never mind, yoav2’s answer above works. Missed the part about adding /subdomain to the end of url. Worked great!