I am trying to send JSON data to a REST API using my C# application
The JSON data should be like that:
{
'agent': {
'name': 'AgentHere',
'version': 1
},
'username': 'Auth',
'password': 'Auth'
}
So, as you can see... agent have sub payloads which are name and version
I am calling the REST API using RestSharp like that:
var client = new RestClient("https://example.com");
// client.Authenticator = new HttpBasicAuthenticator(username, password);
var request = new RestRequest(Method.POST);
request.AddParameter(
"{'agent': { 'name': 'AgentHere', 'version': 1 }, 'username': 'Auth', 'password': 'Auth' }"
);
// easily add HTTP Headers
request.AddHeader("Content-Type", "application/json");
// execute the request
IRestResponse response = client.Execute(request);
var content = response.Content; // raw content as string
But I get the errors The best overloaded method match for 'RestSharp.RestRequest.AddParameter(RestSharp.Parameter)' has some invalid arguments and Argument 1: cannot convert from 'string' to 'RestSharp.Parameter' on this line:
request.AddParameter(
"{'agent': { 'name': 'AgentHere', 'version': 1 }, 'username': 'Auth', 'password': 'Auth' }"
);
I am unable to make the sub payload
Any help would be appreciated.
Thanks!