使用 REST API 更新客户导致 500 内部服务器错误
Updating Customer with REST API results in 500 Internal Server Error
我正在使用 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()
对于添加 entire 堆栈跟踪,我深表歉意,但我认为这可能会有所帮助。
起初,我认为它可能与请求的 URL 有关,但在查看类似问题的 this 答案后,它似乎与以下内容无关在 URL?
中传递的参数
我已经通过从请求正文中删除 CustomerID
找到了 'solution/workaround',但是为了使请求正常工作需要这样做似乎有点奇怪?
我查看了 documentation for updating a record,但没有看到任何与 'remove the key
field when using the filter
parameter in the request URL' 有关的内容。
此请求returns 500 内部服务器错误:
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"
}
}
}
此请求 returns 200 成功响应:
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
,如上所示,但我可能遗漏了什么吗?
错误可能是由于您混合了多种选择记录的方式来更新它。
您正在使用以下两种方式:
- URL
中的过滤器参数
- 记录正文中的Key字段
请考虑只使用其中一种方法。
我正在使用 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()
对于添加 entire 堆栈跟踪,我深表歉意,但我认为这可能会有所帮助。
起初,我认为它可能与请求的 URL 有关,但在查看类似问题的 this 答案后,它似乎与以下内容无关在 URL?
中传递的参数我已经通过从请求正文中删除 CustomerID
找到了 'solution/workaround',但是为了使请求正常工作需要这样做似乎有点奇怪?
我查看了 documentation for updating a record,但没有看到任何与 'remove the key
field when using the filter
parameter in the request URL' 有关的内容。
此请求returns 500 内部服务器错误:
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"
}
}
}
此请求 returns 200 成功响应:
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
,如上所示,但我可能遗漏了什么吗?
错误可能是由于您混合了多种选择记录的方式来更新它。
您正在使用以下两种方式:
- URL 中的过滤器参数
- 记录正文中的Key字段
请考虑只使用其中一种方法。