• I understand why for the public you would not want to show posts that are in draft mode, but I have a special circumstance where I need to show posts that are in draft to the public, a user not logged in.

    If I put this post (20512) in draft I get this error when trying the GET the page.
    https://localhost:2029/wp-json/wp/v2/pages/20512?status=publish,draft

    {
    code: “rest_forbidden”,
    message: “Sorry, you are not allowed to do that.”,
    data: {
    status: 401
    }
    }

    Is there a workaround, plugin or method I can use to get drafts with the API?

    thanks,

    Paul

    • This topic was modified 4 years, 7 months ago by James Huff. Reason: moved to Localhost Installs since this is a localhost install
Viewing 1 replies (of 1 total)
  • For developers making manual Ajax requests, the nonce will need to be passed with each request. The API uses nonces with the action set to wp_rest. These can then be passed to the API via the _wpnonce data parameter (either POST data or in the query for GET requests), or via the X-WP-Nonce header. If no nonce is provided the API will set the current user to 0, turning the request into an unauthenticated request, even if you’re logged into WordPress.

    https://developer.www.ads-software.com/rest-api/using-the-rest-api/authentication/

Viewing 1 replies (of 1 total)
  • The topic ‘WP-API get posts with status=draft returns 401’ is closed to new replies.