I am working on a side project at work (I'm not a developer).
What I'm trying to achieve is validating whether status
is NULL
or it has ERR
in the login request response so I can know if I may continue the process.
This is the code I have so far:
namespace EseyeSIMAPI
{
class Program
{
static void Main(string[] args)
{
var client = new RestClient("https://siam.eseye.com/Japi/Tigrillo");
var loginRequest = new RestRequest("/login/", Method.POST);
loginRequest.AddHeader("postman-token", "4e67ed4c-4130-4067-9539-d5ed6b6ad761");
loginRequest.AddHeader("cache-control", "no-cache");
loginRequest.AddHeader("content-type", "application/json");
loginRequest.AddParameter("application/json", "{\r\n\"username\" : \"someusername\" ,\r\n\"password\" : \"somepassword\" ,\r\n\"portfolioID\" : \"someportfolioid\"\r\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(loginRequest);
client.ExecuteAsync(loginRequest, x =>
{
var json = x.Content;
});
Console.ReadLine();
}
}
public class LoginStatus
{
public Status status { get; set; }
public string cookie { get; set; }
public string permissions { get; set; }
public string canActivate { get; set; }
}
public class Status
{
public string errorCode { get; set; }
public string errorMessage { get; set; }
public string status { get; set; }
}
}
I receive the following JSON response:
{
"status": {
"errorCode": "",
"errorMessage": "",
"status": "OK"
},
"cookie": "2p255ju6q1lfql594uppnq9lp2",
"permissions": "ULE",
"canActivate": "yes"
}
So I created a class that will handle all the response parameters in the JSON object. I'm just not sure how exactly to access status
.