JuM
April 9, 2020, 3:05pm
1
I want to use the API token feature to upload a Cloudflare Worker. That’s after all much better than a general API key.
So I used the standard Workers template from the web interface. But I get the message back from the API that:
PUT method with API Tokens is not supported by this API code
But the Cloudflare API requires a PUT
action to upload a Worker.
So how do we upload Workers with an API Token? Is this even possible?
2 Likes
JuM
April 16, 2020, 6:48am
2
I asked Support and they confirmed that API tokens do work with Cloudflare Workers. So I went through all my settings & code again to find the error.
The mistake I made was to use the following API end point with API Tokens:
https://api.cloudflare.com/client/v4/zones/{ZONE_ID}/workers/script
This end point works fine with the regular, general purpose API key. But it fails with the API tokens feature.
This API end point to upload a worker does work with API Tokens:
https://api.cloudflare.com/client/v4/accounts/{ACCOUNT_ID}/workers/scripts/{SCRIPT_NAME}
It seems to be undocumented why API Tokens are incompatible with the earlier end point I used all the time earlier, but now I do have my issue solved.
3 Likes
Thanks for sharing the solution!
2 Likes
JuM
April 16, 2020, 7:28am
4
Thanks Thomas! Hopefully it helps someone else with the same problem.
1 Like
mholt
April 30, 2020, 6:04am
5
It did. Thanks.
Running into the same issue with zones/:zone_identifier/dns_records/:identifier
for PUT
and PATCH
methods.
Edit: Ah, found the problem. Misassembled the URI. Confusing error message, but… I should not be coding after midnight…
1 Like
ember
April 7, 2021, 12:51pm
6
I ran into the same error, by coincidence my terminal line-broke right where the error was.
The real error is with a missing / character. In my case, my request URI was /zones/$ZONE-ID/dns_records$RECORD-ID
(note the missing / between dns-records
and $RECORD-ID
) but I didn’t catch it right away because the edge of the terminal was right after the s
in dns-records
. Silly mistake, but sillier error message. Malformed URI requests should return with an error indicating such.