Consume Nimbuspost API in .Net using C#

ramco1917
 
on Dec 19, 2022 09:57 PM
416 Views

Hi

I want to generate token. I am consuming Nimbuspost Api. Below is the code i am tying

var client = new RestClient("https://api.nimbuspost.com/v1/users/login");
client.Timeout = -1;
var request = new RestRequest(Method.POST);
request.AddHeader("content-type", "application/json");
var body = @"{" + "\n" +
           @"    ""email"" : ""xyz@gmail.com""," + "\n" +
           @"    ""password"" : ""Temp234""" + "\n" +
           @"}";
request.AddParameter("application/json", body, ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
Console.WriteLine(response.Content);

In response it is returning -

{"status":true,"data":"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzUxMiJ9.eyJpYXQiOjE2NzE0NzIzNTksImp0aSI6Ilgwc3lCclRNYW43Z3BJN3NSYzNXNVBDbVNUTkF5M29FNDJEcENKVDFhR2s9IiwibmJmIjoxNjcxNDcyMzU5LCJleHAiOjE2NzE0ODMxNTksImRhdGEiOnsidXNlcl9pZCI6IjQ3MDYyIiwicGFyZW50X2lkIjoiMCJ9fQ.s4mOl1Oa24iiA1e-wTTsYGeLSBjARcDZWl1BkW10_Ej5aQzTGWXAlrBGjznEghQJa2rmZts6zy1igLPeGcAWUQ"}

Thanks

Download FREE API for Word, Excel and PDF in ASP.Net: Download
dharmendr
 
on Dec 20, 2022 09:48 PM

Hi ramco1917,

Refer below sample code.

C#

protected void Page_Load(object sender, EventArgs e)
{
    var client = new RestClient("https://api.nimbuspost.com/v1/users/login");
    client.Timeout = -1;
    var request = new RestRequest(Method.POST);
    request.AddHeader("content-type", "application/json");
    var body = @"{" + "\n" +
                @"    ""email"" : ""xyz@gmail.com""," + "\n" +
                @"    ""password"" : ""Temp234""" + "\n" +
                @"}";
    request.AddParameter("application/json", body, ParameterType.RequestBody);
    IRestResponse response = client.Execute(request);
    Root root = JsonConvert.DeserializeObject<Root>(response.Content);
    bool status = root.status;
    string token = root.data;
}

public class Root
{
    public bool status { get; set; }
    public string data { get; set; }
}