Forum Discussion

mschoenhub's avatar
mschoenhub
Frequent Visitor
3 years ago
Solved

Cannot apply operator & to types Text and Function

Dear all,  I am trying to use a bearer token which I get from a function in a query. Function:    () => let // Get the API Token api_url = "https://api.xxxxxxx.com", token_path = "/o...
  • ImkeF's avatar
    3 years ago

    Ha mschoenhub ,
    that was a tricky one 🙂
    In the function for the token, you are not returning the last step.
    Please change it to this:

    () =>
    let
        // Get the API Token
        api_url = "https://api.xxxxxxx.com",
        token_path = "/oauth2/access_token",
        ClientID = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", 
        Secret = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", 
    
        EncodedCredentials = "Basic " & Binary.ToText(Text.ToBinary(ClientID & ":" & Secret), BinaryEncoding.Base64),
    
        Token_Response = Json.Document(Web.Contents(api_url,
        [
            RelativePath = token_path,
            Headers = [#"Content-Type"="application/x-www-form-urlencoded",#"Authorization"=EncodedCredentials],
            Content=Text.ToBinary("grant_type=client_credentials")
        ]
        )
        ),
    
        // Get the token from the API response
        token = Token_Response[access_token]
    
    in
       token