Skip to main content

Importing sales orders through the API

Bring open orders from another system into The Layer in bulk: one order per call, checked before anything is saved, and never duplicated.

Written by Nick Kewney

Why use the sales order import

When you move to The Layer, the orders that are still in progress in your old system need to come with you. Keying them in by hand is slow, and with hundreds of orders it is easy to miss an item, put an order on the wrong customer or create the same order twice.

The sales order import lets your own system send those orders straight into The Layer, and it is built to be safe to run in bulk:

  • Checked first: each order is checked in full before anything is saved, and every problem is listed in one reply.

  • All or nothing: an order is created completely, with all its items, or not at all.

  • No duplicates: sending the same order again returns the order made the first time.

  • Your normal process: imported orders start at the beginning of your order process, like any order created on screen.

Orders, not assets

The import creates sales orders and their items. It does not create assets. Assets are created later, when an order is completed, and only for items marked as New. Services your customers already have should come in through your asset import, not through orders.


How it works

Your system groups its data by order number and sends one request per order. The import builds the order the same way The Layer builds one on screen:

  • The sales order: the customer, owner, dates and purchase order number.

  • Lines: each line is a product from your Inventory with a quantity and prices.

  • Units: each line has one data capture row per unit, holding that unit's details (for example its CLI, serial or IMEI) and how it links to other units.


Before you start

  1. Load your customers, contacts, sites and products first. Every order must match a customer in The Layer and every line a product in your Inventory.

  2. Load live services through your asset import, including any service an order upgrades or replaces. An order can only point at an asset that is already in The Layer.

  3. Create an API application and tokens for the user that will run the import. See Authenticating API Requests for The Layer.

  4. Give that user the API - Sales Order Import permission: go to Settings > Users, open the user, open the Roles tab, find Developer API, tick API - Sales Order Import and click Save. See User-Based API Permissions.

API - Access All Areas does not include the import. Because it creates orders in bulk, it needs its own permission, even for a user who already has full API access.

We recommend trying the import on a test company first. Each order is checked and created exactly as it will be for real.


The calls

All three calls are on https://webapi.thelayer.com and need the Token1 and Token2 headers, like every Layer API call.

Call

What it does

POST /api/SalesOrderImport/Validate

Runs every check and saves nothing. Use it to clean your data before the real run.

POST /api/SalesOrderImport/Import

Creates the order, its lines and its data capture rows.

GET /api/SalesOrderImport/Status?externalReference=SO-1001

Tells you what happened to an order you sent.


Building a request

This example is one order for one customer with three lines: two connections, a handset tied to the first connection, and two data bolt-ons that sit under the connections. The second connection upgrades a service the customer already has (asset 900).

{
"ExternalReference": "SO-1001",
"CustomerLookupField": "Reference",
"CustomerLookupValue": "CUS0001",
"Owner": "jane.smith",
"OrderDate": "2026-10-01",
"CustomerPO": "PO-778",
"Lines": [
{
"LineKey": "CONN", "ProductSKU": "MOB-CONN", "Quantity": 2, "RecurringCost": 18.50,
"Units": [
{ "UnitKey": "C1", "Action": "New", "ServiceMSISDN": "07700900001", "LinkedProductUnitKey": "H1" },
{ "UnitKey": "C2", "Action": "Update", "TargetAssetId": 900, "ServiceMSISDN": "07700900123" }
]
},
{
"LineKey": "PHONE", "ProductSKU": "HANDSET", "Quantity": 1,
"Units": [ { "UnitKey": "H1", "Action": "New", "ProductIMEI": "350000000000001" } ]
},
{
"LineKey": "BOLT", "ParentLineKey": "CONN", "ProductSKU": "DATA-BOLT", "Quantity": 2,
"Units": [ { "Action": "New" }, { "Action": "New" } ]
}
]
}

Order fields

Field

Required

Notes

ExternalReference

Yes

Your order number, up to 100 characters, unique within your company. It is what makes sending an order again safe.

CustomerId

One of these

The customer's id in The Layer.

CustomerLookupField and CustomerLookupValue

One of these

