Updating Page Rules with API

Hello,

I am using the code below to attempt to turn specific page rules on and off, however, although the API request returns success, the status of the page rule never changes. I have tried updating (PUT) and editing (PATCH), however, both return the same outcome. I have also tried only including status in the data for the cURL request.

My PHP code:

 $data1 = [
        'targets' => [
          'target' => 'url',
          'constraint' => [
            'operator' => 'matches',
            'value' => 'domain.com/*'
          ]
        ],
        'actions' => [
          'id' => 'forwarding_url',
          'value' => [
            'url' => 'http://www.subdomain.domain2.com/$1',
            'status_code' => '302'
          ]
        ],
        "priority" => 2,
        "status" => "active"
      ];```

How can I fix this, or what am I doing wrong?

Thanks!

I’ve tried only sending the status field and using PATCH, however, the page rule stays disabled, even though the request comes back as successful.

This is the data I’m sending:

  $data1 = [
    "status" => "active"
  ];

Turns out I was using http_build_query in PHP, which is what was causing the issue.

I just want to make clear the PATCH method suggested here does indeed work like a charm. I didn’t really want to re-supply all the page rule’s parameters just to change the active/disabled status, and this works well.