Where communities thrive


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

    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();

    Kada6
    @Kada6_gitlab
    hello
    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
    @ivanjeremic
    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 Benjamín Aguilar Aguilar
    @diegoaguilar
    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
    @thelucre
    is it possible to chain .embed() to a custom registered route?
    Lawrence Kimsey
    @lkimsey
    Has anyone completed Zach Gordon's WordPress REST Complete Beginners Guide ?
    Helder Oliveira
    @heldrida
    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.
    Air
    @yunair
    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 ?
    smartm0use
    @smartm0use
    hello, is it possible to get help here?
    I'm having problem with this: WP-API/node-wpapi#455
    smartm0use
    @smartm0use
    @kadamwhite
    Shahriar Shojib
    @shahriar-shojib
    when you use error to your advantage 😂😂😂😂
    await wp.categories().create({
    name: categoryName
    }).then(res => {
    categoryID = res.id; // sets categoryID to the newly created id
    }).catch(err => {
    categoryID = err.data.term_id // sets categoryID to existing ID 😂😂
    });
    Lachezar Stoyanov
    @lstoyanoff
    @kadamwhite Hey, I'm trying to use wp.media().file() in RN (if that even matters). I've tried passing both path and File with no success. When I pass path the WP REST API respond with rest_upload_no_data and if I pass a File Object I get the following message File is empty. Please upload something more substantial..... I've tried using a simple fetch request with FormData and it works fine. Am I doing something wrong or there is some kind of limitation when node-wpapi is used in RN? Thank you!
    Valentin P.
    @vpuls
    Hey there, I'm new to node-wpapi and like it but I can't find an answer to a supposedly easy question: Is it possible to reduce the WP API response to only needed fields with node-wpapi? The WP REST API Doc features the _fields query param (see https://developer.wordpress.org/rest-api/using-the-rest-api/global-parameters/#_fields), but in the node-wpapi doc I can't find related information. Any help appreciated, thanks in advance!
    Valentin P.
    @vpuls

    Hey there, I'm new to node-wpapi and like it but I can't find an answer to a supposedly easy question: Is it possible to reduce the WP API response to only needed fields with node-wpapi? The WP REST API Doc features the _fields query param (see https://developer.wordpress.org/rest-api/using-the-rest-api/global-parameters/#_fields), but in the node-wpapi doc I can't find related information. Any help appreciated, thanks in advance!

    I guess I found it out on my own by playing around and reading code on Github. For anyone asking him/herself the same question I did: You can use WPRequest.param() method as in this example:

    wpapi.pages().param('_fields', 'id,slug,title,parent').

    The wordpress API will return a JSON with all pages in it but for each page only the parameters id, slug, title and parent are listed. So far it tested it with WPReuqest objects returned by wpapi.root(), wpapi.pages().orderby().order() and wpapi.post() and it seems to work as I intended, reducing the JSON download size and thus the loading time.

    Negocios rentables
    @Negocios201X_twitter
    Hello, how can I create a post with a post type other than "post"?
    Luis Miguel Urbina Rodriguez
    @urbinadeveloper_twitter
    I was already able to create a post with a different post type, but the image is not attached.

    wp.productsAPI = wp.registerRoute("wp/v2", "/wp-manga/");
    wp.productsAPI().create({

    title: 'Your Post Title2',
    content: 'Your post content2',
    status: 'publish'

    }).then(function(post) {
    console.log("post", post, "post");

    return wp.media().file('prueba.png').create({
    title: 'Amazing featured image',
    post: post.id
    })

    }).then(function(media) {

                          // Set the new media record as the post's featured media
                          return wp().posts().id(post.id).update({
                            featured_media: media.id
                          });

    });

    Luis Miguel Urbina Rodriguez
    @urbinadeveloper_twitter
    Please.
    Mystiq
    @JakubSladek

    Hey, what to do? I never got that error before, can't fetch or update any posts, I changed nothing, yesterday worked normally and idk what to do.

    node_modules\superagent\lib\request-base.js:342 this._header[field.toLowerCase()] = val; ^ TypeError: Cannot set property 'authorization' of undefined
    Code:

    this.wp.series()
                    .param("status", "any")
                    .then(async (series) => {
                        let result = await getOnlyNeededInfo(series);
                        resolve(result);
                    })
                    .catch((err) => {
                        this.handleError(err);
                        resolve(false);
                    });
    Alessandro Manias
    @alessandro.manias.gag_gitlab
    Good morning, is possible to use wpapi to make call to jwt.auth plugin route and generate the jwt token?
    Andrew L Webber
    @kadadji:matrix.org
    [m]
    hello, anybode here?
    Tae-yoon Yeo
    @taeyooniSK
    Hi!
    Sławek Amielucha
    @amielucha
    Hi, I have a question about WPAPI configuration object. Is it possible to set a default amount of pages for each requests rather than using .perPage()for each request?
    K Adam White
    @kadamwhite
    @amielucha I don't believe we support that, because the default configuration is shared among both GET and POST requests where GET-specific query parameters would not make sense. What I've done in the past if I have a common set of arguments is to make helper functions, e.g.
    const posts = () => wp.posts().perPage( 100 );
    Abhinav Das
    @theabhinavdas
    @kadamwhite is it possible to do bulk post creation via this library? i'm having some odd timeouts while using async/await and Promise.all([..])..
    K Adam White
    @kadamwhite
    @theabhinavdas you might be maxing out the number of parallel requests your WP install can handle. I’ve written code in the past to send two (or five, etc, depending on server capability) requests at a time, with some basic retry logic if the request fails, and have gotten through hundreds of posts that way
    No code to share I’m afraid, it was in a client’s repo, but if you are doing something like that and still seeing errors, please share them here and we can take a look
    Zhon
    @ListlessH_twitter
    Hey @kadamwhite do you still monitor this? I'm trying to use WPAPI to update Advanced Custom Fields and having absolutely no luck.
    const WPAPI = require ('wpapi');
    
    
    var wpdev = new WPAPI ({
        endpoint: '..../wp-json',
        username: '...',
        password: '...'
    });
    
    wpdev.acfAPI = wpdev.registerRoute("acf/v3", "/posts/(?P<id>[\\d]+)/?(?P<field>[\\w\\-\\_]+)?", {
        params: [ 'main_sidebar' ]
    });
    
    main();
    
    async function main () {
        let resp = await wpdev.acfAPI().id(62542).field("main_sidebar").get();
        console.log(resp);
        console.log(JSON.stringify(resp));
    }
    This properly retrieves the value of "main_sidebar" (which is null, because it doesnt' exist for that post yet)
    I need to set the value of "main_sidebar" to something else. I've searched and tried various things for hours and can't figure it out. I'd greatly appreciate any help
    K Adam White
    @kadamwhite
    Hey there @ListlessH_twitter
    If you are wanting to update main sidebar, you would need to use a post — not a get. What value does it have to start, and what are you hoping to update it to?
    (You said it was null to start so ignore that part of the question)
    Zhon
    @ListlessH_twitter
    @kadamwhite I appreciate the response, I have a string "sidebarcontents" that I'm pulling from another version of the site. It just contains some links and lists in html. I'm familiar with using get/post in fetch requests, but I'm not sure how to do that here. I tried using post() instead of get() but get an error (post is not a function).
    K Adam White
    @kadamwhite
    What about “update” instead of “post”? http://wp-api.org/node-wpapi/using-the-client/#updating-posts
    Zhon
    @ListlessH_twitter
    {"code":"rest_forbidden","message":"Sorry, you are not allowed to do that.","data":{"status":401}}

    If I updated the actual post instead, like this:

    await wpdev.posts().id(62542).update({
            // updates
        })

    It seems there's a way to reach the ACF field? i.e.

    // updates
    data: { "acf": { "main_sidebar": "contents here" } }
    K Adam White
    @kadamwhite
    Oh yeah you can update acf data by sending content to the normal posts endpoint. This may be helpful: http://wp-api.org/node-wpapi/using-the-client/#updating-posts
    See the POST request section (which you’d send with update() using this library)
    Zhon
    @ListlessH_twitter

    That seems to be better... At least it doesn't throw an error. But nothing happens when I run this code:

        let result = await wpdev.posts().id(117925).auth().update({
            data: {
                "acf": {
                     "main_sidebar": "test"
                }
            },
            status: 'publish'
        });
        console.log(result);

    The sidebar doesn't update. Is the structure of my request wrong?

    Zhon
    @ListlessH_twitter
    Argh I figured it out. Thank you so much for responding so quickly.

    It was really simple in the end, but that's how it always is, isn't it? lol
    Working code for anyone else looking for the same solution:

        let result = await wpdev.posts().id(117925).auth().update({
            "fields": {
                "main_sidebar": "test"
            },
            status: 'publish'
        });
        console.log(result);

    Should be able to replace "main_sidebar" with any custom field set by acf

    K Adam White
    @kadamwhite
    Glad you got it working!
    Ünsal Korkmaz
    @unsalkorkmaz_twitter

    Hello,
    Is this project maintained atm?

    npm install --save wpapi

    command doesnt even install all necessary files & folders, for example wpapi/superagent folder. If yes, how about WooCommerce Rest API support?