Find the customer by Reference, CustomerReference, BillingAccountNumber or SageAccountNumber. The value must match exactly one customer. Send these or CustomerId, not both.

ContactId

No

One of the customer's contacts.

SiteId

No

One of the customer's sites. It sets the order's delivery and billing addresses.

SubCompanyId

No

One of your sub companies.

Owner

No

The username of the order owner. Defaults to the API user.

OrderDate

No

The date the order was raised in your old system. Defaults to today.

EstimatedFulfilmentDate

No

Defaults to today plus your usual fulfilment lead time.

CustomerPO

No

The customer's purchase order number.

RunCreateScripts

No

Defaults to false. See Good to know below.

Lines

Yes

At least one line.

There is no status field. Every imported order starts at your company's starting sales order status, whatever its status was in your old system, so it goes through your order process from the beginning.

Line fields

Field

Required

Notes

LineKey

Yes

Your id for the line, unique within the order. It is used in replies and by ParentLineKey.

ProductId or ProductSKU

Yes, one of them

The product in your Inventory. A SKU must match exactly one live product.

Quantity

Yes

From 1 to 2,000.

UnitCost and CostPrice

No

One-off sell and buy price for each unit. Default to the product's.

RecurringCost and RecurringCostBuy

No

Monthly sell and buy price for each unit. Default to the product's.

RecurringTerm

No

The term in months. Defaults to the product's.

ProductName

No

Changes the name shown on the line.

ClassificationId

No

One of the product's active classifications.

SiteId

No

One of the customer's sites.

LineDescription

No

A note shown on the line.

ParentLineKey

No

Links this line's units under another line's units. See Linking units together.

Units

No

Up to the line's quantity. Units you leave out are created blank, as they are when an order is made on screen.

Unit fields

Field

Required

Notes

UnitKey

Only if another unit links to it

Your id for the unit, unique within the order.

Action

No

New, Update, New & Cease or No Action. Defaults to No Action. Update and New & Cease can only be used if they are switched on for your company's data capture.

TargetAssetId

For Update and New & Cease

The id of the existing service the unit changes or replaces.

LinkedParentUnitKey

No

The service unit this unit sits under.

LinkedProductUnitKey

No

The hardware unit this unit is tied to.

ConnectionDate

No

The unit's connection date.

ServiceMSISDN, ServiceSIM, ServiceReference, ServiceTerm, ProductSerial, ProductIMEI, SupplierAccountReference, SupplierServiceReference, CostCentre, User, Notes, SiteId, ServiceCustomField1 to ServiceCustomField10

No

The unit's details, as you would enter them in data capture.

Only New units become assets. If a service is already live and came in through your asset import, send its unit as No Action, or completing the order will create it a second time.

Products sold as one grouped quantity

