Running API using R to get the authentication token from a server

48 views Asked by At

After running the API I am getting "NULL" authentication code.

JSON data input format is:

data={
    "list":[
            {"response": {"appId":"appID","userId":"userId","userPwd":"password"}},
            {"selectParList":{}},
            {"uploadParList":[{}]}
        ]
}

Expected output:

{
   "wsInfoMsg":    {
      "statusCode": "200",
      "statusMessage": "User <userId> Login Successfully .!!!",
      "errorMessage": "",
      "errorCause": "",
      "authToken": "MjAyMDA2MTAwMDAwMDAwMDAy"       
   },
   "wsInfoQry": []
}

R code snippet:

library(httr)
library(jsonlite)


url <- "url"


data <- list(
  list(
    response = list(
      appId = "appID",
      userId = "userID",
      userPwd = "userPWD"
    )
  ),
  list(selectParList = list()),
  list(uploadParList = list())
)

response <- POST(url, body=toJSON(data), encode = "json", content_type("application/json"))

token <- content(response)$wsInfoMsg$authToken

print(token)

The output is NULL

Note: url, appID, userID, userPWD to be replaced by actual values

0

There are 0 answers