Forum Discussion
Convert Dynamic Data source
Hi everyone
I have a token request for an API, but it’s a dynamic data source that can’t be refreshed in the service.
I’ve worked with a token request for another API that wasn’t a dynamic data source, but try as I might, I can’t convert this dynamic data source to a static one.
I keep getting out of my depth; I just don’t understand the M code well enough to convert it. Assuming it can be converted, the API provider seems to think it can’t.
This is their original (dynamic) code:
let
// First, get the access token
tokenUrl = "https://api.iris.co.uk/oauth2/v1/token",
tokenHeaders = [
#"Content-Type" = "application/x-www-form-urlencoded",
#"Authorization" = "Basic {Your credentials in Base64}"
],
tokenBody = "grant_type=client_credentials",
// Function to HTTP POST request for token
GetJsonToken = (url as text, body as text, headers as record) as record =>
let
response = Web.Contents(
url, [
Headers = headers,
Content = Text.ToBinary(body)
]
),
json = Json.Document(response)
in
json,
// Call the function and retrieve the token data
tokenResult = GetJsonToken(tokenUrl, tokenBody, tokenHeaders),
access = tokenResult[access_token]
in
access
And this is the code for the token request from the other API, that refreshes in the service, and that I’m trying to use as a base to convert the above token request. The below code uses parameters for the credentials, so they're not exposed here:
let
TokenReq = Web.Contents(
"https://qws.quartix.net/v2/api/auth?", [
Headers = [
#"Content-Type" = "application/json"
],
Content = Json.FromValue([
CustomerID = Quartix_CustomerID,
UserName = Quartix_UserName,
Password = Quartix_Password,
Application = Quartix_Application
])
]
),
TokenJson = Json.Document(TokenReq),
TokenData = TokenJson[Data],
AccessToken = TokenData[AccessToken]
in
AccessToken
Can anyone please help adapt the dynamic code to be static, so that it can be refreshed in the service?
Thanks
Jim
Hi jimbob2285 ,
Thank you for reaching out to fabric community.
According to Microsoft's documentation, most dynamic data sources cannot be refreshed in the Power BI Service. A documented exception is using the RelativePath and Query options with Web.Contents. Since your token endpoint is fixed, you may want to restructure the request around a static base URL (for example, https://api.iris.co.uk ) and use RelativePath = "oauth2/v1/token" instead of passing the full URL directly to Web.Contents, then check whether the query is still identified as a dynamic data source.
https://learn.microsoft.com/en-us/power-bi/connect-data/refresh-data#refresh-and-dynamic-data-sourceshttps://learn.microsoft.com/en-us/powerquery-m/web-contents#about
Thanks!!
1 Reply
- v-sathmakuriCommunity Support
Hi jimbob2285 ,
Thank you for reaching out to fabric community.
According to Microsoft's documentation, most dynamic data sources cannot be refreshed in the Power BI Service. A documented exception is using the RelativePath and Query options with Web.Contents. Since your token endpoint is fixed, you may want to restructure the request around a static base URL (for example, https://api.iris.co.uk ) and use RelativePath = "oauth2/v1/token" instead of passing the full URL directly to Web.Contents, then check whether the query is still identified as a dynamic data source.
https://learn.microsoft.com/en-us/power-bi/connect-data/refresh-data#refresh-and-dynamic-data-sourceshttps://learn.microsoft.com/en-us/powerquery-m/web-contents#about
Thanks!!