Forum

Web Connector Power...
 
Notifications
Clear all

Web Connector Power Query to API

4 Posts
2 Users
0 Reactions
581 Views
(@nicolone)
Posts: 2
New Member
Topic starter
 

I have gone through this 

https://www.youtube.com/watch?v=2mR44X7PrRo

I have done EXACTLY the same steps to try to connect to nasa

https//api.nasa.gov/insight_weather/?api_key=DEMO_KEY&feedtype=json&ver=1.0

but what I got is an error message saying "Impossibile to resolve the remote name: 'api.nasa.gov' "

____________

BTW This is part of my attempt to understand how to actually connect to a webservice of mine where I have a token.

My headers include an authorization Bearer or Token

Something that in "M" language should be similar to

let source

source = Json.Document(Web.Contents("http://213.215.231.4/swappX/api/ASC_Anni",

[Headers=[Bearer="my  token"]]

))

in

source

 

It's not working and I can't find any way to make it work

I also went through

https://community.fabric.microsoft.com/t5/Desktop/Connect-API-with-Header-ApiKeyName-not-going-through/m-p/437253

but this is not working for me.

Any help is highly appreciated

 
Posted : 29/10/2023 8:16 am
Philip Treacy
(@philipt)
Posts: 1629
Member Admin
 

Hi Nicola,

without your code I can't do much to help you.

Phil

 
Posted : 30/10/2023 7:42 pm
(@nicolone)
Posts: 2
New Member
Topic starter
 

I copy

https://api.nasa.gov/insight_weather/?api_key=DEMO_KEY&feedtype=json&ver=1.0

and add a connection "from Web" but the answer is "Impossible to solve the remote name "api.nasa.gov"".
_________________________

I've got an API which is public and I can see it from the web. if I type https://jsonplaceholder.typicode.com/posts I get the json.

If I use Power query IT WORKS if I write

let
    Source= Json.Document(
        Web.Contents(
            "https://jsonplaceholder.typicode.com/posts"
       ))
 
in
    Source
but

let

    Source= Json.Document(

        Web.Contents(

            "https://jsonplaceholder.typicode.com/posts",

                          [Content=

                    Json.FromValue(

                    [title="foo", body ="bar", userId = 1]

                                        )

        ]))

in

    Source

is giving my an error. (again impossible to solve the tremote name jsonplaceholder.tyipicode.com)

It's like if I couldn't add any additional headers...which prevents me from adding authentication...

Infact I have my own API which I try to connect to through:

let 

Origine = Json.Document(Web.Contents("http://213.215.231.4/swappX/api/ASC_Anni",

      [Headers=[#"x-api-key"="...my APItoken"]]))

in

    Origine

This is one of the ways to pass an api key which I have found on the web (one of many).

But  it says credentials are not valid...in the end what I need is this, and previous steps are for me necessary just to understand how it works and then to pass a token. I have found many different versions on the web on how to add the headers payload but none of them works in my case....

Any help is appreciated, thanks

 
Posted : 31/10/2023 3:10 am
Philip Treacy
(@philipt)
Posts: 1629
Member Admin
 

Hi Nicola,

I can't reproduce any of your issues.

If you click the link you pasted to the NASA API it returns JSON data.  Therefore the error you are receiving is not due to the API.  

As the error states something about "impossible to solve the remote name" it would suggest some kind of name (DNS) lookup issue.  As such that's a network/PC configuration issue.

That said, if you simply click the link to the NASA API and get a result returned, your PC is able to resolve the domain name correctly.  In which case I can't really shed any light on to why you are getting an error.

I tried the sample code you provided for the jsonplaceholder website and both queries successfully return data.

Have you tried just visiting the URL's for these queries and seeing if they return a valid response?

In terms of how to provide authorization headers, I wrote about this here Connecting to an OAuth API with Power Query

If you download the Excel workbook and examine the query you'll see that I pass the authorization as a header like this

 

data= Json.Document(Web.Contents(api_url,
[
RelativePath = path,
Query = [end_date=endDate, start_date=startDate, fields=fields],
Headers = [#"Authorization"="Bearer "&token,#"Content-Type"="application/json"]
]

 

Regards

Phil

 
Posted : 31/10/2023 9:30 pm
Share: