Skip to main content

I’m trying to update an existing stock item record using a PUT request:

 

but I’m getting the following "Object reference not set to an instance of an object." 500 error from the server. Why is this happening? I can retrieve the record just fine using a GET request.

{
"message": "An error has occurred.",
"exceptionMessage": "Operation failed",
"exceptionType": "PX.Data.PXInvalidOperationException",
"stackTrace": " at PX.Api.ContractBased.EntityService.Put(ISystemContract systemContract, String version, String name, EntityImpl entity, CbOperationContext operationContext, Boolean throwOnError)\r\n at PX.Api.ContractBased.Soap.SoapFacadeBase.PutImpl(EntityImpl entity, Boolean throwOnValidationError)\r\n at PX.Api.ContractBased.SystemContracts.V2.RestController.PutEntity(EntityImpl entity, String select, String filter, String expand, String custom)\r\n at lambda_method(Closure , Object , ObjectO] )\r\n at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor.<>c__DisplayClass6_2.<GetExecutor>b__2(Object instance, ObjectO] methodParameters)\r\n at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ExecuteAsync(HttpControllerContext controllerContext, IDictionary`2 arguments, CancellationToken cancellationToken)\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Web.Http.Controllers.ApiControllerActionInvoker.<InvokeActionAsyncCore>d__1.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Web.Http.Filters.ActionFilterAttribute.<CallOnActionExecutedAsync>d__6.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n at System.Web.Http.Filters.ActionFilterAttribute.<CallOnActionExecutedAsync>d__6.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Web.Http.Filters.ActionFilterAttribute.<ExecuteActionFilterAsyncCore>d__5.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Web.Http.Filters.ActionFilterAttribute.<CallOnActionExecutedAsync>d__6.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n at System.Web.Http.Filters.ActionFilterAttribute.<CallOnActionExecutedAsync>d__6.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Web.Http.Filters.ActionFilterAttribute.<ExecuteActionFilterAsyncCore>d__5.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Web.Http.Controllers.ActionFilterResult.<ExecuteAsync>d__5.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Web.Http.Filters.AuthorizationFilterAttribute.<ExecuteAuthorizationFilterAsyncCore>d__3.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Web.Http.Controllers.ExceptionFilterResult.<ExecuteAsync>d__6.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n at System.Web.Http.Controllers.ExceptionFilterResult.<ExecuteAsync>d__6.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Web.Http.Dispatcher.HttpControllerDispatcher.<SendAsync>d__15.MoveNext()",
"innerException": {
"message": "An error has occurred.",
"exceptionMessage": "Object reference not set to an instance of an object.",
"exceptionType": "System.NullReferenceException",
"stackTrace": " at KN.CP.KNCPInventoryItemMaintExt.InventoryItem_RowSelected(PXCache cache, PXRowSelectedEventArgs e, PXRowSelected BaseSelectedevent)\r\n at KN.DistrictCameras.KNDCInventoryItemMaintBaseExt.InventoryItem_RowSelected(PXCache cache, PXRowSelectedEventArgs e, PXRowSelected BaseEvent)\r\n at KN.S3Images.KNCPInventoryItemMaintS3Ext.InventoryItem_RowSelected(PXCache cache, PXRowSelectedEventArgs e, PXRowSelected BaseSelectedevent)\r\n at KNCommerceBasic.KNCBInventoryItemMaintExt.InventoryItem_RowSelected(PXCache cache, PXRowSelectedEventArgs e, PXRowSelected BaseEvent)\r\n at KNMagentoConnector.KNMCInventoryItemMaintExtn.InventoryItem_RowSelected(PXCache cache, PXRowSelectedEventArgs e, PXRowSelected BaseEvent)\r\n at PX.Data.PXRowSelected.Invoke(PXCache sender, PXRowSelectedEventArgs e)\r\n at PX.Data.PXCache.OnRowSelected(Object item)\r\n at PX.Api.SyImportProcessor.SyStep.CommitChangesInt(Object itemToBypass, PXFilterRowt] targetConditions, PXFilterRowt] filtersForAction, SyImportRowResult importResult)\r\n at PX.Api.SyImportProcessor.SyStep.CommitChanges(Object& itemToBypass, PXFilterRowt] targetConditions, PXFilterRowt] filtersForAction)\r\n at PX.Api.SyImportProcessor.ExportTableHelper.ExportTable()"
}
}

 

@pmblake 

You cant use filter with PUT.

You would need to pass inventoryID in body to update that stock item. See below:

Before
Postman update with inventoryID in body
Updated description using API

 


@pmblake

You cant use filter with PUT.

You would need to pass inventoryID in body to update that stock item. See below:

Before
Postman update with inventoryID in body
Updated description using API

 

 

Hi Rohit, I changed the request the following and I’m still getting the same error:

 


@pmblake 

Are you able to GET that inventory using POSTMAN?

Also, maybe try changing description it in the UI just to confirm/compare behavior with API?


@RohitRattan88 yes, that’s the weird part. I can GET the inventory ID record just fine, and change the title via UI as well:

 

Very confused as to why the PUT is not working

 

 


This ended up being a problem with a customization which was causing issues with the InventoryMaintenance. Thanks for your help @RohitRattan88 


Thank you for sharing your solution with the community @pmblake !


This ended up being a problem with a customization which was causing issues with the InventoryMaintenance. Thanks for your help @RohitRattan88 

@pmblake  glad you were able to figure it out


Reply