I need to consume an endpoint that has JSON array of objects as the request structure. I have already tested it on a rest client. The problem is I am unable to form the request body in restsharp.
Below is the JSON structure
[
{
"id": "1",
"name": "rejected",
"timestamp": "2021-10-07T16:47:37Z",
"identity": "MainId",
"source": "web",
"params": {
"email": "[email protected]",
"fullName": "John Doe",
"Mobile": "444586867857"
}
}
]
I have also created the POCO class
public class activityClass
{
public Class1[] Property1 { get; set; }
}
public class Class1
{
public string id { get; set; }
public string name { get; set; }
public DateTime timestamp { get; set; }
public string identity { get; set; }
public string source { get; set; }
public Params _params { get; set; }
}
public class Params
{
public string email { get; set; }
public string fullName { get; set; }
public string Mobile { get; set; }
}
There is the code to call the endpoint
var client = new RestClient("http://api.tech.com/apiv2");
var request = new RestRequest(Method.POST);
//ThIS IS WHERE THE PROBLEM IS
var body = new activityClass
{
Class1 = new List<Class1>
{
}
}
var json = request.JsonSerializer.Serialize(body);
request.AddParameter("application/json", json, ParameterType.RequestBody);
IRestResponse response = client.Execute(request);