使用REST API更新客户会导致500内部服务器错误

问题描述 投票:0回答:1

我正在使用PHPGuzzle 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字段'相关的内容。

This request returns the 500 Internal Server Error:

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"
      }
   }
}

This request returns a 200 Success Response:

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,但可能是因为我可能遗漏了某些东西?

rest api acumatica guzzle
1个回答
2
投票

该错误可能是由于您正在混合多种方式来选择记录以进行更新。

您正在使用以下两种方式:

  • URL中的Filter参数
  • 记录正文中的Key字段

请考虑仅使用这些方法之一。

© www.soinside.com 2019 - 2024. All rights reserved.