question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How can I retrieve a draft post?

See original GitHub issue
const wp = new WP({
        endpoint: endpoint,
        username: username,
        password: password
});

wp.posts().filter({status: 'any'}).embed().id(id).then(function(data) {
    console.log(data)
})

When I try to retrieve an post that is set to draft, I’m unable to retrieve the post. When I log the error, i got a 403 permission error.

error: 
      { [Error: cannot GET /wp-json/wp/v2/posts/631?_embed=true (403)]
        status: 403,
        text: '{"code":"rest_forbidden","message":"You don\'t have permission to do this.","data":{"status":403}}',
        method: 'GET',
        path: '/wp-json/wp/v2/posts/631?_embed=true' },

The user credential i sent to WP is a user with Admin privilege.

Thank you so much for your help!

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:12

github_iconTop GitHub Comments

2reactions
yongzhihuangcommented, Mar 18, 2016

Figured it out. I have to chain

.param({
        status: 'draft'
})

to the request!

1reaction
motleydevcommented, Jun 30, 2017

Hi @kadamwhite, I am using this exact function chain wp.posts().auth().param( 'context', 'edit' ).param( 'status', 'draft' ) to fetch drafts and I keep getting this error message:

{ code: 'rest_invalid_param',
  message: 'Invalid parameter(s): status',
  data: { status: 400, params: { status: 'Status is forbidden.' } } }

My auth works because I can create posts just fine AND I can see the drafts (that my user created), just fetching drafts is the issue.

Read more comments on GitHub >

github_iconTop Results From Across the Web

I saved a draft post on my personal Facebook profile. Where is ...
To find this draft again, just create a post again by tapping on the “What's on your mind?” on your mobile device, and...
Read more >
How to Find Facebook Drafts - Alphr
1. Sign in to your Facebook account. 2. Click on Pages in the navigation menu on the left side of your screen. This...
Read more >
How To Find Drafts on Facebook App - Nerds Chalk
Inside the Posts & stories page, click on the Drafts tab at the top. You'll now see all the drafts you've saved on...
Read more >
How to Find Drafts on Facebook? - Remote Tools
Scroll down to find the 'Posts & Stories' icon at the bottom and click on it. In the dropdown menu, select 'Drafts'. The...
Read more >
Easy Ways to Find Saved Drafts on Facebook: 9 Steps - wikiHow
1. Go to https://facebook.com and log into your account. You'll need to use the desktop version of the site to find the link...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found