Skip to main content

Notifications

Announcements

No record found.

Service | Customer Service, Contact Center, Fie...
Suggested answer

Creating Incident From WEB API via API in C#

(0) ShareShare
ReportReport
Posted on by 1,415

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

  • Suggested answer
    Denny Deng Profile Picture
    Denny Deng on at
    RE: Creating Incident From WEB API via API in C#

    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.

    docs.microsoft.com/.../create-entity-web-api

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Verified Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,431 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,503 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans