Forum Discussion
CMAltium
2 years agoFrequent Visitor
Calling two different APIs with different authentication requirements
Hi, I have set up OAuth 2 in a power query connector to work with refresh tokens, to access reports from an API and show them in a table. This works fine. However, the URL to access the repor...
AmiraBedh
2 years agoSuper User
Create a new function in Power Query to handle the TinyURL API authentication and URL shortening and define the authentication mechanism for the TinyURL API.
// Function to get TinyURL shortened URL
let
TinyURL_API_Key = "YourTinyURLApiKey",
BaseURL = "https://api.tinyurl.com/create",
ShortenURL = (LongURL as text) as text =>
let
Body = "{""url"":""" & LongURL & """, ""domain"":""tiny.one""}",
Options = [
Headers = [#"Content-Type"="application/json", #"Authorization"="Bearer " & TinyURL_API_Key],
Content = Text.ToBinary(Body)
],
Response = Json.Document(Web.Contents(BaseURL, Options)),
ShortenedURL = Response[short_url]
in
ShortenedURL
in
ShortenURL
Then you call it in your main PQ :
let
Source = Web.Contents("https://your-main-api.com/reports", [Headers = [Authorization = "Bearer " & AccessToken]]),
Data = Json.Document(Source),
Reports = Data[reports],
LongURL = "https://your-main-api.com/reports/details?reportId=1234567890",
ShortenedURL = ShortenURL(LongURL),
FinalData = Table.AddColumn(Reports, "Shortened URL", each ShortenedURL)
in
FinalData
Connecting to an OAuth API Like PayPal With Power Query • My Online Training Hub
How to configure OAuth 2.0 Authentication for Microsoft Power Platform Custom Connectors
Handling authentication for Power Query connectors - Power Query | Microsoft Learn