我正在尝试更新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",
}
但是,当我执行此请求时,会收到:
{“错误”:{“代码”:“ 0x0”,“消息”:“对象引用未设置为对象的实例。”,“ innererror”:{“消息”:“对象引用未设置为一个对象的实例。“,”类型“:” System.NullReferenceException“,” stacktrace“:”在Microsoft.Crm.Extibility.OData.CrmODataUtilities.ValidatePatchInputProperties(EdmEntityObjectentityDelta,CrmODataExecutionContext crmODataExecutionContext)\ r \ n在Microsoft.Crm .Extensibility.OData.EntityController.PatchEntityImplementation(String&entityName,String key,EdmEntityObjectEntityDelta)\ r \ n在Microsoft.PowerApps.CoreFramework.ActivityLoggerExtensions.Execute [TResult](ILogger记录器,EventId eventId,ActivityType activityType,Func`1 func, IEnumerable`1 AdditionalCustomProperties)\ r \ n在Microsoft.Xrm.Telemetry.XrmTelemetryExtensions.Execute [TResult](ILogger记录器,XrmTelemetryActivityType activityType,Func`1 func)\ r \ n在lambda_method(Closure,Object,Object [])\ r \ n位于System.Web.Http.Controllers.ReflectedHttpActionDescriptor。 ActionExecutor。<> c__DisplayClass10.b__9(Object instance,Object [] methodParameters)\ r \ n在System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ExecuteAsync(HttpControllerContext controllerContext,IDictionary`2自变量,CancellationToken cancelledToken)\ r \ n-- -从之前引发异常的位置开始的堆栈结束跟踪--- \ r \ n在System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\ r \ n在System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务任务)\ r \ n在System.Web.Http.Controllers.ApiControllerActionInvoker.d__0.MoveNext()\ r \ n ---从上一个引发异常的位置开始的堆栈跟踪--- \ r \ n在System.Runtime.ExceptionServices .ExceptionDispatchInfo.Throw()\ r \ n在System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务任务)\ r \ n在System.Web.Http.Controllers.ActionFilterResult.d__2.MoveNext()\ r \ n-- -从发生异常的先前位置结束的堆栈跟踪在System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\ r \ n被抛出--- \ r \ n在System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)被抛出.HttpControllerDispatcher.d__1.MoveNext()“}}}
答案 0 :(得分:1)
这是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;