Monday, 1 May 2017

request node get results from api response

I am making an API call using request.

Everything is working ok, but I cannot actually get the results from the response.

My code looks like this

app.get('/events/:query', (req, res) => {

    request('http://www.skiddle.com/api/v1/events/search/?api_key=*****&keyword=elvis', (error, response, body) => {
        res.setHeader('Content-Type', 'application/json');
        res.send(body);
    });

});

The res.send(body); looks like the below. Does anyone know how I can access the results? I have tried body.results but this doesn't work.

{  
   "error":0,
   "totalcount":"25",
   "pagecount":20,
   "results":[  
      {  
         "id":"12958041",
         "EventCode":"FOOD",
         "eventname":"Elvis Tribute",
         "cancelled":"0",
         "venue":{  
            "id":72198,
            "name":"Simla Restaurant",
            "address":"5a Watling Street",
            "town":"Dordon",
            "postcode":"B78 1SS",
            "country":"GB",
            "phone":"00000000000",
            "latitude":52.597021,
            "longitude":-1.6113712,
            "type":"Restaurant",
            "rating":0
         },
         "imageurl":"https:\/\/d31fr2pwly4c4s.cloudfront.net\/2\/2\/a\/950766_0_elvis-tribute_th.jpg",
         "largeimageurl":"https:\/\/d31fr2pwly4c4s.cloudfront.net\/2\/2\/a\/950766_0_elvis-tribute.jpg",
         "link":"http:\/\/www.skiddle.com\/whats-on\/Birmingham\/Simla-Restaurant\/Elvis-Tribute\/12958041\/",
         "date":"2017-05-10",
         "startdate":"2017-05-10T19:00:00+00:00",
         "enddate":"2017-05-10T23:00:00+00:00",
         "description":"Elvis Tribute evening ",
         "openingtimes":{  
            "doorsopen":"19:00",
            "doorsclose":"23:00",
            "lastentry":""
         },
         "minage":"0",
         "imgoing":null,
         "goingtocount":"0",
         "tickets":false,
         "entryprice":"Ticket: GBP 26.95",
         "rep":{  
            "enabled":null
         }
      },
      {  
         "id":"12948859",
         "EventCode":"COMEDY",
         "eventname":"NCFComedy present The Elvis Dead - Part of Derby Comedy Fest",
         "cancelled":"0",
         "venue":{  
            "id":77454,
            "name":"Carnero Lounge",
            "address":"10 St Peter's Gate",
            "town":"Derby",
            "postcode":"DE1 1SH",
            "country":"GB",
            "phone":"",
            "latitude":52.9208847,
            "longitude":-1.4767019,
            "type":"bar",
            "rating":0
         },
         "imageurl":"https:\/\/d31fr2pwly4c4s.cloudfront.net\/5\/c\/c\/946899_2_ncfcomedy-present-the-elvis-dead-part-of-derby-comedy-fest_th.jpg",
         "largeimageurl":"https:\/\/d31fr2pwly4c4s.cloudfront.net\/5\/c\/c\/946899_2_ncfcomedy-present-the-elvis-dead-part-of-derby-comedy-fest.jpg",
         "link":"http:\/\/www.skiddle.com\/whats-on\/Derby\/Carnero-Lounge\/NCFComedy-present-The-Elvis-Dead---Part-of-Derby-Comedy-Fest\/12948859\/",
         "date":"2017-05-11",
         "startdate":"2017-05-11T19:00:00+00:00",
         "enddate":"2017-05-11T20:00:00+00:00",
         "description":"Rob Kemp: The Elvis Dead\r\nPart of Derby Comedy Festival",
         "openingtimes":{  
            "doorsopen":"19:00",
            "doorsclose":"20:00",
            "lastentry":""
         }
      }
   }



via peter flanagan

No comments:

Post a Comment