Delete <OrderLine>s from <Order> using entity REST API

Hello,

I am using the GET, POST, PUT commands to retrieve, create, and edit orders using the Entity REST API at /api/sales/orders.

I am able to POST both order information and Line information using something like below:

<?xml version='1.0' encoding='UTF-8'?>
<Order xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <CustomerId>361876</CustomerId>
  <CompanyId>ABC</CompanyId>
  <LocationId>21090</LocationId>
  <ShipToId>790905</ShipToId>
  <Lines>
    <OrderLine>
      <ItemId>MY_ITEM_ID</ItemId>
      <UnitQuantity>1</UnitQuantity>
    </OrderLine>
  </Lines>
</Order>

Let’s say I want to update this order with completely new <OrderLine>s. If I do a PUT to /api/sales/orders/55555 with the <Lines> element removed like below:

<?xml version='1.0' encoding='UTF-8'?>
<Order xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <CustomerId>361876</CustomerId>
  <CompanyId>ABC</CompanyId>
  <LocationId>21090</LocationId>
  <ShipToId>790905</ShipToId>
  <OrderNo>55555</OrderNo>
  <Lines>
  </Lines>
</Order>

In theory it should remove all of the lines since PUT overwrites the resource. It does not remove the order lines or lines. I can add additional orderlines using the patch method, but I do not seem to be able to edit existing orderlines or delete them.

Using the Entity REST API how can I delete or overwrite existing lines?
If it is not possible with the Entity REST API, what is the simplest solution using a webservice to delete all Lines associated with an order (items tab in Order Entry).

Thanks

Fairly sure you need PATCH for update items not POST.
POST would normally create new lines.

1 Like

@CSmith Thanks for the prompt response Clint !

Unfortunately, PATCH is not available via the entity API. I have tried using the PUT, but that does not appear to delete or allow modifications of the <Lines> or <OrderLine>s.

Are you sending RowMod = ‘D’ then?

2 Likes

@Randy What should the XML structure look like ? My below structure gives the following error.

<?xml version="1.0"?>
<Order xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <Lines>
         <OrderLine RowMod="D">
            <LineNo>1</LineNo>
        </OrderLine>
         <OrderLine RowMod="D">
            <LineNo>2</LineNo>
        </OrderLine>
    </Lines>
...
</Order>
<ResourceError xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
    <DateTimeStamp>2025-06-02T15:20:19.8228409Z</DateTimeStamp>
    <ErrorMessage>&amp;lt;ImportReturn type=&amp;quot;CREATE&amp;quot;&amp;gt;&#xD;
&amp;lt;ImportMessages&amp;gt;&#xD;
&amp;lt;ImportMessage severity=&amp;quot;error&amp;quot;&amp;gt;&amp;lt;Messages&amp;gt;&amp;lt;ImportReturn type=&amp;quot;order&amp;quot;&amp;gt;&#xD;
&amp;lt;ImportMessages&amp;gt;&#xD;
&amp;lt;ImportMessage severity=&amp;quot;error&amp;quot;&amp;gt;Invalid condition in of_SetupImportBo method of n_cst_import object: Either Item ID or Inv Mast UID must be specified.&amp;lt;/ImportMessage&amp;gt;&#xD;
&amp;lt;/ImportMessages&amp;gt;&#xD;
&amp;lt;ImportRows /&amp;gt;&#xD;
&amp;lt;/ImportReturn&amp;gt;&amp;lt;/Messages&amp;gt;&amp;lt;/ImportMessage&amp;gt;&#xD;
&amp;lt;ImportMessage severity=&amp;quot;info&amp;quot;&amp;gt;(Return value: -1 , Failure )&amp;lt;/ImportMessage&amp;gt;&#xD;
&amp;lt;/ImportMessages&amp;gt;&#xD;
&amp;lt;ImportRows /&amp;gt;&#xD;
&amp;lt;/ImportReturn&amp;gt; (-1)</ErrorMessage>
    <ErrorType>P21.DataAccess.PbNet.Common.PbService.P21ServerException</ErrorType>
    <HostName>FCG-P21DEV-01</HostName>
    <InnerException i:nil="true"/>
    <LogId>a99dfbf0-b2d7-4898-bc2c-b8c8bf435265</LogId>
    <StackTrace>&amp;lt;ImportReturn type=&amp;quot;CREATE&amp;quot;&amp;gt;&#xD;
&amp;lt;ImportMessages&amp;gt;&#xD;
&amp;lt;ImportMessage severity=&amp;quot;error&amp;quot;&amp;gt;&amp;lt;Messages&amp;gt;&amp;lt;ImportReturn type=&amp;quot;order&amp;quot;&amp;gt;&#xD;
&amp;lt;ImportMessages&amp;gt;&#xD;
&amp;lt;ImportMessage severity=&amp;quot;error&amp;quot;&amp;gt;Invalid condition in of_SetupImportBo method of n_cst_import object: Either Item ID or Inv Mast UID must be specified.&amp;lt;/ImportMessage&amp;gt;&#xD;
&amp;lt;/ImportMessages&amp;gt;&#xD;
&amp;lt;ImportRows /&amp;gt;&#xD;
&amp;lt;/ImportReturn&amp;gt;&amp;lt;/Messages&amp;gt;&amp;lt;/ImportMessage&amp;gt;&#xD;
&amp;lt;ImportMessage severity=&amp;quot;info&amp;quot;&amp;gt;(Return value: -1 , Failure )&amp;lt;/ImportMessage&amp;gt;&#xD;
&amp;lt;/ImportMessages&amp;gt;&#xD;
&amp;lt;ImportRows /&amp;gt;&#xD;
&amp;lt;/ImportReturn&amp;gt; (-1)
   at P21.Application.c__importer_xml.add()&#xD;
   at P21.Application.Importer.add()&#xD;
   at P21.DataAccess.PbNet.Common.PbService.PbServiceHelper.Check[T](MethodBase caller, Func`1 check)   at P21.DataAccess.PbNet.Common.PbService.PbServiceHelper.Check[T](MethodBase caller, Func`1 check)&#xD;
   at P21.DataAccess.PbNet.Common.ImporterProxy.Add(String Name, IDictionary`2 DataSetDict, String&amp;amp; returnMsg)&#xD;
   at P21.DataAccess.PbNet.Common.ImporterProxy.Add(ImportData data)&#xD;
   at P21.Business.Sales.OrderManager.UpdateExistingOrder(Order order)&#xD;
   at P21.Soa.Service.Rest.Common.BaseManagerResource`2.Update(TDomainObject toUpdate, Boolean retrieve)
   at P21.Application.c__importer_xml.add()&#xD;
   at P21.Application.Importer.add()&#xD;
   at P21.DataAccess.PbNet.Common.PbService.PbServiceHelper.Check[T](MethodBase caller, Func`1 check)&#xD;
</StackTrace>
    <UserId>company.local\username</UserId>
</ResourceError>

“of_SetupImportBo method of n_cst_import”

Never seen these. Are they your custom?