web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Customer experience | Sales, Customer Insights,...
Answered

Consuming CRM Web Api in Rest Web Api

(0) ShareShare
ReportReport
Posted on by 35

I am trying to Create Record in Account using Web Api.

Issue is Im getting 400  bad request if Iam using it from FROMBODY

This is my request given in postman

{
    "name": "DemoWebApi1" ,
    "emailaddress1": "kondurianil555@gmail.com" 
    
}

This is my Post method

[HttpPost]
[Route("api/account/post")]
public async Task<string> Post([FromBody]Account account)
{
try
{
string accessToken = authenticateAsync();
HttpClient httpClient = new HttpClient();
//Default Request Headers needed to be added in the HttpClient Object
httpClient.DefaultRequestHeaders.Add("OData-MaxVersion", "4.0");
httpClient.DefaultRequestHeaders.Add("OData-Version", "4.0");
httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

//Set the Authorization header with the Access Token received specifying the Credentials
httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", accessToken);

httpClient.BaseAddress = new Uri(webApiUrl);

HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Post, "accounts")
{
Content = new StringContent(JsonConvert.SerializeObject(account), Encoding.UTF8, "application/json")
};

using (HttpResponseMessage response = await httpClient.SendAsync(request))
{
if (response.IsSuccessStatusCode) //204
{
var entityUri = response.Headers.GetValues("OData-EntityId").FirstOrDefault();
return entityUri;
}
}
return string.Empty;
}
catch (Exception e)
{

throw e;
}

I have the same question (0)
  • Verified answer
    mobeenmohsin Profile Picture
    on at

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
Tom_Gioielli Profile Picture

Tom_Gioielli 108 Super User 2025 Season 2

#2
Jimmy Passeti Profile Picture

Jimmy Passeti 50 Most Valuable Professional

#3
Gerardo Rentería García Profile Picture

Gerardo Rentería Ga... 49 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans