Interacting with the Cloudflare API from a Worker
# workers-help
g
I am trying to interact with the Cloudflare API from within a Worker. I want to be able to update a Zero Trust Gateway Rule per the API docs here: https://developers.cloudflare.com/api/operations/zero-trust-gateway-rules-update-zero-trust-gateway-rule The code I am using to interact with the API looks like this:
Copy code
const url = `https://api.cloudflare.com/client/v4/accounts/${ACCOUNT_ID}/gateway/rules/${POLICY_ID}`;

const response = await fetch(url, {
  method: 'PUT',
  headers: {
    'X-Auth-Email': API_EMAIL,
    'Authorization': `Bearer ${API_TOKEN}`,
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({
    action: "block",
    enabled: false,
  })
});
This code is intended to disable the rule. But when I run it I just get an error:
Copy code
{
  "result": null,
  "success": false,
  "errors": [
    {
      "message": "must include at least one condition or expression"
    }
  ],
  "messages": []
}
I don't understand what "must include at least one condition or expression" means in this context. I also don't understand what the
action
string is supposed to do or how it should be used correctly. If anyone could help me understand this I would really appreciate it. Thanks!