Updating worker route via REST API

We’re getting the following

{

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

When attempting to run

curl -X PUT “https://api.cloudflare.com/client/v4/zones/$CF_ZONE_ID/workers/routes/$ROUTE_ID
-H “X-Auth-Email:$ACCOUNT_EMAIL” -H “X-Auth-Key:$CF_API_TOKEN”
-H “Content-type: application/json”
–data ‘“pattern”: “dev.domain.com/*","script”: “script-name”,’

I’m not sure where we might be doing wrong to get

“code”: 10001,
“message”: “workers.api.error.content_type”

Any ideas?

Well we just found one issue. Code is actually as follows

curl -X PUT “https://api.cloudflare.com/client/v4/zones/$CF_ZONE_ID/workers/routes/$ROUTE_ID”
-H “X-Auth-Email:$ACCOUNT_EMAIL” -H “X-Auth-Key:$CF_API_TOKEN”
-H “Content-type: application/json”
–data ‘“pattern”: “dev.domain.com/*","script”: “script-name”,’

and the error code is

“code”: 10026,
“message”: “workers.api.error.parse_body”

That’s invalid json I believe, you need curly braces around your input. Try editing json as a file (eg. body.json) then use --data @body.json so that curl reads input from file. This will allow you to easily validate the json you’re sending by either piping it to jq (cat data.json | jq .) or by using an online json validator.

Right. Damn, those got stripped out, and I didn’t see it. All working

1 Like