Skip to main content

Build your own Order-based ERP integration

Sometimes you want to use TRAEDE as an ordering system, but actually fulfilling your orders, doing invoicing, managing inventory in a different ERP. In such a case you can build your own ERP integration. Follow this guide to learn best practice and a recommended structure.

caution

NOTE This guide is for when you want to synchronize orders to your ERP system so they can be delivered and invoiced in there instead of in TRAEDE. If you are instead looking to create invoices and credit notes in TRAEDE and synchronize these to your accounting system then you should look at our guide for building your own invoice-based ERP integration.

Flows to implement

There are multiple flows that can be implemented where some are recommended and some are optional

Each flow is described in detail further down

Sync orders from TRAEDE -> ERP

Whenever an order is created at some point it should be synchronized to the ERP system. It's up to you if you want to support changes to the order as well. To synchronize an order you should follow 2 steps

  1. Use TRAEDE export API to get a list of all orders that have not been exported yet
  2. For each order import it into your ERP and if it was imported successfully mark it as exported in TRAEDE

It's important to mark orders as exported in TRAEDE so that exported orders are closed in TRAEDE. Any pieces that are not synced will be subtracted from the inventory that is synced from the ERP.

Step 1: Get list of all orders that have not been exported yet

TRAEDE has built-in export APIs that keeps track of which orders that have been exported and which have not. Read more about the export APIs here.

You should use the Order Export API to fetch all orders that have not been exported yet.

Step 2: Import order into ERP and mark it as synced

The next step is to iterate over all the orders and import them into your ERP. If the import is successful you should send a call back marking the orders as exported. This is also done using the export API. You can read more about this here

Full pseudo-example in PHP

This example assumes we have a client class that can make HTTP requests (e.g. could be made using Guzzle). The example also assumes you have a class named OrderImporter that actually imports the order into your system.

<?php

// Just a fake class for making HTTP requests. Replace with something like guzzle or similar
// Notice our fake client class implements `requestAllPages` that makes sure to iterate
// through all pages of new/updated orders
$client = new Client();

// Just a fake class to simulate actually saving the order in our own system. Replace
// with your own implementation
$importer = new OrderImporter();

$requestOptions = [
'system_id' => 'my_system',
'include_archived' => 0,
'include_cancelled' => 0,
'include_not_approved' => 0,

// details we need to import the order
'includes' => [
'customer',
'lines',
'lines.product',
'lines.variant'
]
];

$ordersThatShouldBeImported = $client->requestAllPages(
'/v10/orders/export',
$requestOptions
);

foreach ($ordersThatShouldBeImported as $order) {
$importStatus = $importer->importOrderIntoErp($order);

// The import succeeded. So we should mark the order as synced
// to tell TRAEDE to close the order
if ($importStatus === true) {
$client->request(
'/v10/orders/mark-as-exported',
'POST',
[
'orders' => [
[
'order_id' => $order->id,
'system_id' => 'my_system',
'note' => 'Order was imported!',
'regulate_inventory' => true
]
]
]
);

// Import failed. Throw error?
} else {

}
}

Sync available inventory from ERP -> TRAEDE

Most of the time you will want the ERP system to be the "master of inventory". As such we have made it very easy for you to synchronize the inventory of the ERP to TRAEDE.

You should use the Full inventory sync endpoint to do this. Note that this endpoint is extra rate-limited and can only be called once every hour. TRAEDE will regulate it's own inventory when orders are made so it's probably not needed to create more frequent syncs than that.

If further adjustments are needed within the rate-limt period then use the Adjust inventory endpoint

Sync product data from ERP -> TRAEDE

If you want to control product data in your ERP system, you can easily sync the data to TRAEDE using our Import API.