1

I'm trying to make a Postman call to the Wordpress API to delete a block. However, I keep getting a 403. This user is used to add and delete pages, tags, and posts just fine using the Application Passwords Plugin for authentication. The user is an Administrator.

I have no idea why I don't have permissions. I can delete in the UI.

I suspect I am not adding a needed parameter to the creation call such as context or a template. But I don't know what values those should be. I hope someone here as experience with using Blocks in the REST API.

ERROR:

{
    "code": "rest_cannot_delete",
    "message": "Sorry, you are not allowed to delete this post.",
    "data": {
        "status": 403
    }
}

I'm deleting these blocks using the API with a call like this:

curl -X DELETE \
  'http://<IP_ADDRESS>/<SUBSUTE>/wp-json/wp/v2/blocks/59?force=1' \
  -H 'Accept: */*' \
  -H 'Accept-Encoding: gzip, deflate' \
  -H 'Authorization: Basic <Token>' \
  -H 'Cache-Control: no-cache' \
  -H 'Connection: keep-alive' \
  -H 'Content-Length: ' \
  -H 'Host: <IP>' \
  -H 'Postman-Token: <TOKEN>' \
  -H 'User-Agent: PostmanRuntime/7.15.2' \
  -H 'cache-control: no-cache'

I'm creating these blocks using the API with a call like this:

curl -X POST \
  'http://<SITE>/<SUBSITE>/wp-json/wp/v2/blocks?title=BLOCKS%20TITLE&content=BLOCKS%20CONTENT' \
  -H 'Accept: */*' \
  -H 'Accept-Encoding: gzip, deflate' \
  -H 'Authorization: Basic <TOKEN>' \
  -H 'Cache-Control: no-cache' \
  -H 'Connection: keep-alive' \
  -H 'Content-Length: ' \
  -H 'Host: <IP>' \
  -H 'Postman-Token: <TOKEN>' \
  -H 'User-Agent: PostmanRuntime/7.15.2' \
  -H 'cache-control: no-cache'
6
  • You mentioned you're using the Application Passwords plugin for authentication; did you include --user "USERNAME:PASSWORD" in the cURL request?
    – Sally CJ
    Jul 26, 2019 at 10:21
  • 1
    yes, I have the Authorization: Basic <Token> header. It's worked for everything else. <Token> is the username:password in Base64 encoded already. Jul 26, 2019 at 16:28
  • 1
    Actually, the problem is not the plugin (as I mentioned earlier). But I think you (or that user) doesn't have the delete_blocks permission? Try $user = get_userdata( 'USER ID' ); $user->add_cap( 'delete_blocks' ); and run the REST API request for deleting the block.
    – Sally CJ
    Jul 27, 2019 at 4:32
  • Ahhh do I do that in the wp_config.php? I'm not trying to mess with any custom Rest API points. I'm actually building documentation on what's already there for anyone who wants to use the default Rest API. Just clearing up that none of this is for any Wordpress development. I'll try adding that and let you all know Jul 27, 2019 at 17:47
  • 1
    Awesome, I think I'll just include this in my documentation as I'm trying to just document as much of the barebones Wordpress API without plugins as possible. Thank you :) Jul 29, 2019 at 18:59

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.