What is the recommended way to export a large amount of data from Acumatica via the SOAP Contract-Based API?
The Stock Items screen (IN.20.25.00) is one of the most often used data entry forms of Acumatica ERP to export data. Inventory ID is the only primary key on the Stock Items screen:
using (DefaultSoapClient client = new DefaultSoapClient())
{
client.Login(username, password, null, null, null);
try
{
var items = client.GetList(new StockItem());
}
finally
{
client.Logout();
}
}
With time amount of data in any ERP application tends to grow in size. If you will be exporting all records from your Acumatica ERP instance in a single web service call, very soon you might notice timeout errors. Increasing timeout is a possible one-time, but not the very good long-term solution. Your best option to address this challenge is to export stock items in batches of several records.
using (DefaultSoapClient client = new DefaultSoapClient())
{
client.Login(username, password, null, null, null);
try
{
var items = client.GetList(
new StockItem
{
RowNumber = new LongSearch
{
Condition = LongCondition.IsLessThan,
Value = 10
}
});
while (items.Length == 10)
{
StockItem filter = new StockItem
{
RowNumber = new LongSearch
{
Condition = LongCondition.IsLessThan,
Value = 10
},
InventoryID = new StringSearch
{
Condition = StringCondition.IsGreaterThan,
Value = (items[items.Length - 1] as StockItem).InventoryID.Value
}
};
}
}
finally
{
client.Logout();
}
}
There are 2 main differences between the single call approach and the export in batches:
RowNumber property of the StockItem entity is not used in the single call approach
when exporting records in batches, size of a batch is configured through the RowNumber property of the entity passed into the GetList
method to request the next result set
The Sales Orders screen (SO.30.10.00) is a perfect example of a data entry form with a composite primary key. The primary key on the Sales Orders screen is composed of the Order Type and the Order Number:
using (DefaultSoapClient client = new DefaultSoapClient())
{
client.Login(username, password, null, null, null);
try
{
var orders = client.GetList(
new SalesOrder
{
OrderType = new StringReturn(),
OrderNbr = new StringReturn(),
RowNumber = new LongSearch
{
Condition = LongCondition.IsLessThan,
Value = 100
},
ReturnBehavior = ReturnBehavior.OnlySpecified
});
bool sameOrderType = true;
while (orders.Length > 0 && (orders.Length == 100 || !sameOrderType))
{
SalesOrder filter = new SalesOrder
{
RowNumber = new LongSearch
{
Condition = LongCondition.IsLessThan,
Value = 100
},
OrderType = new StringSearch
{
Condition = sameOrderType ? StringCondition.Equal : StringCondition.IsGreaterThan,
Value = (orders[orders.Length - 1] as SalesOrder).OrderType.Value
},
OrderNbr = new StringSearch
{
Condition = StringCondition.IsGreaterThan,
Value = sameOrderType ? (orders[orders.Length - 1] as SalesOrder).OrderNbr.Value : string.Empty
},
ReturnBehavior = ReturnBehavior.OnlySpecified
};
orders = client.GetList(filter);
sameOrderType = orders.Length == 100;
}
}
finally
{
client.Logout();
}
}
The sample above demonstrates how to export all sales orders from Acumatica ERP in batches of 100 records. We start with the request to obtain first 100 sales orders from Acumatica. After that we export sales order of each type independently: your SOAP request obtains either next 100 orders of the same previously received type or first 100 sales orders of the next order type.