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
What is in the documentation from the API? Did you try to connect with for example Postman (https://www.postman.com/)? Did you get a succesvol connection?
If your not familiar with Postman:
Postman is an API platform for building and using APIs. Postman simplifies each step of the API lifecycle and streamlines collaboration so you can create better APIs—faster.I'll try that. Thanks!
- Anonymous3 years agoNot applicable
OK, so for future reference, in case there is somebody else searching for the complete answer, here is what I did after SomeDataDude put me on the right track. My goal was to connect to Channel Advisor orders.
STEP 1: CREATE CUSTOM FUNCTION
Prerequisite: create an application in Channel Advisor's developer console and record the access token and refresh token.
Recommended: test code first before creating the function as described elsewhere in this post.
() => let url = "https://api.channeladvisor.com/oauth2/token", headers = [#"Authorization"="Basic XXXXX"], postBody = [ grant_type = "refresh_token", refresh_token = "XXXXX" ], response = Json.Document(Web.Contents(url, [ Headers = headers, Content = Text.ToBinary(Uri.BuildQueryString(postBody)) ])), access_token = response[access_token] in access_tokenThis gets the current access token (= bearer token in Channel Advisor "speak") based on the refresh token.
STEP 2: CREATE THE CONNECTION QUERY
This is the initial query:
let Source = Json.Document(Web.Contents("https://api.channeladvisor.com/v1/orders", [Headers=[#"Authorization"="bearer " & GetAccessToken(), #"accept" = "text/plain", #"Content-Type"="application/json"], ManualStatusHandling = {404, 400}])) in SourceAnd this is the output from that query:
Click on the word "List" in the table, next to the word "value". This inserts a step "Navigation" into the query. It also opens up the list an a tab called "List Tools" at the top. Click on "Convert | To Table" on the ribbon in the "List Tools" tab:
It will present you with a dialog box. I simply clicked "OK":
The last step is to expand the resulting column:
Uncheck "Use original column name as prefix" and click "OK". Voila, here is your data.
OF NOTE:
Make sure that both data sources are set to connect anonymously. Otherwise, you will get an error. Also, try things in Postman first if you run into trouble.
- Anonymous3 years agoNot applicable
SomeDataDude I set up Postman and was able to connect as follows:
GET https://api.channeladvisor.com/v1/ordersAuthorization: Bearer token (using the initial access token from Channel Advisor)
Body: none
When I try to enter a refresh token, the whole thing errors out.
How do I now take what is working in Postman and alter the initial code for the function and query? What I have tried is to enter that information into my initial code, but it doesn't work. It comes back and says something about connecting anonymously.