Forum Discussion
Api Connection with methods and token
Hi All,
I'm newby with power BI
I want to connect to web serwice with token autenthication and method
Connection is to https://api.baselinker.com/index.php
I preapared code like this, but soesnt work. Error "Connent is not the right option for this function.
can you advise?
let
url = "https://api.baselinker.com/connector.php",
body = "{""Method"":""getOrders""}",
header =[#"X-BLToken"= "################################",#"Content-Type"= "application/json"],
response = Web.Headers(url,[Content=Json.FromValue(body),Headers=header]),
Source = Json.Document(response,1252)
in
Source
2 Replies
- amitchandakSuper User
doman2508 , refer if these methods can help
Token based Auth
https://www.youtube.com/watch?v=f7HLyiAk-lQ
https://community.powerbi.com/t5/Desktop/Connect-to-data-with-API-token/td-p/731867
https://chris.koester.io/index.php/2015/07/16/get-data-from-twitter-api-with-power-query/
https://docs.microsoft.com/en-us/rest/api/power-bi/embedtoken - Inna84Regular Visitor
Hello, try this in PQ:
let
// Token and API URL
apiUrl = "https://api.baselinker.com/connector.php",
tokenHeader = [X-BLToken = ""],// Request headers
headers = [#"Content-Type"="application/x-www-form-urlencoded"] & tokenHeader,// Request data
requestData = [
method = "getOrders",
parameters = "{""date_from"": 1692223200}"
],// Convert request data to form-urlencoded
formData = "method=" & Uri.EscapeDataString(requestData[method]) & "¶meters=" & Uri.EscapeDataString(requestData[parameters]),// Create the request
source = Web.Contents(apiUrl, [Headers=headers, Content=Text.ToBinary(formData)]),// Convert response to text
responseText = Text.FromBinary(source),// Parse JSON response
jsonResponse = Json.Document(responseText)
in
jsonResponse
You must change token and date