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 :
Microsoft Dynamics CRM (Archived)

Dynamics CRM Web API POST Products 'Internal Server Error'

(0) ShareShare
ReportReport
Posted on by

Hi,

I've working on a C#.net desktop application to create a products in CRM but when I post my request my response message IsSuccessStatusCode returns false and ReasonPhrase value is "Internal Server Error".

requestUri = https://xxxxxx.xxxxxx.com/api/data/v8.2/products

Content = { "description": "Desc12345", "productnumber": "12345", "name": "Name12345" }

This is for an on-prem. version of CRM and my code to patch/update existing product values all works fine, so I have to assume the Uri isn't the issue.

I've tried including other fields in my content on the assumption that there could be a mandatory value I need to populate but even when I set values to match other products the error still appears.

Can anyone give me suggestions on how I can dig deeper to find details of the error?

Thanks

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    gdas Profile Picture
    50,091 Moderator on at

    Hi Jim ,

    Could you please share your code. Meanwhile you can also validate your code with below reference. The internal server error is basically coming when request is not hitting to the server which you want.

    www.inogic.com/.../programming-using-webapi-through-c-in-dynamics-crm-2016

    You can download fiddler to see where it's actually fails.

    Hope this helps.

  • Verified answer
    a33ik Profile Picture
    84,331 Most Valuable Professional on at

    Hello Jim,

    You will need to pass defaultuomid, defauluomscheduleid and quantitydecimal fields as well because all of those fields are "platform required".

  • Community Member Profile Picture
    on at

    Here's my code:

    string thisRequest = _BaseAddress + _APIDataVersion + "products";

    using (System.Net.Http.HttpRequestMessage thisHttpRequestMessage = new System.Net.Http.HttpRequestMessage(System.Net.Http.HttpMethod.Post, thisRequest))

    {

       JObject newProduct = new JObject();

       newProduct.Add("description",ProductDescription);

       newProduct.Add("productnumber",ProductNumber);

       newProduct.Add("name",ProductName);

       thisHttpRequestMessage.Content = new System.Net.Http.StringContent(newProduct.ToString());

       thisHttpRequestMessage.Content.Headers.ContentType = System.Net.Http.Headers.MediaTypeHeaderValue.Parse("application/json");

       System.Net.Http.HttpResponseMessage thisResponse = httpClient.SendAsync(thisHttpRequestMessage).Result;

       if (thisResponse.IsSuccessStatusCode == false)

       {

           throw new Exception("Error " + thisResponse.ReasonPhrase);

       }

    }

  • Community Member Profile Picture
    on at

    I tried adding those fields (as below) after seeing your response to a similar query but it didn't stop the error occurring.

    newProduct.Add("defaultuomscheduleid@odata.bind", "/uomschedules(4560d506-eee2-4cf8-a8d2-3e189ffd5572)");

    newProduct.Add("defaultuomid@odata.bind", "/uoms(bfd3f507-1532-48c1-a35b-d0da82d4f477)");

    newProduct.Add("quantitydecimal", 1);

  • Community Member Profile Picture
    on at

    Goutam/Andrew,

    Thanks for your advise but believe it or not it's now started working.  I've been trying to fix the problem for hours and now it looks like it's posting, typical!.

    Cheers

    Jim

  • Suggested answer
    a33ik Profile Picture
    84,331 Most Valuable Professional on at

    For me it was enough. Can you please doublecheck that you don't have product with the same productnumber in the system?

  • Community Member Profile Picture
    on at

    I've just re-checked and I don't (and didn't) have any duplicates, in-fact the CRM database had only a few products in there.

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 > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans