Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
    kkuhler
    @kkuhler

    Hi. I am getting this error:

    Autodiscovery failed
    [SyntaxError: Invalid regular expression: /(?P<id>[^\/: Invalid group]
    Endpoint detected, proceeding despite error...
    Binding to https://waybright.com/wp-json/ and assuming default routes

    The error occurs when I do WP.discover( 'https://waybright.com/' );

    Thanks

    Szymon Nowak
    @szimek
    Hi! I'm exporting data from WP and I'd like to export featured image for each post as well. currently I'm fetching posts in batches of 100. is there a way to automatically fetch data from { "_links": { "wp:featuredmedia": [...] }} as well? or do I have to do a separate request for each post to get it?
    sunpietro
    @sunpietro
    You can always try to create a custom endpoint that returns a desired piece of information.
    Dignity1988
    @Dignity1988
    Hello i i am tryiing to make it from gunt tasks function but cannot even test the responss. I only get Promises as answer
    Running "post" task
    Promise { '': 4, _state: undefined, _result: undefined, _subscribers: [] }

    grunt.task.registerTask('post', function (){

    var WPAPI = require( 'wpapi' );
    var wp = new WPAPI({
    endpoint: 'http://new.whiteraven.org.ua/wp-json',
    // This assumes you are using basic auth, as described further below
    username: 'maksym',
    password: '1234567890',
    auth: true

    });

    var _p = wp.posts().create({
    title:'test',
    content:'test content'
    })
    .then(function(response){
    console.log("complete");
    console.log(response);
    })
    .catch(function(err){
    // handle error
    console.log("ERROR:");
    console.log(err.response.text);
    });

    console.log(_p);

    });

    the answer is present from the real site and route is fine. Do i need to specify the route?
    Jodde
    @samdoj
    Hey, so I'm having trouble using this with react native.
    I can't build it because of incorrect dependencies, and I can't find the correct dependencies.
    Dignity1988
    @Dignity1988
    finally solved it.
    Mike Hingley
    @computamike
    Hi - i've just downloaded the wpapi code, and tried running the integration tests. I've noticed that the integration tests are timing out (2 second time out). I'm running a chassis WPAPI server - as per the instructions, and I'm struggling to figure out why that would time out. I'm guessing it's something to do with my configuration (macbook with ssd) but I can't figure out what it could be. Maybe IP Resolution? Anyone else experienced similar issues?
    Mike Hingley
    @computamike
    Here’s a single test with a timeout set to 0 that takes quite a long time to run :
    Mike Hingley
    @computamike
    best way to go is to add timeout 0 to the npm call - this removes timeouts.
    Mike Hingley
    @computamike
    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
    @computamike
    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
    @computamike
    I’ve pushed a couple of pull requests (updating docs, and fixing integration tests). Is this still alive?
    ajv
    @andreasvirkus
    @kadamwhite
    Voon Ming Hann
    @eldyvoon
    Need help on creating a post, been stuck for quite some time
    Praful
    @Praful

    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
        console.log(data)
      }).catch(function (err) {
        console.log(err)
      });
    }
    
    readPosts()

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

    Thanks
    Praful

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

    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
    @kadamwhite
    @meesrutten What is the value of ENV.WP_API_ENDPOINT?
    Mees Rutten
    @meesrutten
    When I navigate there it shows me the JSON, so the link isn't broken
    K Adam White
    @kadamwhite
    @meesrutten the endpoint should only be the piece ending in wp-json; if you console.log(
    console.log( wp.pages().toString() )`
    Mees Rutten
    @meesrutten
    I'll try!
    K Adam White
    @kadamwhite
    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
    @meesrutten
    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
    @meesrutten
    @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 :)
    Praful
    @Praful
    @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.
    Praful
    @Praful

    @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?!

    Thanks!

    Juan Adolfo
    @2Jacz
    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
    gonzalobarria
    @gonzalobarria
    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();