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

The Fabric community is upgrading! Read all of the details including the timeline and what you can expect. Learn more

Reply
Zeroeffect
New Member

Get data from REST API with oAuth-Token, returns couldn't authenticate with the credentials provided

Hi,

 

I'm trying to connect to a Rest API from Sugar CRM (sugarcrm).

I'm using the  example from Chris Coester; Get Data from Twitter API with Power Query

and I have updated the code slightly with info from Chris Webb; Using The RelativePath And Query Options With Web.Contents()

 

Part 1, getting the access token from the first api call works fine. But in the next step, when I try to access a page using the access token, I get the following error; We couldn't authenticate with the credentials provided

 

I'm using the Anonymous connection method to access web content, and I have visited File -> Options and Settings -> Data source settings and both tried to Clear All Permissions and also Edit the permissions to Anonymous

 

Here is my code:

 

 

let
    root="https://xxx.sugaropencloud.eu",    
    relativepath = "/rest/v11_12/oauth2/token",
    
    GetJsonAccess = Web.Contents(root,
    [
        RelativePath = relativepath,      
        Query=
        [
            grant_type="password",
            client_id="sugar",
            username="xxx",
            password="xxx",
            platform="powerbi"
        ],
        Headers = [#"Content-Type"="application/x-www-form-urlencoded;charset=UTF-8"],
        Content = Text.ToBinary("grant_type=password")  //This needs to be here for some reaon..
    ]),
 
    FormatAsJson = Json.Document(GetJsonAccess),
    // Part 1 - Completed here

    // Gets token from the Json response
    AccessToken = FormatAsJson[access_token],
    AccessTokenHeader = "bearer " & AccessToken,

    relativepath_report = "/rest/v11_12/me",

    // Uses the Twitter GET search/tweets method using the bearer token from the previous POST oauth2/token method
    GetJsonReport = Web.Contents(root,
    [
        RelativePath = relativepath_report,     
        Headers = 
        [
            #"Authorization"=AccessTokenHeader
        ]        
    ])

in
    GetJsonReport 

 

 

 

The code above works fine if I stop after Part 1 (see comment in code), but when I run all of the code above, I get the following error message: We couldn't authenticate with the credentials provided. Please try again.

 

If I try to access the URL (https://xxx.sugaropencloud.eu/rest/v11_12/me) from a webbrowser (without the correct Acces-token) I get the following error message, so even if the token was wrong, I expect another error message from Power BI then the one from above..

 

 

{
    "error": "need_login",
    "error_message": "No valid authentication for user.",
    "url": "https://sts.service.sugarcrm.com/oauth2/xxx",
    "platform": "base"
}

 

 

 

I have managed to get it to work by using Postman  (First getting an Access Token and then using it in another call)

 

Zeroeffect_0-1655020200697.png

 

Please note that I have replaced all sensitive information above, with xxx (Part of the URL, Username and Password)

 

Any help is much apreciated!

 

Thanks

1 ACCEPTED SOLUTION
Zeroeffect
New Member

Hi again!

 

I found the solution!!! With a lot of help from my friends!

 

It's a really small and annoying error. 
This row:

 AccessTokenHeader = "bearer " & AccessToken,

should be replaced with this row:

 AccessTokenHeader = "Bearer " & AccessToken,

Do you see the difference? Bearer should start with a capital B

 

I hope this helps someone!

 

 

View solution in original post

2 REPLIES 2
Zeroeffect
New Member

Hi again!

 

I found the solution!!! With a lot of help from my friends!

 

It's a really small and annoying error. 
This row:

 AccessTokenHeader = "bearer " & AccessToken,

should be replaced with this row:

 AccessTokenHeader = "Bearer " & AccessToken,

Do you see the difference? Bearer should start with a capital B

 

I hope this helps someone!

 

 

Hi, 

does your dataset refresh without errors when you publish your report to the Power BI service? I currently have a similar query but I get error 405 saying the method is not allowed or unable to combine data.

Helpful resources

Announcements
FabCon and SQLCon Barcelona 2026

FabCon & SQLCon – Barcelona 2026

Join us in Barcelona for FabCon and SQLCon, the Fabric, Power BI, SQL, and AI community event. Save €200 with code FABCMTY200.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.