• Hello,
    I am using wordpress 4.7.1 and i want to use wordpress rest api that came with latest version.
    WP Rest API is working fine with GET request but not POST request. I am not able create any post with the POST request.
    I am getting these response for every time i tried.

    {
      "code": "rest_cannot_create",
      "message": "Sorry, you are not allowed to create posts as this user.",
      "data": {
        "status": 401
      }
    }

    Please help to solve this asap

Viewing 4 replies - 1 through 4 (of 4 total)
  • Hello, and thanks for trying the rest API! You’ll need to authenticate your post request, so that WordPress knows the POST came from an authorized user. Check out this documentation: https://developer.www.ads-software.com/rest-api/authentication/ and here’s another article walking through how you can embed nonces in an arbitrary JS script loaded by WordPress: https://wp-api.org/node-wpapi/guides/2016/08/12/authenticating-with-cookies.html

    Hope this helps

    Edit: updated the first link, sorry for the bad mobile copy-paste!

    • This reply was modified 7 years, 10 months ago by K. Adam White. Reason: pasted wrong link
    Thread Starter Brijesh Borad

    (@brijesh2911)

    Thanks @kadamwhite for the response.
    I want to create post from another website and i have tried basic authentication as well as integrate oauth1 and oauth2 authentication but none of these is working.

    Have you any idea why it is not working?

    @brijesh2911 Unfortunately without knowing anything about your site or the application from which you’re making the connection, it’s very hard to say. What language/environment are you sending the requests from? Can you provide more information?

    Thread Starter Brijesh Borad

    (@brijesh2911)

    @kadamwhite Yes, sure.
    I am using wordpress’ default wp rest api feature and WP OAuth Server plugin.I am getting access token when i tried to call endpoint to create post with POST request but still i am getting this response

    {
      "code": "rest_cannot_create",
      "message": "Sorry, you are not allowed to create posts as this user.",
      "data": {
        "status": 401
      }
    }

    Access token is valid though i am not able to create post with json endpoint. I don’t know what is the issue. I have checked database,too and found that the access token is valid for the user who is administrator of site.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘WP rest api post requestq’ is closed to new replies.