Skip to main content
Solved

How to invoke AR Document (AR Payment) Delete via api Action

  • April 21, 2025
  • 6 replies
  • 88 views

I have a scenario where I need to programmatically invoke the delete action on AR Documents in specific scenarios. however, I am not finding the correct action to invoke in the api.

I have verified this AR Document exists, is in status ‘Balanced’, and the Delete action is available from the UI.

POST <host>/Payment/Delete
BODY {
  "entity": {
    "ReferenceNbr": {
      "value": "<refNum>"
    }
  }
}
RETURNS 204: No Content

What am I missing?

Best answer by Dmitrii Naumov

You need to provide the payment ID in the URL

Try replacing the Delete part of the URL by the ID

 entity/.../20.200.001/Payment/Delete

 

It should look like that:

 entity/.../20.200.001/Payment/e734ff7e-fadb-ea11-8177-c9aeb77cfe99

 

Alternatively you can use the Key field (doc type and ref nbr)

 entity/.../20.200.001/Payment/Payment/068371

 

You also do not need body at all here.

 

Here is the help article on the topic:

https://help.acumatica.com/(W(2))/Help?ScreenId=ShowWiki&pageid=04825ddc-c3af-49de-8663-ae119e84b987

 

 

 

6 replies

  • Author
  • Freshman II
  • April 21, 2025

I should point out that typically 204 is a success-ish status, but the AR document with the ref number is not removed. 

When I delete the AR Document from the UI, it is, of course, removed from the list of AR Documents.


Dmitrii Naumov
Acumatica Moderator
Forum|alt.badge.img+7
  • Acumatica Moderator
  • April 21, 2025

You need to use ‘DELETE’ type of request instead of ‘POST’


  • Author
  • Freshman II
  • April 21, 2025

Thank you. If there is something to read in the knowledge base on this, I will look through that. I’m not finding much on Deletes specifically. I think I am close. But it is reporting "Operation is not valid due to the current state of the object."

This is the current state of my payment in the UI. I could use the delete icon here. It does have a Document to Apply entry, if that is relevant.


The current state of my request.
DELETE entity/.../20.200.001/Payment/Delete
BODY {
  "entity": {
    "ReferenceNbr": {
      "value": "068371"
    }
  }
}
RESPONSE 500 

{

"message": "An error has occurred.",

"exceptionMessage": "Operation is not valid due to the current state of the object.",

"exceptionType": "System.InvalidOperationException",

"stackTrace": " at PX.Api.ContractBased.EntityService.FillEntityImplWithKeys(String version, String name, EntityImpl entity, String[] keys)\r\n at PX.Api.ContractBased.AspNetCore.CbEndpointFeatureServiceExtensions.FillEntityImplWithKeys(IEntityService entityService, ICbEndpointFeature feature, EntityImpl entity, String[] keys)\r\n at PX.Api.ContractBased.WebApi.Controllers.EntityController.CreateEntityFromKeys(String objectName, String idsString)\r\n at lambda_method(Closure , Object , Object[] )\r\n at Microsoft.AspNetCore.Mvc.Internal.ActionMethodExecutor.SyncActionResultExecutor.Execute(IActionResultTypeMapper mapper, ObjectMethodExecutor executor, Object controller, Object[] arguments)\r\n at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.<InvokeActionMethodAsync>d__12.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 Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.<InvokeNextActionFilterAsync>d__10.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 Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Rethrow(ActionExecutedContext context)\r\n at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)\r\n at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.<InvokeInnerFilterAsync>d__13.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 Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.<InvokeNextExceptionFilterAsync>d__24.MoveNext()"

}


What is this response trying to tell me? Do I need to handle the DocumentToApply separately, or $expand into it like I would with an InsertUpdate?  


  • Author
  • Freshman II
  • April 21, 2025

I’ve also tried a few variations on the theme

DELETE /Payment  
BODY {

  "entity": {

    "ReferenceNbr": {

      "value": "068371"

    }

  }

}
RESPONSE 500 "Object reference not set to an instance of an object.",



DELETE /Payment/068371 
BODY <EMPTY> and with same body used above.
RESPONSE 500 "Operation is not valid due to the current state of the object”


Dmitrii Naumov
Acumatica Moderator
Forum|alt.badge.img+7
  • Acumatica Moderator
  • Answer
  • April 21, 2025

You need to provide the payment ID in the URL

Try replacing the Delete part of the URL by the ID

 entity/.../20.200.001/Payment/Delete

 

It should look like that:

 entity/.../20.200.001/Payment/e734ff7e-fadb-ea11-8177-c9aeb77cfe99

 

Alternatively you can use the Key field (doc type and ref nbr)

 entity/.../20.200.001/Payment/Payment/068371

 

You also do not need body at all here.

 

Here is the help article on the topic:

https://help.acumatica.com/(W(2))/Help?ScreenId=ShowWiki&pageid=04825ddc-c3af-49de-8663-ae119e84b987

 

 

 


  • Author
  • Freshman II
  • April 21, 2025

Thank you. I finally tried.

DELETE /Payment/e734ff7e-fadb-ea11-8177-c9aeb77cfe99
BODY <empty>
RESPONSE 204

For whatever reason, only this variation actually removed the record from the system. Regardless, my issue is resolved, thank you once again for your time.