Forum Discussion
Channel Advisor API Connection with auth key creation
- 4 years ago
Great! Cheers!
The response is in Json format, so you just need to add a step at the end of the custom function to extract access_token value. Don't forget to add a comma at the end of previous response step.
..................... response = Json.Document(Web.Contents(.......................)), access_token = response[access_token] in access_tokenJing
Hi v-jingzhang,
Thanks for sharing the solution. Could you help me with the following problem?
I created the function, that is working fine. But if I put the function in the second query, it doesn’t work. When I put the token directly in the query it works fine. I use the following M code:
let
Source = Json.Document(Web.Contents("URL",
[Headers=[#"Authorization"="Bearer "&GetAccessToken(),
#"accept" = "text/plain",
#"Content-Type"="application/json"],
ManualStatusHandling = {404, 400}]))
in
Source
My custom query is called GetAccessToken.
What am I doing wrong?
This is the error I get: Formula.Firewall: Query 'Query5' (step 'Source') is accessing data sources that have privacy levels which cannot be used together. Please rebuild this data combination.
As it says. Modify the query privacy settings so that they match. Or Inline the token query.
- SomeDataDude3 years agoAdvocate I
Thanks for the trigger around Bearer. I put the Bearer &function in the other query. Now it is working.
Function:
() => let content = "{ ""mode"" : ""raw"", ""client_id"": ""************", ""client_secret"": ""*********"" }", Source = Json.Document(Web.Contents("url_refreshtoken", [Headers=[#"Authorization"="******", #"accept" = "text/plain", #"Content-Type"="application/json"], ManualStatusHandling = {404, 400}, Content=Text.ToBinary(content)])), access_token ="Bearer " &Source[access_token] in access_tokenQuery:
let Source = Json.Document(Web.Contents("search_url", [Headers=[#"Authorization"= GetAccessToken(), #"accept" = "text/plain", #"Content-Type"="application/json"], ManualStatusHandling = {404, 400}])) in Source - lbendlin3 years agoSuper User
- SomeDataDude3 years agoAdvocate I
Hi lbendlin ,
Thanks for your reply. Which options do I have to modify te query privacy settings? Inline the token is not an option, because it is a refresh token. I don’t want to replace the token every time I refresh the data.
- SomeDataDude3 years agoAdvocate I
Okay, thanks.
That clears the error on Privacy Levels. Now I run into the error: We couldn’t authenticate with the credentials provided. Please try again.
But if I run the token Inline, it runs fine. So, I think the M code is not good enough to passes the authentication. But I have no clue, what’s wrong.
- lbendlin3 years agoSuper User
Did you notice there are two spaces after "Bearer" ?
- SomeDataDude3 years agoAdvocate I
Yes I did. In my current M code is it just one.