|
| 1 | +--- |
| 2 | +title: Fixed and documented Workers Routes and Secrets API |
| 3 | +description: The Workers Routes API now returns a correct response and the Secrets API has been added to the Cloudflare API docs. |
| 4 | +products: |
| 5 | + - workers |
| 6 | + - workers-for-platforms |
| 7 | +date: 2025-04-15T00:00:00Z |
| 8 | +--- |
| 9 | + |
| 10 | +## Workers Routes API |
| 11 | + |
| 12 | +Previously, a request to the Workers [Create Route API](/api/resources/workers/subresources/routes/methods/create/) always returned `null` for "script" and an empty string for "pattern" even if the request was successful. |
| 13 | + |
| 14 | +```bash title="Example request" |
| 15 | +curl https://api.cloudflare.com/client/v4/zones/$CF_ACCOUNT_ID/workers/routes \ |
| 16 | +-X PUT \ |
| 17 | +-H "Authorization: Bearer $CF_API_TOKEN" \ |
| 18 | +-H 'Content-Type: application/json' \ |
| 19 | +--data '{ "pattern": "example.com/*", "script": "hello-world-script" }' |
| 20 | +``` |
| 21 | + |
| 22 | +```json title="Example bad response" |
| 23 | +{ |
| 24 | + "result": { |
| 25 | + "id": "bf153a27ba2b464bb9f04dcf75de1ef9", |
| 26 | + "pattern": "", |
| 27 | + "script": null, |
| 28 | + "request_limit_fail_open": false |
| 29 | + }, |
| 30 | + "success": true, |
| 31 | + "errors": [], |
| 32 | + "messages": [] |
| 33 | +} |
| 34 | +``` |
| 35 | + |
| 36 | +Now, it properly returns all values! |
| 37 | + |
| 38 | +```json title="Example good response" |
| 39 | +{ |
| 40 | + "result": { |
| 41 | + "id": "bf153a27ba2b464bb9f04dcf75de1ef9", |
| 42 | + "pattern": "example.com/*", |
| 43 | + "script": "hello-world-script", |
| 44 | + "request_limit_fail_open": false |
| 45 | + }, |
| 46 | + "success": true, |
| 47 | + "errors": [], |
| 48 | + "messages": [] |
| 49 | +} |
| 50 | +``` |
| 51 | + |
| 52 | +## Workers Secrets API |
| 53 | + |
| 54 | +The [Workers](/api/resources/workers/subresources/scripts/subresources/secrets/) and [Workers for Platforms](/api/resources/workers_for_platforms/subresources/dispatch/subresources/namespaces/subresources/scripts/subresources/secrets/) secrets APIs are now properly documented in the Cloudflare OpenAPI docs. Previously, these endpoints were not publicly documented, leaving users confused on how to directly manage their secrets via the API. Now, you can find the proper endpoints in our public documentation, as well as in our API Library SDKs such as [cloudflare-typescript](https://github.com/cloudflare/cloudflare-typescript) (>4.2.0) and [cloudflare-python](https://github.com/cloudflare/cloudflare-python) (>4.1.0). |
| 55 | + |
| 56 | +Note the `cloudflare_workers_secret` and `cloudflare_workers_for_platforms_script_secret` [Terraform resources](https://registry.terraform.io/providers/cloudflare/cloudflare/latest/docs) are being removed in a future release. This resource is not recommended for managing secrets. Users should instead use the: |
| 57 | + |
| 58 | +- [Secrets Store](/api/resources/secrets_store/) with the "Secrets Store Secret" binding on Workers and Workers for Platforms Script Upload |
| 59 | +- "Secret Text" Binding on [Workers Script Upload](/api/resources/workers/subresources/scripts/methods/update/) and [Workers for Platforms Script Upload](/api/resources/workers_for_platforms/subresources/dispatch/subresources/namespaces/subresources/scripts/methods/update/) |
| 60 | +- Workers (and WFP) Secrets API |
0 commit comments