0
votes

I'm trying to update some properties of contact entity in Dynamics CRM 365.

I'm using the Web API and send my updates to :

http://<URI>/api/data/v8.0/contacts(a29d23c0-f75a-e611-80c4-0050568deb29)

For example :

Headers :

content-type: application/json
accept: application/json
OData-MaxVersion: 4.0
OData-Version: 4.0
Authorization: 'the token'

Body:
    {
     "address1_city": "new city",
     "address1_country": "new country",
    }

However when I perform this request, I receive:

{"error":{"code":"0x0","message":"Object reference not set to an instance of an object.","innererror":{"message":"Object reference not set to an instance of an object.","type":"System.NullReferenceException","stacktrace":" at Microsoft.Crm.Extensibility.OData.CrmODataUtilities.ValidatePatchInputProperties(EdmEntityObject entityDelta, CrmODataExecutionContext crmODataExecutionContext)\r\n at Microsoft.Crm.Extensibility.OData.EntityController.PatchEntityImplementation(String& entityName, String key, EdmEntityObject entityDelta)\r\n at Microsoft.PowerApps.CoreFramework.ActivityLoggerExtensions.Execute[TResult](ILogger logger, EventId eventId, ActivityType activityType, Func`1 func, IEnumerable`1 additionalCustomProperties)\r\n at Microsoft.Xrm.Telemetry.XrmTelemetryExtensions.Execute[TResult](ILogger logger, XrmTelemetryActivityType activityType, Func`1 func)\r\n at lambda_method(Closure , Object , Object[] )\r\n at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor.<>c__DisplayClass10.b__9(Object instance, Object[] methodParameters)\r\n at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ExecuteAsync(HttpControllerContext controllerContext, IDictionary`2 arguments, CancellationToken cancellationToken)\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Web.Http.Controllers.ApiControllerActionInvoker.d__0.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Web.Http.Controllers.ActionFilterResult.d__2.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Web.Http.Dispatcher.HttpControllerDispatcher.d__1.MoveNext()"}}}

1

1 Answers

1
votes

Here's a working sample in powershell. My headers are a bit different and I'm using the endpoint on v8.2:

$headers = @{
"Content-Type"="application/json; charset=utf-8";
"OData-MaxVersion"="4.0";
"OData-Version"="4.0";
};

$body = @{
    "address1_city"="new city";
    "address1_country"="new country";
};

$json = ConvertTo-Json $body;

$result = Invoke-WebRequest -Uri "$serverurl/api/data/v8.2/contacts(66B652BF-06AB-E811-80EE-005056935BD6)" -Method PATCH -Headers $headers -Body $json -UseDefaultCredentials;

Write-Host $result.StatusCode;