Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
kalspiros
Helper I
Helper I

JSON and authentication issues

Hi all,

 

Following multiple attempts and researches, the problem persists.

I am trying to connect to a business management system and i constantly have issues with authorisation.

This is what i use (Example 2🙂

 

let
    apiToken = "********************************",
    url = "https://********.**********.com/api/tasks",
    query = [
        start = "2022-01-01",
        end = "2022-01-31"
    ],
    headers = [
        Authorization = "Token " & apiToken,
        #"Content-Type" = "application/json"
    ],
    response = Web.Contents(
        url,
        [
            Headers = headers,
            Query = query
        ]
    ),
    jsonResponse = Json.Document(response)
in
    jsonResponse

 

  and that is what i get

kalspiros_0-1650888691762.png

i changed to anonymous

kalspiros_1-1650888985113.png

and getting this one

kalspiros_2-1650889101795.png

 

Then i have tried this version which i found here:

 

let
    apiToken = "************************",
    site = "https://****.*********.com/",
    url = "api/tasks",
    query = [
        start = "2022-01-01",
        end = "2022-01-31"
    ],
    headers = [
        Authorization = "Token " & apiToken,
        #"Content-Type" = "application/json"
    ],
    response = Web.Contents(
        site,
        [
                RelativePath = url,
            Headers = headers,
            Query = query
        ]
    ),
    jsonResponse = Json.Document(response)
in
    jsonResponse

 

 and i'm still getting the same authentication errors.

 

Can anyone spot an issue with the code? could it be the actual API having issues?

 

Many thanks!

1 ACCEPTED SOLUTION

Many thanks @v-eqin-msft even though, in the end, i used anonymous. my mistake was that i was using the entire API address in the level where i should have only used the link to the site.

 

Have another concern now. Protecting the API Token. Currently reading this one https://community.powerbi.com/t5/Developer/Protection-of-API-Keys-Stored-in-Parameter/m-p/1564020

and i'll keep searching.

View solution in original post

2 REPLIES 2
v-eqin-msft
Community Support
Community Support

Hi @kalspiros ,

 

To my knowledge, since you have such header:

 Authorization = "Token " & apiToken

The data source requires credentials, so Anonymous is not applicable. Please try other authentication methods instead :

  • Anonymous: Select this authentication method if the web page doesn't require any credentials.

  • Windows: Select this authentication method if the web page requires your Windows credentials.

  • Basic: Select this authentication method if the web page requires a basic user name and password.

  • Web API: Select this method if the web resource that you’re connecting to uses an API Key for authentication purposes.

  • Organizational account: Select this authentication method if the web page requires organizational account credentials.

 

Refer to:

Power Query Web connector - Power Query | Microsoft Docs

Solved: Re: Pull data from RESTful API with token authenti... - Microsoft Power BI Community

 

 

Best Regards,
Eyelyn Qin
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Many thanks @v-eqin-msft even though, in the end, i used anonymous. my mistake was that i was using the entire API address in the level where i should have only used the link to the site.

 

Have another concern now. Protecting the API Token. Currently reading this one https://community.powerbi.com/t5/Developer/Protection-of-API-Keys-Stored-in-Parameter/m-p/1564020

and i'll keep searching.

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.

Top Solution Authors
Top Kudoed Authors