Where communities thrive

  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
Repo info
    Mike Hingley
    So - once I’ve set up the wordpress test environment, do i need to seed it with content? Because it’s all empty. Am I missing a step somewhere?
    Mike Hingley
    in other news - i’ve found out why my server was running so slowly - which is good - it just means that my integration tests now fail faster due to missing data.
    Mike Hingley
    I’ve pushed a couple of pull requests (updating docs, and fixing integration tests). Is this still alive?
    Voon Ming Hann
    Need help on creating a post, been stuck for quite some time

    Hello, I've just created a free site at wordpress.com. I created a js script to read posts using the node-wpapi and ran the script using node script.js. It has no UI component. This is the code I'm using, copied from the Github docs for the node-wpapi:

    var WPAPI = require('wpapi');
    var wp = new WPAPI({
      endpoint: 'http://myblog.home.blog/wp-json',
      username: 'myusername',
      password: 'mypassword'
    function readPosts() {
      // Promises
      wp.posts().then(function (data) {
        // do something with the returned posts
      }).catch(function (err) {

    However, I get an error with output that starts with:

    { Error: Not Found
        at Request.callback (C:\data\dev\projects\facebook-to-wordpress\node_modules\superagent\lib\node\index.js:706:15)
        at Stream.parser (C:\data\dev\projects\facebook-to-wordpress\node_modules\superagent\lib\node\index.js:916:18)
        at Stream.emit (events.js:182:13)
        at Unzip.unzip.on (C:\data\dev\projects\facebook-to-wordpress\node_modules\superagent\lib\node\unzip.js:55:12)
        at Unzip.emit (events.js:187:15)
        at endReadableNT (_stream_readable.js:1085:12)
        at process._tickCallback (internal/process/next_tick.js:63:19)
      status: 404,
       Response {

    I used the console app, https://developer.wordpress.com/docs/api/console/ (using options WP REST API, wp/v2) and that does return posts.

    Please can someone help me understand what I'm doing wrong.

    Ultimately, I want to write a script that reads my Facebook downloaded data (json format) and creates posts on Wordpress. I couldn't find anything that does this.


    Juan Alvarez
    @Praful you are missing .get()
    It should be wp.posts().get()
    K Adam White
    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

    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
    K Adam White
    @meesrutten What is the value of ENV.WP_API_ENDPOINT?
    Mees Rutten
    When I navigate there it shows me the JSON, so the link isn't broken
    K Adam White
    @meesrutten the endpoint should only be the piece ending in wp-json; if you console.log(
    console.log( wp.pages().toString() )`
    Mees Rutten
    I'll try!
    K Adam White
    I suspect you may see that you’re getting a URL like https://website/index.php/wp-json/wp/v2/pages/6/wp/v2/pages. You should set the endpoint to only https://website/index.php/wp-json
    Forgive the poor formatting, trying to use gitter via mobile web ;)
    Mees Rutten
    ah it seems to work
    Do you know how I can get a certain page by ID?
    wp.pages().id(6).then(...) seems to do the trick
    Mees Rutten
    @kadamwhite it works now! Thank you so much :)
    BTW, love the node-wpapi! My clients still get WordPress and I don't get the headache of WordPress :)
    @jlalvarez18 thanks for replying.
    @kadamwhite I've switched to developing in a local Docker WordPress install now! However, for others, I used endpoint https://praful.home.blog/?rest_route=/' since my test site on WordPress.com is praful.home.blog. I also used http://prafulhome.wordpress.com/wp-json.

    @kadamwhite On another note, I want to add an image to a post. I copied the example you provide in which you create a media object then update the post attribute. This has no effect on the post.

    How do I create a post with text followed by one or more photos at the bottom? Also how do I create a gallery post?!


    Juan Adolfo
    can someone make me a demo?
    im new with wordpress rest api and im trying to use the wpapi client but cant make it work :s
    Hi! I would like to know how call POST method on a

    Hi! I would like to know how call POST method on a registerRoute.

    I'm trying to use JWT Authentication for WP-API and I want to get the token

    wp.token = wp.registerRoute('jwt-auth/v1', '/token');

    const token = await wp.token();

    i have trouble with posting through api {
    code: 'rest_cannot_create',
    message: 'Sorry, you are not allowed to create posts as this user.',
    data: { status: 401 }
    Iv tried several accounts, no results. basic auth plugin is installed and activated
    Ivan Jeremic
    I try to get the user-role of current authenticated user can anyone give me a hint I can't find out where it is I tried without seccess.
    Diego Aguilar Aguilar
    Hello, I want to fetch a landing_page Post Type
    I can find the Custom PostType via wp.types().type( 'landing_page' ).embed()
    but not sure how I should fetch all of this tyope
    Eric Howard
    is it possible to chain .embed() to a custom registered route?
    Lawrence Kimsey
    Has anyone completed Zach Gordon's WordPress REST Complete Beginners Guide ?
    Helder Oliveira
    When creating an image, the document example works but only generates a single featuredImage and I need to have different sizes, like thumb, small, large etc. If I use the wordpress UI and set a featured image this happens automatically. But no sure how to do it programmatically.
    Hello, I want to create a post with js code, If i put my code in content, I can't edit it in user publish page anymore. What's the right way to do ?
    hello, is it possible to get help here?
    I'm having problem with this: WP-API/node-wpapi#455