Support » Plugin: WP OAuth Server - CE » Rest cannot create error

  • Hello
    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.

    That means plugin doesn’t make user logged in because to create post user must be logged in and user should have capabilities for that.

    Please help me out for this problem as soon as possible.

    Thanks in advance.

Viewing 9 replies - 1 through 9 (of 9 total)
  • Plugin Author Dash10

    (@justingreerbbi)

    Forum Moderator

    Thanks for using WP OAuth Server and sorry for the issues. Common causes for this issue is:

    – Being logged into WordPress and attempting to use an access token.

    Solution:

    – Ensure you are logged out of WordPress before attempting to make calls using the access token.

    • This reply was modified 10 months, 1 week ago by  Dash10.

    Hi @brijesh2911 – you might also try hitting the /users/me endpoint. This will tell you if the API thinks you are logged in or not.

    Plugin Author Dash10

    (@justingreerbbi)

    Forum Moderator

    @brijesh2911,

    Were you able to get get your solution working? If so, please share 🙂

    Hello, @justingreerbbi
    Thanks for your response. I am trying to do that from another website. Should it work with that?

    Plugin Author Dash10

    (@justingreerbbi)

    Forum Moderator

    It would depend on how you are making the call from website to website. If you are making the call that is using the browser, then there is no need to include the access token. You would be considered logged in and it would use cookie auth.

    There is issues where even if you send a valid request to the REST API using browser based calls, then the two authentication methods (cookie and OAuth2) will clash and treat the call like an invalid users.

    Brijesh Borad

    (@brijesh2911)

    Thanks @justingreerbbi, But I was trying to call it using POSTMAN and also from my localhost to live site. How will it work?

    Plugin Author Dash10

    (@justingreerbbi)

    Forum Moderator

    Forgive me. I thought you were using a site to try and connect.

    Thanks for your response. I am trying to do that from another website. Should it work with that?

    You will only be able to use Authorization Code is you are using the version here on .org. POSTMAN will only work when using the access token and not to gain the access toke (again, with the version here on .org).

    Please share your workflow. Are you actually getting a valid access token? If so, what is the request you are using to call the REST API?

    hello,
    May be it’s too late to help, but i got the same issue. What i did was, to log out wordpress admin panel and try to send the basic Authentication Post request. surprise!!! this worked for me. I can’t explain why but it’s seem like the authentication process failed when you are already connected.

    Plugin Author Dash10

    (@justingreerbbi)

    Forum Moderator

    Hi,

    What you are experiencing is correct and not an oversight. WP REST can not choose which type of authentication to go with so it will fail. You can not be logged into WordPress via cookies and attempt to use any HTTP request with an access token. This is result is a failed authentication.

    You MUST use only one authentication method at a time. More than one, authentication will fail.

Viewing 9 replies - 1 through 9 (of 9 total)
  • You must be logged in to reply to this topic.