Can I use the REST API for a site hosted on WordPress.com [closed]
Asked Answered
A

1

15

I have a blog hosted on WordPress.com. When I try to make a GET request to retrieve the posts I get a 'Not Found' html page.

https://alexkojin.wordpress.com/wp-json/wp/v2/posts

I know about the legacy public API but it doesn't allow me to retrieve private posts.

Can I use the REST API for site hosted on WordPress.com?

Antonantone answered 2/2, 2018 at 19:52 Comment(2)
This question should be directed to the WordPress site maintainers.Barrel
Edited the question to help clarify the problem and solutionMixon
M
34

On the WordPress.com platform the REST API is actually hosted and structured at https://public-api.wordpress.com/wp/v2 for all sites. In addition, there's a /sites/ endpoint that will namespace your specific site.

For example, the root endpoint for your site would be https://public-api.wordpress.com/wp/v2/sites/alexkojin.wordpress.com/. The other endpoints behave the same way as they would on a self hosted platform.

For example, your pages would be found under https://public-api.wordpress.com/wp/v2/sites/alexkojin.wordpress.com/pages

You can find more information at https://developer.wordpress.com/2016/11/11/wordpress-rest-api-on-wordpress-com/ including how to setup OAuth2 (which will be required to access private posts).

Mixon answered 2/2, 2018 at 21:16 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.