Support Topics Documentation Slack YouTube Blog

How to get data from an external API?

Hi, I assume it’s with the Network API, but I don’t really know how to use it and I can’t find documentation. I have need to call a thrid party API with two parameters: api_key and query. It returns a json object.

Which puzzle pieces to combine to get the results?

Hello @Michiel_Prins1

Yes, Network API is the right way to get any third party API.
In order to specify query you can use Create Object block

Regards, Vlad

Hi Vladimir,

I’m having problems trying to get data from what looks like a simple external News API.

For example if I’m trying to do a search for the key term “logistics” and I
just enter the appropriate url string into my browser link I get a good following response back.

But I can’t get the following Codeless “GET HTTP/s” block variations to pull news feed data into a variable.

Version 1 uses the “Create Object” block to pass my apiKey and query term “logistics” into the query.

Version 2 hardcodes both the apiKey and “q” search term “logistics” into the URL string.

Am I missing any parameters to put into the “headers” and “body” of the “GET HTTP/s”?

I didn’t see anything else required on the newsapi.org documentation other than the search term and my temp API key which I’m using for testing.

Sorry for the newbie question and thanks for your help!

Hi @William_Lee,

The documentation page says that the X-API-Key header is required:


However, I do not see you passing any HTTP Headers in the request in your HTTP/s block in Codeless.

Regards,
Mark

My bad, it looks like it can be passed as a query string parameter as an alternative to the HTTP header. Can you describe what you get back from that block? You could use logging (the print block) to see what the block returns.

Hi Mark thanks for the quick reply. I did the print block.

But this is what I get back in my browser console.

Thanks for helping with this.

I believe the root cause for the error is this:

Ok I wasn’t quite sure why that error popped up since I was led to believe that news api site was free for developers just getting started… In any case I decided to try another news api site from yahoo that has some clear header and parameter documentation.

So with this documentation I constructed the following codeless blocks (partial api-key showing) triggered by a button.

But then I get these string of errors and I’m at a loss on what to look at next.


Is it possible to get a codeless block example on how to properly use HTTP/s GET to pull from any generic api like yahoo news? Thanks!!

Would love to see more documentation or a video on calling external API’s.

Hello @William_Lee

Error You are not subscribed to this API - This is a response from rapidapi, you must subscribe to this API.
I tested, initially I also got this error, but after I signed up in the rapidapi itself, then I got a 200 code in response.
Subscribe to the appropriate API at rapidapi and try again to request. Please write about the result.

Thanks Vladimir, After I clicked the Test Endpoint button I was able to get the following api body message back.

So I tried my best to figure out how to structure the Codeless syntax here .

But I’m still not able to populate my UI which has the same content logic names as the text content names you see here.

2

I tried to look at the console as you can see here but couldn’t really make sense of it.

Could you please show me the codeless blocks that allowed you to call this rapid api data successfully? Thanks!!

Hello @William_Lee

You need to replace the “Get Properties” blocks as follows (the screenshot shows the correct version on the right) Monosnap

Regards,
Inna

1 Like

Hi Inna thanks for that block “syntax” correction for object creation and mapping. However I’m still unable to create a working HTTPS GET block using the above example for URL parameters like the following example.

block_construction_1

Can you please show me what I’m doing wrong with my HTTPS GET above here.

Thank YOU!!

Hello @William_Lee

If I understood correctly, you cannot get the data here, don’t you?

But I dont see enough info from ypur screenshots.

I just tried some random rapidapi

I copied params from “red circle” on screenshot and put it in codeless block and it works fine


Regards,
Viktor

Hi Victor and Inna, Thanks for that codeless example with the HTTPS GET…
I finally got it to show up on a print statement below.

However I’m not able to bind my text fields in my dynamic list row for any of the data that’s returned by this API.

4

This content logic should work right?

Unfortunately it’s not showing up in preview mode. Any ideas?

Thanks!

Hello @William_Lee.

You are trying to use the “map” method on the object, but you need to extract the “news” property from the “var_get_object” object and return it.

For example:

Regards,
Alexander

1 Like

That did it thanks!

Hi does the above console error mean that they are blocking backendless API requests from your site because I’m not sending them a GET request from my own localhost? If so is there a way around this error?

I just hardcoded all my parameters into the url path string for testing following this documentation.

Hello @William_Lee

No, this doesn’t come from Backendless. Your app is hosted on the Backendless (backendlessappcontent.com) which is opened over HTTPS and in your app requests data from external server over HTTP, that’s the reason why browser blocks this request.

Try to change http://api.mediastack.com to https://api.mediastack.com

Regards, Vlad

Hi Thanks for your help.

I tried that but unfortunately it didn’t work and returned this error instead.

This is the string I’m using in the Codeless HTTP/s GET path