我正在使用PHP
和Guzzle 6
通过基于合同的REST API更新AR客户记录,并获得500 Internal Server Error
回复。
响应中的错误消息是:
{
"message": "An error has occurred.",
"exceptionMessage": "Unable to cast object of type 'PX.Api.ContractBased.Models.EntityValueField' to type 'PX.Api.ContractBased.Models.EntitySearchField'.",
"exceptionType": "System.InvalidCastException",
"stackTrace": "... see below ..."
}
堆栈跟踪:
at PX.Api.ContractBased.OData.FilterVisitor.SetNullableCondition(BinaryOperatorNode nodeIn, String nullCondition, String regularCondition)
at PX.Api.ContractBased.OData.FilterVisitor.VisitRoot(SingleValueNode root)
at PX.Api.ContractBased.OData.Helpers.FillRestQueryOptions(IEdmModel edmModel, EntityImpl entity, String filter, String select, String expand, String custom)
at lambda_method(Closure , Object , Object[] )
at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor.<>c__DisplayClass10.<GetExecutor>b__9(Object instance, Object[] methodParameters)
at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ExecuteAsync(HttpControllerContext controllerContext, IDictionary`2 arguments, CancellationToken cancellationToken)
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Web.Http.Controllers.ApiControllerActionInvoker.<InvokeActionAsyncCore>d__0.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Web.Http.Filters.ActionFilterAttribute.<CallOnActionExecutedAsync>d__5.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Web.Http.Filters.ActionFilterAttribute.<CallOnActionExecutedAsync>d__5.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Web.Http.Filters.ActionFilterAttribute.<ExecuteActionFilterAsyncCore>d__0.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Web.Http.Filters.ActionFilterAttribute.<CallOnActionExecutedAsync>d__5.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Web.Http.Filters.ActionFilterAttribute.<CallOnActionExecutedAsync>d__5.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Web.Http.Filters.ActionFilterAttribute.<ExecuteActionFilterAsyncCore>d__0.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Web.Http.Controllers.ActionFilterResult.<ExecuteAsync>d__2.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Web.Http.Filters.AuthorizationFilterAttribute.<ExecuteAuthorizationFilterAsyncCore>d__2.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Web.Http.Controllers.ExceptionFilterResult.<ExecuteAsync>d__0.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Web.Http.Controllers.ExceptionFilterResult.<ExecuteAsync>d__0.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Web.Http.Dispatcher.HttpControllerDispatcher.<SendAsync>d__1.MoveNext()
我最诚挚地为添加整个堆栈跟踪道歉,但我认为它可能会有所帮助。
起初,我认为它可能与请求的URL有关,但在查看this从类似问题回答后,它似乎与URL中传递的参数无关?
我已经通过从请求体中删除CustomerID
找到了“解决方案/解决方法”,但为了使请求正常工作,需要这样做有点奇怪?
我查看了documentation for updating a record,但没有看到任何与'在请求URL中使用key
参数时删除filter
字段'相关的内容。
PUT entity/Default/18.200.001/Customer?$filter=CustomerID%20eq%20%27100000044%27&$select=CustomerID
{
"CustomerClass": {
"value": "CUSTOMER_CLASS"
},
"CustomerID": {
"value": "100000044"
},
"CustomerName": {
"value": "Christiaan Raubenheimer"
},
"MainContact": {
"Address": {
"AddressLine1": {
"value": "Street Line 1"
},
"AddressLine2": {
"value": "Stree Line 2"
},
"City": {
"value": "City"
},
"Country": {
"value": "ZA"
},
"PostalCode": {
"value": "0000"
},
"State": {
"value": "State"
}
},
"Attention": {
"value": "Christiaan Raubenheimer"
},
"DisplayName": {
"value": "Company Name"
},
"Email": {
"value": "...email address..."
},
"JobTitle": {
"value": "Company Name"
},
"Phone1": {
"value": "0000000000"
}
}
}
PUT entity/Default/18.200.001/Customer?$filter=CustomerID%20eq%20%27100000044%27&$select=CustomerID
{
"CustomerClass": {
"value": "CUSTOMER_CLASS"
},
"CustomerName": {
"value": "Christiaan Raubenheimer"
},
"MainContact": {
"Address": {
"AddressLine1": {
"value": "Street Line 1"
},
"AddressLine2": {
"value": "Stree Line 2"
},
"City": {
"value": "City"
},
"Country": {
"value": "ZA"
},
"PostalCode": {
"value": "0000"
},
"State": {
"value": "State"
}
},
"Attention": {
"value": "Christiaan Raubenheimer"
},
"DisplayName": {
"value": "Company Name"
},
"Email": {
"value": "...email address..."
},
"JobTitle": {
"value": "Company Name"
},
"Phone1": {
"value": "0000000000"
}
}
}
总之,如上所示,看起来需要从请求体中删除CustomerID
,但可能是因为我可能遗漏了某些东西?
该错误可能是由于您正在混合多种方式来选择记录以进行更新。
您正在使用以下两种方式:
请考虑仅使用这些方法之一。