Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
3 years ago

Get token and data from rest api with JWT

Hello,

I am very new to JWT and trying to get access token as well as data through JWT rest Api.

so the authentication is done through JWT token and the token should be sent in the authentication header to get the data.

here's my code for now:

 

 

 

 

let 
    //URLs
    urlApi = "https://myurl/outbound/api",
    pathToken = "/account/requesttoken",
    pathData = "/system/all",

    //Client credentials
    credentials = [ #"username" = "my_username", #"password" = "my_password" ],

    //Get JSON Web Token via API
    optionsToken = [Headers=[#"Content-Type"="application/json"], 
    Content=Json.FromValue(credentials)],
    responseToken = Web.Contents(urlApi & pathToken, optionsToken),
 
    //Get Access Token and Token Type
    responseJson = Json.Document(responseToken),
    accessToken = responseJson[token], // name of the token property
 
    //Bearer Token
    authorizationHeader = "Bearer " & accessToken,
 
    //Get Data
    optionsData = [Headers=[#"Authorization"=authorizationHeader]],
    responseData = Web.Contents(urlApi & pathData, optionsData),
    data = Json.Document(responseData)
in
    data

 

 

 

 

the error I am getting is:

 

Expression.Error: We cannot apply field access to the type Text.
Details:
Value= what appears to be the token I guess? it is alot of random letters
Key=token

 

 

I would be grateful for your help.

2 Replies