Forum Discussion

jimbob2285's avatar
jimbob2285
Advocate IV
2 months ago
Solved

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

 

 

 

 

1 Reply