-1

I'm trying to store the results of the '/sources' endpoint from this api from the backend of a Node/Express app: https://newsapi.org/docs/endpoints/sources

The results are coming back like so:

{
  "confirmation": "success",
  "data": "{\"status\":\"ok\",\"sources\":[{\"id\":\"abc- 
  news\",\"name\":\"ABC News\",\"description\":\"Your trusted source for 
  breaking news, analysis, exclusive interviews, headlines, and videos 
at ABCNews.com.\",\"url\":\"http://abcnews.go.com\",\"category\":\"general\",\"language\":\"en\",\"country\":\"us\"}
}

I can't figure out how to access the below, I am assuming it's because of the escape slashes but I can't find anything out about an easy way to convert this or why the results are returning like this. I know I could hack at it for a while and figure out a way to remove the slashes, but the other endpoints at this API return results as JSON objects I have no problem working with and I want to make sure I'm not missing some kind of big obvious issue with something I did, and what search terms I am missing when I'm Googling this?

(in my defense, I'm trying to do this while keeping an eye on today's 3 World Cup group stage matches so....)

 superagent.get('https://newsapi.org/v2/sources')
    .set('X-Api-Key', '')
.then(results => {
  res.json({
    status: 'success',
    data: results.text
  })
})
.catch(err => {
      res.json({
       confirmation: 'fail',
       err: err
     })
   })
Pogrindis
  • 7,755
  • 5
  • 31
  • 44
ScorpIan
  • 71
  • 10

1 Answers1

0

The issue was the results.text, it needed to be results.body.sources

ScorpIan
  • 71
  • 10