I'm using the wordpress.com API to access a blog's content:


It works great, I can access all the text content I need, however, I cannot access the /media endpoint to get the featured_image associated with each page. The media endpoint gives me a 401 error.

I can access that endpoint using the developers console: https://developer.wordpress.com/docs/api/console/

Because I'm signed in as the owner of the site.

My question is, how do I properly retrieve the featured images? It seems crazy that I'd need to authenticate to gain access to the URL for each image which is publicly available anyways...

If it is the case that I need to auth, how do you do that with wordpress.com? I don't know much about authentication, so even just pointers in the right direction would be great! Thanks.

  • what does it have to do with wordpress the software? – Mark Kaplun Dec 30 '16 at 5:44
  • The question is 'how do I retrieve images from the wordpress.com API?' which is related to wordpress... – Joel Dec 30 '16 at 16:55
  • Of course, if the answer is, 'you must authenticate', then that's an answer that helps me out...and I can continue my search in that direction... – Joel Dec 30 '16 at 16:57
  • Ok. I seem to have found my answer, in the Caveats section of the page here: developer.wordpress.com/2016/11/11/… – Joel Dec 30 '16 at 17:11
  • "In addition, a few endpoints are restricted or disabled on WordPress.com, generally for parity with our v1 API. A few examples: - Listing and retrieving media items requires authentication..." – Joel Dec 30 '16 at 17:11

Simple: Add ?_embed to the url query string.

Eg: /wp-json/wp/v2/posts?_embed=true (_embed will work too )

You will then find a property within each post in the JSON called _embedded which will contain all the info you need for Featured Image. Also your taxonomies/categories/tags etc.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.