I'm just trying to do a quick test using Axios to run a GET request from eBay API.
Here's my code:
var express = require("express");
var router = express.Router();
const axios = require("axios");
var url = "http://svcs.ebay.com/services/search/FindingService/v1";
url += "?OPERATION-NAME=findItemsAdvanced";
url += "&SERVICE-VERSION=1.0.0";
url += "&SECURITY-APPNAME=XXXX";
url += "&GLOBAL-ID=EBAY-US";
url += "&RESPONSE-DATA-FORMAT=JSON";
url += "&categoryId=213"; // baseball
url += "&keywords=t206"; // change value to title
url += "&paginationInput.entriesPerPage=6";
console.log(url);
axios({
method: "get",
url: url
})
.then(response => {
console.log(response.data);
})
.catch(error => {
console.log(error);
});
module.exports = router;
The URL of the string works when i input in the browser. However when i run node, i get the following:
{
findItemsAdvancedResponse: [
{
ack: [Array],
version: [Array],
timestamp: [Array],
searchResult: [Array],
paginationOutput: [Array],
itemSearchURL: [Array]
}
]
}
I tried to change the response console log to this
console.log(response.data.searchResult)
and
this
console.log(response.data.findItemsAdvancedResponse.searchResult)
but i keep getting undefined.
Any ideas?
It's because findItemsAdvancedResponse
is an Array
. So, do something like this
console.log(response.data.findItemsAdvancedResponse[0].searchResult)
Also beware that searchResult
is also an array. so you have to loop over it to get all the Results