Skip to main content
Solved

Add line items to existing order via REST API

  • February 25, 2025
  • 4 replies
  • 61 views

I am trying to add line items to an existing order via the API.  I am able to create orders with line items via the API, but I have found that if the number of line items is too high, the process times-out/fails.

So I am attempting to create the order header, then loop through the line items and add them in batches of a certain # of lines (TBD, possibly 100).  My script is creating the order header no problem, but I can’t get it to add any line items.  

This is the error msg:

Specified argument was out of the range of valid values.\r\nParameter name: Invalid uri structure

This is the URL:  https://xyz.com/entity/Default/22.200.001/SalesOrder/1712261/Details

I then modified the URL to be: 

https://xyz.com/entity/Default/22.200.001/SalesOrder?$expand=Details&$select=OrderType,OrderNbr,Details/OrderQty,Details/InventoryID,OrderedQty,OrderTotal 

I do not get an error with this 2nd URL, but it just hangs.  My script hangs and I do not see activity in Acumatica.  This is the request payload:

 {"OrderNbr": {"value": "1712277"}, "OrderType": {"value": "DR"}, "Details": [{"InventoryID": {"value": "014431086625"}, "OrderQty": {"value": 1.0}, "UnitPrice": {"value": 0.02}, "WarehouseID": {"value": "999"}, "Operation": {"value": "Issue"}}, {"InventoryID": {"value": "015882002264"}, "OrderQty": {"value": 1.0}, "UnitPrice": {"value": 2.08}, "WarehouseID": {"value": "999"}, "Operation": {"value": "Issue"}}, {"InventoryID": {"value": "015882075367"}, "OrderQty": {"value": 1.0}, "UnitPrice": {"value": 0.12}, "WarehouseID": {"value": "999"}, "Operation": {"value": "Issue"}}, {"InventoryID": {"value": "015882075473"}, "OrderQty": {"value": 1.0}, "UnitPrice": {"value": 4.33}, "WarehouseID": {"value": "999"}, "Operation": {"value": "Issue"}}, {"InventoryID": {"value": "022945071808"}, "OrderQty": {"value": 1.0}, "UnitPrice": {"value": 0.02}, "WarehouseID": {"value": "999"}, "Operation": {"value": "Issue"}}, {"InventoryID": {"value": "022945200925"}, "OrderQty": {"value": 1.0}, "UnitPrice": {"value": 0.06}, "WarehouseID": {"value": "999"}, "Operation": {"value": "Issue"}}]}

 

I left it running for at least 5 mins and nothing happens.  Any insight would be appreciated!

thanks

 

Best answer by Django

Your payload looks correct for adding new detail lines to an existing order.

If you’re updating an order, just set the URL to the base for SalesOrder and not a document specific URL:
https://xyz.com/entity/Default/22.200.001/SalesOrder

 

For your update processes, I’d recommend limiting the fields you’re returning so that Acm doesn’t have to spend a bunch of cycles generating a full json return with details if you’re not going to use it. You might use it in your last call to validate that Acm has everything you sent, but before that, just return the ordernbr field.

View original
Did this topic help you find an answer to your question?

Forum|alt.badge.img+6
  • Captain II
  • 570 replies
  • Answer
  • February 25, 2025

Your payload looks correct for adding new detail lines to an existing order.

If you’re updating an order, just set the URL to the base for SalesOrder and not a document specific URL:
https://xyz.com/entity/Default/22.200.001/SalesOrder

 

For your update processes, I’d recommend limiting the fields you’re returning so that Acm doesn’t have to spend a bunch of cycles generating a full json return with details if you’re not going to use it. You might use it in your last call to validate that Acm has everything you sent, but before that, just return the ordernbr field.


  • Freshman I
  • February 25, 2025

Changing my URL to that was all it took. Now it is working and my batching is working as well.  

On the second part of your response, i’m not sure what you mean by “limiting the fields you’re returning”.  How do I do that?  The order number is the only data being returned that I’m actually using. And performance is my biggest issue so I definitely want to do everything I can to improve that.  We deal with orders that can have 1000s of line items.  A large part of why I’m working on this is so we can get away from having a person using an Import Scenario, which is brutally slow.

thanks


Forum|alt.badge.img+6
  • Captain II
  • 570 replies
  • February 25, 2025

Great news!

For the return, just adjust your $select parameter to include the fields you want to return: $select=OrderType,OrderNbr

In your example, above, you have details in the select parameter as well as the $expand parameter.


  • Freshman I
  • February 26, 2025

Ah I see what you mean.  I am not actually using that URL structure, that was just an attempt to get it to work (there was an example that looked like this in the support docs).  

Thanks again


Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings