Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 882
Alex Kojin Avatar asked Feb 02 '18 19:02

Alex Kojin


People also ask

Can I use REST API with WordPress?

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.

How do I know if my WordPress REST API is working?

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.

Is WordPress REST API secure?

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.


1 Answers

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).

like image 53
Jared Cobb Avatar answered Oct 23 '22 22:10

Jared Cobb