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

18th
Oct 2017
Linas
@juslintek
Oct 18 2017 09:17

Hi, having problem with getting custom endpoint value using this code below:

const wpPromise = WP.discover( 'https://hosting.review/' );

wpPromise.then(function( site ) {
    // If default routes were detected, they are now available
    site.posts().then(function( posts ) {
        console.log( posts );
    }); // etc


    // Namespaces can be saved out to variables:
    var whoisData = site.namespace( 'hosting-review/v1' );
    whoisData.whois()
        .domain( 'alvinalexander.com' )
        .then(response => {
            console.log(response);
        });
});

Response in console.log I get.

Failed to load https://hosting.review/: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'chrome-extension://manpbofjhcdbchabfjffabpfnjgcjmoc' is therefore not allowed access.
Autodiscovery failed
Error: Request has been terminated

I'm trying to do this in an chrome-extension

One of the problems is mode, problem, because I was trying to fetch using fetch. If I change more to no-cors. Then I get empty response, but in development tools network I can see response json.
But I cannot put it into the code.
Linas
@juslintek
Oct 18 2017 11:12
solved, added CORS header *
on API
Fabian Perich Lara
@fperich
Oct 18 2017 19:35

Hi, i need some help. I'm trying to use filter plugin (https://github.com/wp-api/rest-filter) but the node-api does not work. I'm using this code.

var WPAPI = require( 'wpapi' );

WPAPI.discover( 'https://www.verygood.travel/blog' )
    .then(function( wp ) {
        // Query by the slug of a category or tag
        // Get all posts in category "islands" and tags "clouds" & "sunset"
        // (filter can either accept two parameters, as above where it's called with
        // a key and a value, or an object of parameter keys and values, as below)
        wp.posts().filter({
            category_name: 'guide',
            tag: [ 'ecuador' ]
        }).then(function(posts){
            console.log(posts)
        })        
    });

the filter() function appears to do nothing or maybe in a loop. If i remove the filter function, works well.

if you go to this request
you will se filter plugin it is working well.

Could you help me please.
Thanks