Cloudflare Page Rules API: Difference Between PUT (Update) and PATCH (Edit)

I seem to be able to do the exact same things when updating a page rule using either the PUT or PATCH option. Documentation a bit light on this.

They in fact seem totally interchangeable - am I missing something ?

https://api.cloudflare.com/#page-rules-for-a-zone-update-page-rule
https://api.cloudflare.com/#page-rules-for-a-zone-edit-page-rule

PUT requires the entire configuration/parameter object, whereas with PATCH a subset is acceptable as well. Pay attention to the required and optional fields.

Fairly standard under the REST concept.

thanks

Hi - thanks for the info. I do see the required and optional parameters in the documentation. But given that then the following should not work but it does seem to

Supplying only the priority using PUT should not be permitted as per the documentation - correct ? As targets and actions are supposed to be required …

curl -X PUT “https://api.cloudflare.com/client/v4/zones/0/pagerules/0
-H “Authorization: Bearer 0”
-H “Content-Type: application/json”
–data ‘{“priority”:1}’

{“result”:{“id”:“0”,“targets”:[{“target”:“url”,“constraint”:{“operator”:“matches”,“value”:"*whatever"}}],“actions”:[{“id”:“minify”,“value”:{“html”:“off”,“css”:“on”,“js”:“off”}}],“priority”:1,“status”:“disabled”,“created_on”:“2021-09-10T15:52:35.000000Z”,“modified_on”:“2021-09-14T15:56:18.000000Z”},“success”:true,“errors”:,”messages”:}

That is correct and would be most likely a bug in the interface as the documentation is pretty straightforward on this and follows traditional REST concepts. The validation in the PUT call might not be complete.

Do you experience any issues?

I can confirm the behaviour of PUT. I wouldn’t be surprised if PUT was just an alias for PATCH, though it neither should be according to the documentation nor by REST. Most likely a convenient shortcut, but shouldn’t influence the use.

If you wanted to report that it would be best to open a thread at #feedback.

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.