简体   繁体   中英

Getting a value from 3rd party website API

So I'm desperately trying to pull a value from a 3rd party website API. The information is formatted in the following way:

Website's API response

I'd like to pull out a value for "price". So far I've tried many different codes but all have failed. I've also spent a lot of time searching for a solution but without succes. At the moment my code for obtaining the value looks like this, but it's obviously not complete and incorrect as I'm new to NodeJs:

var Request = require("request");
Request.get("url", (error, response, body) => {
    if(error) {
        return console.dir(error);
    }
    console.dir(JSON.parse(body));
});

And yes the url is actually inserted in my code + I know that this should only display the full JSON structure, but it fails to do even that :/

Any kind of advice would be welcome :)

EDIT: So I've fixed that issue with not getting data :) However I still need to filter my data in order to pull out the "price" value. As of now my data displays this: "data: { items_on_sale: [ [Object] ], items_not_on_sale: [] } }"

status: 'fail' : The api is not replying with the data.Does the url require any query params/body to be passed with the url?

Try hitting the api using postman/SoapUI and check the response there.

also try printing the response in the log,what values do you get?

console.log('statusCode:', response && response.statusCode); 

There was a problem with 2FA code. It wasn't generating properly. It is now fixed.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM