Inserting multiple rules in one curl

Is there a way to insert multiple rules in one curl, or do I need a new curl for each one?

I tried this, but it only inserted the first one:

waf=$(curl https://api.cloudflare.com/client/v4/zones/$zone_id/rulesets/$ruleset_id/rules
–silent
–header “X-Auth-Email: $email”
–header “X-Auth-Key: $key”
–data '{
“description”: “Foo”,
“expression”: “blah blah blah”,
“action”: “block”
},
{
“description”: “Bar”,
“expression”: “yada yada yada”,
“action”: “block”
})

You can add a list of rules when creating a ruleset Cloudflare API Documentation or Update Cloudflare API Documentation. Keep in mind the update replaces all the rules so you can’t add one. It is easier to have separate rules under a ruleset.

To clarify, do you mean that it’s better to have one curl for each rules? Eg,

waf_one=$(curl https://api.cloudflare.com/client/v4/zones/$zone_id/rulesets/$ruleset_id/rules
–silent
–header “X-Auth-Email: $email”
–header “X-Auth-Key: $key”
–data '{
“description”: “Foo”,
“expression”: “blah blah blah”,
“action”: “block”
})

waf_two=$(curl https://api.cloudflare.com/client/v4/zones/$zone_id/rulesets/$ruleset_id/rules
–silent
–header “X-Auth-Email: $email”
–header “X-Auth-Key: $key”
–data '{
“description”: “Bar”,
“expression”: “yada yada yada”,
“action”: “block”
})

Guess it depends on how you are defining your rules and have much you expect them to change. If you only have rules that are created once and at the same them, then doing it in one go is better. If you have rules you want to update separately, then easier to have them independent.

I’m leaning toward the Update Zone Ruleset example linked to above.

Updates a zone ruleset, creating a new version.

If you keep that curl command handy, you can add/edit/delete individual rules in that ruleset.

1 Like

@sdayman, I’m at that point now and really struggling! I need to update the rules, but the docs are pretty vague on the process.

How do I get the Rule ID so that I can delete it or update it?

If you’re asking about the Rulesets I mentioned, then it’s a GET to this API:

https://api.cloudflare.com/client/v4/zones/{{zone_id}}/rulesets

I figured out how to get the ruleset ID, no problem. But you mentioned that I could add/edit/delete individual rules within that ruleset, and that’s where I’m choking :frowning: