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?
Thanks to JSON formatting, WordPress REST API allows WordPress to exchange data with other websites and software written in any programming language. Hence, developers are not constrained to PHP anymore, and they can use WordPress to handle the data via REST API.
The best way to check is to visit this URL: https://yoursite.com/wp-json. If you see some information which seems related to your WordPress REST API, it works. If you see something, it means that, at least, your WordPress REST API is enabled. Otherwise, that's not working, and you will need to understand why.
This API is very useful, but it isn't without its risks. If you use this API without safety checks in place, you could leave your data vulnerable to leaks, security breaches, and other hacking attacks. For example, using HTTP in your REST API puts you at risk of information leaks because of the lack of encryption.
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).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With