Secrets API?

Is there a way to programmatically set secrets without using Wrangler? Use case is refreshing tokens with relatively short expiry without having to make a reauth request with the main application key on every request.

Last time I checked, you can set them during script upload with the documented PUT script, or update them one at a time using the undocumented create secret endpoint. e.g.

PUT https://api.cloudflare.com/client/v4/accounts/${accountId}/workers/scripts/${scriptName}/secrets
Content-Type: application/json
{ "name", "${secretName}", "text", "${secretValue}", "type", "secret_text" }
1 Like

I see. Not sure if I’ll use the undocumented API, but if I don’t, I guess I can hack together something with Download/Upload Worker in a separate worker instance.

Rereading the docs, it looks like another option is to persist using globalThis. That would be a lot simpler.