How to put JSON object in header

The REST API that I am trying to connect to requires a JSON authorization in the header. It is supposed to be in the format

{
“auth” : {
“command” : “api.authenticate”,
“params” : {
“username”: “username@example.com”,
“password”: “swordfish”
}
}
}

I can’t seem to figure out a way to do this in the API Connector. Using the key value input fields puts quotation marks around the object so that it just becomes a string in the RAW header.

Am I missing something obvious? Does anyone know of a way to do this?

Can you provide link to API Doc?

Yes, https://docs.devicewise.com/Content/Products/IoT_Portal_API_Reference_Guide/HTTP_Interface/HTTP-Interface.htm

  • Each TR50 JSON command requires either an “auth” section or a header parameter named “sessionId” containing the sessionId for the session,

This work a little bit like oAuth. You first do a request for a “token” (sesssionId) and you provide this session ID in header for authorization.

You don’t put the request in header. You put this in body to get the session ID. Further call will use session ID. You have two choice, use it in header or use it in body.
Header =

sessionId: 52e17675d15a7030f800000b

Body =

{
  "auth" : {
    "sessionId" : "52e17675d15a7030f800000b"
  },
  "1" : {
    "command" : "diag.ping"
  }
}

Wow, thanks! So will it work if I just use the auth: in the body of every post?

You first need to get the session ID to the api.authenticate endpoint. And use this response to do other call. Iguess you can do use the same Sessions ID for a moment before it will expire.

OK, very helpful. I will see what I can do.

1 Like

When I try to initialize the authorization API it returns

Raw response for the API
Status code 401
Authentication session is invalid: Error: Both username and password required.

Also Tried