Extract JSON Value and Use in Header in Custom Connector/R

233 Views Asked by At

I’m creating a custom connector, the API requires me to authenticate with a username and password, it will then return a token to use for further queries. (The token has to be refreshed every 5mins but that’s another story)

I’ve extracted the token but whenever I try to use it in the header it complains "The parameter is expected to be of type Text.Type or Binary.Type", I tried wrapping Record.Field and Text.From without success.

Authentication code

 loginPayload = [
        username = Extension.CurrentCredential()[Username],
        password = Extension.CurrentCredential()[Password]
    ],
    loginBody = Json.Document(loginPayload),
    responseLogin = Web.Contents("https://api.company.io/login", [
        Headers = [#"Content-Type" = "application/json"],
        Content = loginBody
    ]),

    
    token = Json.Document(responseLogin)[token],

I try to use the token here (which causes the error)

responseAlert = Web.Contents("https://company.io/v2/alert", [
        Headers = [
            #"Content-Type" = "application/json",
            #"x-redlock-auth" = token
        ],
        Content = alertBody
    ]),

    a = Json.Document(responseAlert)
0

There are 0 best solutions below