Some products are set up so the whole quantity is one item, for example a block of DDIs or a pack of licences (the product's Quantity Mode is Grouped). For these, the line has a single data capture row that holds the whole quantity and becomes one asset. Send one unit for the line, with the details that apply to the whole block.


Linking units together

Links decide how assets fit together when the order completes, so send them explicitly. Nothing is worked out from product names.

Link

Field

What it does

Parent service

LinkedParentUnitKey

Puts a service under another service, for example a bolt-on under its connection. The bolt-on's asset becomes a child of the connection's asset.

Hardware

LinkedProductUnitKey

Ties a service to a hardware unit, for example a connection to its handset. The handset takes the connection's user, cost centre and site.

Existing asset

TargetAssetId

The live asset an Update or New & Cease unit acts on.

The rules are the same as on the data capture screen:

  • Only service units link to a parent or to hardware. A parent must be a service, and a hardware link must point at hardware.

  • Links stay within one base category, and they can't go round in a loop.

  • A target asset must be live, belong to the order's customer and be in the same base category as the product. Two units can't target the same asset.

Linking a whole line with ParentLineKey

If a line has ParentLineKey and its units have no LinkedParentUnitKey of their own, they are linked to the parent line's units in turn. Two bolt-ons under two connections go one each; three bolt-ons under two connections go to connection 1, 2 and then 1 again, as the auto map on the data capture screen does. The parent line must be a service line in the same base category that does not have a ParentLineKey itself. The order lines themselves are not nested: the links are on the units, which is what builds the assets.

If two products are linked on the order but are not set up as linked products in your Inventory, the order keeps the link and the reply includes a warning. Inventory links only affect what quotes suggest.


What you get back

Every reply includes Outcome, ExternalReference, SalesOrderId, Reference (the order's number in The Layer, for example SO1000), Errors and Warnings. After an import it also includes Lines: your line and unit keys with the ids created for them.

HTTP

Outcome

Meaning

What to do

200

Valid

Validate only: the order would be accepted.

Check any warnings.

201

Created

The order was created.

Keep SalesOrderId and Reference.

200

AlreadyImported

This ExternalReference was imported before. SalesOrderId is that order.

Nothing: no second order was made.

400

Invalid

Nothing was saved. Every problem is listed in Errors.

Fix the data and send it again.

409

InProgress

Another call with this reference is still running.

Wait, then call Status.

500

Failed

Nothing was saved and the reference was released.

Safe to send again.

500

Partial

The order was created but did not finish. The reference stays taken.

Don't send it again. Contact us with the reference.

Each error says where the problem is, so you can go straight to it:

{ "Path": "Lines[2].Units[0].LinkedParentUnitKey",
"Message": "A linked parent must be a service; 'H1' is Handset, which is hardware. Use LinkedProductUnitKey for hardware." }

Running the load

  1. Validate every order and fix your data until they all come back Valid.

  2. Import one order at a time.

  3. Allow time for big orders. An order with several hundred units can take a minute or more. Set your client's timeout to at least 5 minutes.

  4. If a call times out or you're not sure it went through, call Status, or simply send the order again. You'll get AlreadyImported or InProgress, never a second order.

  5. If you get Partial, stop sending that order and let us know its reference.


Good to know

  • Starting status: imported orders always start at your company's starting sales order status.

  • Automations: automations and scripts that normally run when an order is created (for example raising a case for time tracking, or a customer sync to a billing platform) do not run for imported orders. If you set RunCreateScripts to true, all of them run, exactly as for an order created on screen.

  • Prices: each line takes the product's prices unless you send your own.

  • Text is cleaned: as on every Layer API call, anything that looks like an HTML tag is removed from text values, and so are prefixes such as javascript: and data:. A note of Data: 10GB <b>bolt-on</b> is stored as 10GB bolt-on. Keep free text plain.

  • Ceases: a sales order does not cease a service on its own. To cease services that are already in The Layer, use the cease request import in Data Manager, which takes an asset and a cease date. See Using Data Manager to Import Records.

  • Limits: one order per call, up to 1,000 lines and 2,000 units (the total of the line quantities). Normal API rate limits apply.


Troubleshooting

You see

What it means

What to do

400 "Missing Authorization-Token"

The tokens are missing, wrong or expired.

Check the Token1 and Token2 headers.

400 "User not authorised to access WebAPI"

The API user does not have the import permission.

Tick API - Sales Order Import on the user's Roles tab.

"No customer has Reference ..." or "More than one customer has ..."

The customer lookup matched none, or more than one.

Check the value, or send CustomerId.

"No product has SKU ..." or "2 products have SKU ..."

The SKU isn't in your Inventory, or is on more than one product.

Add or fix the product, or send ProductId.

"Contact ... is not a contact of this customer" or "Site ... is not a site of this customer"

The contact or site belongs to someone else.

Use the customer's own contact or site, or leave it out.

"Asset ... is not live", "is not a service of this customer" or "is in a different base category"

The target asset can't be changed by this unit.

Check the asset id and that the asset is loaded and live.

"Update is switched off ..." or "New & Cease is not switched on ..."

Your company's data capture doesn't offer that action.

Use New or No Action, or ask us about switching it on.

"A linked parent must be a service ..." or "Linked parents form a loop"

A link points the wrong way or goes round in a circle.

See Linking units together.

"User ... was not found"

The Owner isn't a user in your company.

Use their username in The Layer, or leave it out.

Did this answer your question?