我正在尝试更新Dynamics CRM 365中联系人实体的某些属性。
我正在使用 Web API 并将更新发送到:
http://<URI>/api/data/v8.0/contacts(a29d23c0-f75a-e611-80c4-0050568deb29)
例如:
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",
}
但是,当我执行此请求时,我收到:
{">error":{"code":"0x0","message":"对象引用未设置为对象的实例。","innererror":{"message":"对象引用未设置为对象的实例.","type":"System.NullReferenceException","stacktrace":" at Microsoft.Crm.Extensibility.OData.CrmODataUtilities.ValidatePatchInputProperties(EdmEntityObject entityDelta, CrmODataExecutionContext crmODataExecutionContext(\r at Microsoft.Crm.Extensibility.OData.EntityController.PatchEntityImplementation(String& entityName, String key, EdmEntityObject entityDelta(\r at Microsoft.PowerApps.CoreFramework.ActivityLoggerExtensions.Execute[TResult](ILogger logger, EventId eventId, ActivityType activityType, Func'1 func, IEnumerable'1 additionalCustomProperties(\r at Microsoft.Xrm.Telemetry.XrmTelemetryExtensions.Execute[TResult](ILogger logger, XrmTelemetryActivityType activityType, Func'1 func(\r at lambda_method(Closure , Object , Object[] (\r at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor.<>c__DisplayClass10.b__9(Object instance, Object[] methodParameters(\r at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ExecuteAsync(HttpControllerContext controllerContext, IDictionary'2 arguments, CancelToken cancelToken(\r--- 从引发异常的先前位置的堆栈跟踪结束 ---\r atSystem.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw((\r at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task(\r at System.Web.Http.Controllers.ApiControllerActionInvoker.d__0.MoveNext((\r--- 从引发异常的先前位置的堆栈跟踪结束 ---\r at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw((\r atSystem.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task(\r at System.Web.Http.Controllers.ActionFilterResult.d__2.MoveNext((\r--- 从引发异常的先前位置的堆栈跟踪结束 ---\r at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw((\r at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task(\r atSystem.Web.Http.Dispatcher.HttpControllerDispatcher.d__1.MoveNext(("}}}
这是Powershell中的一个工作示例。我的标头有点不同,我在 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;