Here I call the module. Then ask for the response. then I use JSON.parse
the body of the response but the output looks like this.
{ response:
{ status: 'ok',
userTier: 'developer',
total: 240,
startIndex: 1,
pageSize: 1,
currentPage: 1,
pages: 240,
orderBy: 'newest',
results: [ [Object] ] } }
I want to be able to see the Objects
{
"response": {
"status": "ok",
"userTier": "developer",
"total": 240,
"startIndex": 1,
"pageSize": 1,
"currentPage": 1,
"pages": 240,
"orderBy": "newest",
"results": [{
"id": "sustainable-business/2017/jun/13/battery-storage-and-rooftop-solar-could-mean-new-life-post-grid-for-consumers",
"type": "article",
"sectionId": "sustainable-business",
"sectionName": "Guardian Sustainable Business",
"webPublicationDate": "2017-06-12T23:51:00Z",
"webTitle": "Battery storage and rooftop solar could mean new life post-grid for consumers",
"webUrl": "https://www.theguardian.com/sustainable-business/2017/jun/13/battery-storage-and-rooftop-solar-could-mean-new-life-post-grid-for-consumers",
"apiUrl": "https://content.guardianapis.com/sustainable-business/2017/jun/13/battery-storage-and-rooftop-solar-could-mean-new-life-post-grid-for-consumers",
"isHosted": false
}]
}
}
this is the code
function prettyJSON(data) {
return JSON.stringify(data,null," ");
}
api.custom.search({fromDate:"2017-06-12",
toDate:"2017-06-12",
orderBy:"newest",
//showFields:"all",
pageSize: 2})
.then(function(response){
var reqBody = response.body.toString();
reqBody = JSON.parse(reqBody);
console.log(reqBody);
})
.catch(function(err){
console.log(err);
});