我正在使用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
字段相关的信息。
输入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"
}
}
}
输入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
,如上所示,但这是否可能是我遗漏了某些东西?
答案 0 :(得分:2)
该错误可能是由于您混合了多种选择记录以更新记录的事实。
您使用以下两种方式:
请考虑只使用其中一种方法。