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,...
Suggested Answer

How to CRUD contact using Odata API?

(0) ShareShare
ReportReport
Posted on by 10

Hi,

I go with this link for update the entities with API, 

https://docs.microsoft.com/en-us/powerapps/developer/common-data-service/webapi/update-delete-entities-using-web-api

the sample works well, with account changed, 

however , if I apply the same to contacts, like 

change the uri to 

PATCH [Organization URI]/api/data/v9.1/contacts(00000000-0000-0000-0000-000000000001) HTTP/1.1

and content

{ "Firstname": "Updated first name " }

I get error 

 "code""0x0",
        "message""An error occurred while validating input parameters: Microsoft.OData.ODataException: Does not support untyped value in non-open type.\r\n   at System.Web.OData.Formatter.Deserialization.DeserializationHelpers.ApplyProperty(ODataProperty property, IEdmStructuredTypeReference resourceType, Object resource, ODataDeserializerProvider deserializerProvider, ODataDeserializerContext readContext)\r\n   at System.Web.OData.Formatter.Deserialization.ODataResourceDeserializer.ApplyStructuralProperties(Object resource, ODataResourceWrapper resourceWrapper, IEdmStructuredTypeReference structuredType, ODataDeserializerContext readContext)\r\n   at Microsoft.Crm.Extensibility.CrmODataEntityDeserializer.ApplyStructuralProperties(Object resource, ODataResourceWrapper resourceWrapper, IEdmStructuredTypeReference structuredType, ODataDeserializerContext readContext)\r\n   at System.Web.OData.Formatter.Deserialization.ODataResourceDeserializer.ReadResource(ODataResourceWrapper resourceWrapper, IEdmStructuredTypeReference structuredType, ODataDeserializerContext readContext)\r\n   at System.Web.OData.Formatter.ODataMediaTypeFormatter.ReadFromStream(Type type, Stream readStream, HttpContent content, IFormatterLogger formatterLogger)",
        
I then tried to get the first contact, serialized to Json, and replace the content with full contact, detail and I still get the error.
what is the special setting with Contact? and can I create/update using api?
Thanks for any help!
Gordon
I have the same question (0)
  • cloflyMao Profile Picture
    25,210 on at

    Hi Gordon,

    Firstname should be firstname, please pay attention to letter case of fields.

    A full code for update a contact:

    var entity = {
      "firstname": "Mike 1",
      "lastname": "Johnson"
    };
    
    var req = new XMLHttpRequest();
    req.open("PATCH", Xrm.Page.context.getClientUrl()   "/api/data/v9.1/contacts(xxxx)", true);
    req.setRequestHeader("OData-MaxVersion", "4.0");
    req.setRequestHeader("OData-Version", "4.0");
    req.setRequestHeader("Accept", "application/json");
    req.setRequestHeader("Content-Type", "application/json; charset=utf-8");
    req.onreadystatechange = function() {
        if (this.readyState === 4) {
            req.onreadystatechange = null;
            if (this.status === 204) {
                alert("ok");
            } else {
                Xrm.Utility.alertDialog(this.statusText);
            }
        }
    };
    req.send(JSON.stringify(entity));

    In addition, you could automatically create create/update with Web API by CRM Rest Builder.

    It supports for all CRUD operations.

    https://github.com/jlattimer/CRMRESTBuilder

    Regards,

    Clofly

  • Suggested answer
    gordon li Profile Picture
    10 on at

    Thanks Clofly,

    It works by change the Firstname to firstname,

    I am using the postman .

  • cloflyMao Profile Picture
    25,210 on at

    Hi gordon,

    Please let me know whether you had other problem.

    If you had found any answer helped, please kindly mark as verified, it would be greatly appreciated.

    Regards,

    Clofly

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