Forum Discussion
Web.Contents - we couldn't authenticate with the credentials provided (using anonymous credentials)
I am trying to connect to an API with bearer authentication. My first call to the API is to obtain the authentication token - this step seems to be successful. I then call the API again using the token to obtain the results I'm looking for - this is where I am stuck. I initially set the data source settings to Basic API using my login credentials, but I received the following error: "DataSource.Error: Web.Contents with the Content option is only supported when connecting anonymously." If I change the data source settings to use an anonymous connection, I get a different error: "We couldn't authenticate with the credentials provided. Please try again." I'm not sure what else to do! Any help would be greatly appreciated! Thanks in advance.
My code is below (I changed the url, username and password for privacy purposes):
let
Source = Json.Document(Web.Contents("url" & "username=email" & "&password=password")),
#"Converted to Table" = Record.ToTable(Source),
#"Transposed Table" = Table.Transpose(#"Converted to Table"),
#"Promoted Headers" = Table.PromoteHeaders(#"Transposed Table", [PromoteAllScalars=true]),
#"Changed Type" = Table.TransformColumnTypes(#"Promoted Headers",{{"access_token", type text}, {"refresh_token", type text}, {"token_type", type text}, {"expires_in", Int64.Type}}),
#"Content" = Table.AddColumn(#"Changed Type", "Content", each "{
""search"": ""IRE"",
""startRecord"":1,
""recordCount"":100,
""includeAbstracts"":true,
""defaultFields"":""title,parentTitle,abstract"",
""includeCollections"": {
""filter"":""Id"",
""collectionIds"": [
23814
]
},
""SortOrder"":""PubYear"",
""SortDirection"":""Descending""
}
"),
#"Changed Type1" = Table.TransformColumnTypes(Content,{{"Content", type text}}),
#"Added Custom" = Table.AddColumn(#"Changed Type1", "API", each Web.Contents("url", [Headers = [Authorization = [access_token]], Content = Text.ToBinary([Content])]))
in
#"Added Custom"
12 Replies
- AnonymousNot applicable
HI asomers21.
I'd like to suggest you add the relative path to split your url string to root url and relative path to enable anonymous credentials on root level.
Refresh not working in Power BI Service
Regards,
Xiaoxin Sheng
- asomers21Frequent Visitor
Anonymous - Thank you very much for the reply!
Unfortunately, this hasn't resolved my issue. I used RelativePath in both instances of Web.Contents (see edited code below), but I still receive the same error message: "We couldn't authenticate with the credentials provided. Please try again." When I try to edit the credentials and set them to anonymous, the url options in the dropdown for selecting which level to apply these settings to still contain the relative path and doesn't give me the option to select just the root path. If you see any issues with my code or have any other ideas, I'd greatly appreciate it. Thanks!
let Source = Json.Document(Web.Contents("https://www.url.com", [RelativePath = "restapi/v1/token?" & "username=email" & "&password=password"])), #"Converted to Table" = Record.ToTable(Source), #"Transposed Table" = Table.Transpose(#"Converted to Table"), #"Promoted Headers" = Table.PromoteHeaders(#"Transposed Table", [PromoteAllScalars=true]), #"Changed Type" = Table.TransformColumnTypes(#"Promoted Headers",{{"access_token", type text}, {"refresh_token", type text}, {"token_type", type text}, {"expires_in", Int64.Type}}), #"Content" = Table.AddColumn(#"Changed Type", "Content", each "{ ""search"": ""nanoknife"", ""startRecord"":1, ""recordCount"":100, ""includeAbstracts"":true, ""defaultFields"":""title,parentTitle,abstract"", ""includeCollections"": { ""filter"":""Id"", ""collectionIds"": [ 23814 ] }, ""SortOrder"":""PubYear"", ""SortDirection"":""Descending"" } "), #"Changed Type1" = Table.TransformColumnTypes(Content,{{"Content", type text}}), #"Added Custom" = Table.AddColumn(#"Changed Type1", "API", each Web.Contents("https://www.url.com", [Headers = [Authorization = [access_token]], Content = Text.ToBinary([Content]), RelativePath = "restapi/v1/Search/query"])) in #"Added Custom"- asomers21Frequent Visitor
Update: I tried clearing the permissions for the data source and resetting them to anonymous. I am now given the option to select just the root url to apply the settings to, but I still continue to get the same error that they are unable to authenticate the credentials.
- FelibaRegular Visitor
Hello from Uruguay,
Finally you could acces? Or you have failed in the diferents attempts? I am having the same problem and I dont know what to do
- asomers21Frequent Visitor
Unfortunately, I never had any luck solving this issue and had to pull in the data using an entirely different workflow.