How to use Node WPAPI with Wordpress.com (endpoint)?

480 Views Asked by At

I'm trying to figure out how to use Node WPAPI with a Wordpress.com-hosted blog.

const wp = new WPAPI({
  endpoint: 'https://MYSITE.wordpress.com/wp-json'
})
const posts = await wp.posts().get()
console.log(`posts:`, posts)

But I'm getting “Not Found” errors (if I set the Wordpress privacy to "Private" I get no error!).

I'm used to interacting with Wordpress REST API at https://public-api.wordpress.com/rest/v1.1/sites/MYSITE.wordpress.com/posts but the /wp-json route doesn't seem to be available.

What to do?

Update

Seems that the v2 API endpoint is https://public-api.wordpress.com/wp/v2/sites/MYSITE.wordpress.com but now I get this error:

{ code: 'rest_no_route',
  message: 'No route was found matching the URL and request method.' }
1

There are 1 best solutions below

0
Tom Söderlund On BEST ANSWER

I was close, the endpoint was:

https://public-api.wordpress.com/wp/v2/sites/MYSITE.wordpress.com/{resource}

e.g:

https://public-api.wordpress.com/wp/v2/sites/MYSITE.wordpress.com/posts