I want to Post some data to web API using rest api. Json schema is:
{
"contact":
{
"id":123,
"first_name":"Jimmy",
"last_name":"Dee",
"account_id":123,
"owned_by":123,
"email_addresses":[
{
"id":123,
}
],
"phone_numbers":[
{
"id":123,
"number":"123-123-1234",
"phone_number_type":"Main", "extension":"ex 5"
}]
}
}
My code is:
// Endpoint: POST /v1/contacts.json?contact={contact parameters}
{
Authenticator = OAuth1Authenticator.ForProtectedResource(consumerKey, consumerSecret, null, null)
};
var contact = new
{
first_name = "Foo",
last_name = "foo",
account_id = 15998446,
owned_by = 175177,
phone_numbers = new[] { new { number = "1234567887" } },
};
var request = new RestRequest("?contact=", Method.POST);
request.AddJsonBody(contact);
RestResponse response = (RestResponse)client.Execute(request);
When I run this code the contact is created but have nested array as Null, response content with status code of 200 is:
{
"contact":
{
"id":21152554,
"first_name":"Foo",
"last_name":"foo",
"account_id":15998446,
"owned_by":175177,
"email_addresses":[
{
"id":21692948,
"address":""
}],
"phone_numbers":[
{
"id":39428416,
"number":null,
}
]
}
}
Problem is the nested arrays email_addresses and phone_number have null values in address and number. Kindly help me where I'm making mistakes.