Remove page restrictions via REST-API

Hi,
I’m trying to remove page read restrictions with the below REST call.

function removePageRestriction() {

	const bodyData = `[
  {
    "content": {
      "expanded": true,
      "idProperties": {}
    },
    "operation": "read",
    "restrictions": {
 		"user": {},
		"group": {}
	}
   }
]`;

fetch('https://MYIP/rest/api/content/2367857478/restriction', {
  method: 'PUT',
  headers: {
    'Accept': 'application/json',
    'Content-Type': 'application/json'
  },
  body: bodyData
})
  .then(response => {
    alert(
      `Response: ${response.status} ${response.statusText}`
    );
    return response.text();
  })
  .then(text => alert(text))
  .catch(err => alert(err));
}

But upon execution, I receive an error 405.
Note: the code is taken from The Confluence Data Center REST API

I have no issues reading the restrictions of that page by using The Confluence Data Center REST API

Has anyone successfully removed page restrictions from confluence pages via REST API?

Regards,
Dirk

Hi @DirkEyfrig,
PUT /rest/api/content/{pageId}/restriction is only available in Confluence 8.8 and newer.

If you are using an older Version of Confluence you can use the experimental version PUT /rest/experimental/content/{pageId}/restriction instead. This one uses the same body format and has been around since Confluence 6. It is also still available in Confluence 9, in case you want to support multiple Confluence versions.

Hi @t-bundt ,
we’re on 8.5.17, but with /experimental/ instead of /rest/, I receive error 500 instead of 405. :roll_eyes:

I’m giving up for today…

Is there any “official” method to REMOVE ALL page restrictions by using a Confiforms IFTTT action?
I know how to add restrictions for known users and how to remove them again, but how to remove all?

Hi @DirkEyfrig,
the body should look like this (with two empty results lists):

[
 {
  "operation": "read",
  "restrictions": {
    "user": {
      "results": []
    },
    "group": {
      "results": []
    }
  }
 }
]
1 Like

Hi @t-bundt,
unfortunately, this doesn’t help either.
I’ve also tried

[
 {
  "operation": "read",
  "restrictions": {
    "user": [],
    "group": []
    }
  }
]

but that doesn’t work either.

I’m giving up on this, possibly it’s an effect of our specific instance…

Hello @DirkEyfrig

If you refer to the Content Restriction section of the Confluence Server v8.5.17 REST API documentation, you’ll see that version of the product never had an Update Restrictions (PUT) endpoint, hence the 405 error.

As @t-bundt has advised, the ability to update (PUT) content restrictions via the REST API was introduced in v8.8.0 as per that version’s release notes and per CONFSERVER-57907.

If you do either a PUT or a POST to /rest/experimental/content/{pageId}/restriction with no request body at all, you should get back either a 403 or 415 error. If you get a 500 error, then there isn’t a functioning endpoint at that path that supports either method.

Hi @sunnyape ,
thanks for the explanation - so I’ll have to wait until we update to at least 8.8.0. :roll_eyes:

1 Like

@DirkEyfrig
Sorry, the correct body format should be:

{
  "results": [
    {
      "operation": "read",
      "restrictions": {
        "user": {
          "results": []
        },
        "group": {
          "results": []
        }
      }
    }
  ]
}

This time I’ve tested it using the REST API Browser on a Confluence 8.5.0
And if you also want to remove edit restrictions:

{
  "results": [
    {
      "operation": "read",
      "restrictions": {
        "user": {
          "results": []
        },
        "group": {
          "results": []
        }
      }
    },
    {
      "operation": "update",
      "restrictions": {
        "user": {
          "results": []
        },
        "group": {
          "results": []
        }
      }
    }
  ]
}

Hello @t-bundt

In those two request body examples above, do they apply to the experimental API endpoint you described earlier?

@sunnyape yes
and also to the official Server/DC API and the Confluence Cloud API

Thanks. I wonder why the OP’s getting 500 errors when trying to access those endpoints.

I’ll leave that with you to liaise with them on, if required.

Hi @t-bundt,
this finally works!
Thanks a lot for your support.

1 Like