Skip to main content

Notifications

Customer Service forum
Suggested answer

Creating Incident From WEB API via API in C#

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

November Spotlight Star - Khushbu Rajvi

Congratulations to a top community star!

Forum Structure Changes Coming on 11/8!

In our never-ending quest to help the Dynamics 365 Community members get answers faster …

Dynamics 365 Community Platform update – Oct 28

Welcome to the next edition of the Community Platform Update. This is a status …

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 290,818 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 229,147 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans