These are chat archives for WP-API/node-wpapi

12th
Dec 2018
Juan Alvarez
@jlalvarez18
Dec 12 2018 12:28
@Praful you are missing .get()
It should be wp.posts().get()
K Adam White
@kadamwhite
Dec 12 2018 15:54
Hello! I think unfortunately it's a bit more complicated than that; when we launched this project, wordpress.com did not yet support the REST API so all of our documentation is oriented towards self-hosted sites
If your blog is available through wordpress.com at myblog.wordpress.com, you can't access the API at myblog.wordpress.com/wp-json as you normally would
instead, @Praful try making requests against https://public-api.wordpress.com/wp/v2/sites/myblog.wordpress.com
That would be your endpoint, so a .posts() request would yield https://public-api.wordpress.com/wp/v2/sites/myblog.wordpress.com/posts
There's things that probably won't work because this library was written assuming the normal WordPress API structure, and the addition of the sites/myblog.wordpress.com string following the namespace on .com api endpoints somewhat breaks that assumption. Unfortunately this will likely be a frustration for you.
@computamike I'd say perhaps it's less "alive" than "on life support;" I do intend to revisit the project this winter, but in the meantime I thank you for your PRs. I have seen them and will merge as soon as I'm able to devote an afternoon to catching up.
Mees Rutten
@meesrutten
Dec 12 2018 20:40

Hey! I have a small question about an error i'm facing.

 { 
   code: 'rest_no_route',
   message: 'No route was found matching the URL and request method',
   data: { status: 404 } 
}

This happens when I do this in Node:

const WPAPI =     require( 'wpapi' ),
    ENV =         require( 'dotenv' ).config().parsed

const wp = new WPAPI( {
    endpoint: ENV.WP_API_ENDPOINT,
    username: ENV.WP_API_USERNAME,
    password: ENV.WP_API_PASSWORD,
    auth: true
} )

wp.pages().get().then( data => {
    // do something with the returned posts
    console.log( data )

} ).catch( err => {
    console.log( err )
} )
But the thing is, when I navigate to the endpoint i'm using https://website/index.php/wp-json/wp/v2/pages/6 I can see the JSON correctly