I am doing a HTTP call like so:
[HttpGet]
public HttpResponseMessage updateRegistrant(string token, string registrantId, string firstname, string lastname, string postalCode, string phoneNumber, string city, string email)
{
using (HttpClient httpClient = new HttpClient())
{
httpClient.BaseAddress = new Uri("https://api.example.com/v1/registrants/" + registrantId + "/");
httpClient.DefaultRequestHeaders.Accept.Clear();
httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);
HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Put, "person/contact-information");
request.Content = new StringContent("{\"firstName\":\"" + firstname + "\", \"lastName\":\"" + lastname + "\", \"phones\":[{\"phone\":\"" + phoneNumber + "\", \"type\":\"Home\", \"primary\":true}], \"emails\":[{\"email\":\"" + email + "\", \"type\":\"Personal\", \"primary\":true}], \"addresses\":[{\"city\":\"" + city + "\", \"zipCode\":\"" + postalCode + "\"}]}", Encoding.UTF8, "application/json");
//request.Content = new StringContent("{\"firstName\":\"" + firstname + "\", \"lastName\":\"" + lastname + "\"}", Encoding.UTF8, "application/json");
HttpResponseMessage response = httpClient.SendAsync(request).Result;
return response;
}
}
Now when I run this method, I get 409 Error call, however if I comment out the first request.Content and uncomment the second request.Content it works, I get response code of 200.
I would assume that these are causing the 409 error:
\"phones\":[{\"phone\":\"" + phoneNumber + "\", \"type\":\"Home\", \"primary\":true}]
But why and how do I fix this?