I am trying to create a case in c# via web api & I am able to create contacts and other entities records so authentication is not an issue.
I am using below code and getting bad request 400 not sure why. Please advice.
JObject caseObj = new JObject();
caseObj.Add("customerid_contact@odata.bind", "/contacts(164a650d-06b3-ea11-a812-000d3af0247a)");
caseObj.Add("title", "New Case");
var accessToken = await GetAccessToken();
var client = new HttpClient();
var message = new HttpRequestMessage(HttpMethod.Post, orgUrl + "https://abc.api.crm8.dynamics.com/api/data/v9.1/" + "incidents" );
message.Headers.Add("OData-MaxVersion", "4.0");
message.Headers.Add("OData-Version", "4.0");
message.Headers.Add("Prefer", "odata.include-annotations=*");
message.Headers.Authorization = new AuthenticationHeaderValue("Bearer", accessToken);
message.Content = new StringContent(caseObj.ToString(), UnicodeEncoding.UTF8, "application/json");
// Send the message to the WebAPI.
var response = await client.SendAsync(message);
In response getting bad request 400.
Thanks,
Deepak
please check if 'customerid_contact' is collection-valued navigation property
Associating entities this way using a collection-valued (1:N or N:N) navigation property is not supported by the Web API.
Stay up to date on forum activity by subscribing. You can also customize your in-app and email Notification settings across all subscriptions.
André Arnaud de Cal... 290,818 Super User 2024 Season 2
Martin Dráb 229,147 Most Valuable Professional
nmaenpaa 101,156