Using Wordpress.com API to retrieve featured images

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

https://public-api.wordpress.com/wp/v2/sites/MYSITENUMBER/pages

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.

Topic endpoints rest-api wordpress.com-hosting media Wordpress

Category Web


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.

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.