News headlines from News API


#1

Hi! I am a total n00b when it comes to JSON and pulling data from APIs. The goal here is to parse information out of the newsapi.org APIs and text them to my wife, who works in the digital journalism/editing world.

According to the log, it’s successfully executing the GET request, and bringing that information in. But the text I receive has only my custom text, and doesn’t include any of the information from the JSON.

What am I doing wrong?

The piston:

The log:


#2

It looks like it is returning json already in the request. So instead of parsing json (the error you are getting) try replacing $json with $response on line 21 where you set the variable. What happens then?


#3

Perfect. So I’m now able to extract the data in to the string variable… what I can’t seem to do is get each level from the JSON to follow in order. Taking the information from the following example.

I want to send a message that has [Title, Author, Description, URL], but all I see to manage is [Title, Title, Title, Title, Author, Author, Author, Author…etc.]

How would I format the x2 variable line to get the information set out properly? This is what I now have since my original post:


#4

$respons.articles.description $response.articles.author $respons.articles.title $response.articles.url

Each returns a different part

Or maybe? $response.articles.descriptio[1] Not sure if that will work just to get the second article.


#5

The set message to message=‘your Headlines are: ‘{Author}’: ‘{Title}’: ‘ {Description}’: ‘{Url}

And then send that to your contact


#6

This worked perfectly!! Thank you so much for taking the time to figure this out for me.

Now just to set it all up, customize the email format etc… and the wife’ll be happy.


#7

:clap::grinning:


#8

Great job @Gopack2. Sorry I was in middle of the work day when I first responded and never got a chance to get back on. If
you have more questions we are all here.