Corporate Hierarchy and Access
A company can be a sub-company of several parent companies, and can be a parent itself. This page collects the rules that apply across the Company and Corporate endpoints.
Model
- A corporate belongs to one parent company and lists that company's direct sub-companies in
subCompanies. - A company owns at most one corporate. The corporate holds all of the company's direct sub-companies.
- A company can be a sub-company of many parents, and can also be a parent itself.
- Links can be written from either side. Both sides write the same links. A company's own
parents,parentIds,isSubCompanyand the deprecatedparentIdfields are updated in the same step.
Limits
- A chain can have at most 5 links below the top company, so up to 6 companies from the top company to the lowest sub-company.
- A company cannot be its own sub-company, and cannot be placed below one of its own descendants (no cycles).
- Redundant paths are allowed. For example, a company can be a sub-company of both A and B, where B is itself a sub-company of A.
- There is no limit on the number of parents a company can have.
What a link grants
Users of the upper company, when switched into a lower company, get only what all of these allow:
effective access = user's role ∩ access set on the link ∩ the user's own access list (if one exists)
- A new direct link starts with all access.
- Access for direct links is set with
corporateLinkAccess, on Create Corporate and Update Corporate (per sub-company) or on Update Company (per parent). - A pair of companies that skips a level has no access until it is set. That can only be done in the Admin Portal.
- Access only narrows. It never gives a user more than their role allows.
Permission keys
accessList takes keys from your store's customer permissions. Keys are case-sensitive. These are the default permissions, with each group followed by its sub-permissions:
| Group | Keys |
|---|---|
ORDERS | ORDERS, CREATE_ORDERS, VIEW_OTHERS_ORDERS, APPROVE_ORDERS |
INVOICES | INVOICES, VIEW_OTHERS_INVOICES, PAY_OTHERS_INVOICES |
ADDRESS | ADDRESS, VIEW_ALL_SHIPPING_ADDRESS, MANAGE_ALL_SHIPPING_ADDRESS, MANAGE_SHIPPING_ADDRESS, VIEW_ALL_BILLING_ADDRESS, MANAGE_ALL_BILLING_ADDRESS, MANAGE_BILLING_ADDRESS |
COMPANY | COMPANY, UPDATE_COMPANY_DETAILS, CREATE_COMPANY_USERS, MANAGE_COMPANY_USERS |
BUDGET | BUDGET, VIEW_BUDGET, MANAGE_BUDGET |
CART | CART (no sub-permissions) |
- Both group names (
ORDERS) and sub-permission names (CREATE_ORDERS) are accepted. Sending a sub-permission also adds its group. - A key that is not in your store's customer permissions is rejected with
400andcodeACCESS_UNKNOWN_KEYS. CORPORATEandMANAGE_SUBCOMPANIESare never rejected as unknown, but they cannot be granted throughaccessListand are not part of whatallAccess: truegrants.
Active flag
Setting active to false on a corporate stops its parent company's users from acting in all of its sub-companies and in every level below them.
Where to read and write what
Reading
| To find... | Use |
|---|---|
| The parents of a company | parentIds in Get Company. Do not use the deprecated parentId. |
| The direct children of a company | Get All Corporates with company=<id>, or Get All Companies with parentId=<id> |
| The corporates that contain a company | Get Company, then Get All Corporates with company:in=<parentIds> |
Indirect descendants are never returned in one call. To walk the tree, repeat the call with each child's ID.
Writing links
| Side | How to write it |
|---|---|
| Parent side | POST /corporates or PUT /corporates/{id} with subCompanies |
| Child side | PUT /companies/{id} with parentCompanies |
Both sides write the same links. Use the child side to give one company several parents in a single call. Use the parent side to manage a parent's full list of sub-companies.
Both subCompanies and parentCompanies are the complete list: anything left out is unlinked. They differ on unknown IDs. subCompanies skips them and reports skippedSubCompanies, while parentCompanies rejects them with 400.
Error codes
Hierarchy errors return HTTP 400 with a code next to success and message. Match on code when it is present, because messages can change. The same codes are returned by the Corporate endpoints and by Update Company.
code | Meaning |
|---|---|
HIERARCHY_SELF | A company cannot be linked to itself. |
HIERARCHY_CYCLE | The link would place a company below one of its own descendants. |
HIERARCHY_TOO_DEEP | The link would make a chain longer than 5 links. |
ACCESS_UNKNOWN_KEYS | accessList contains a permission key that is not recognised. |
USER_ERROR | Any other validation failure, such as an unknown parent ID or a companyId that is not part of the link. |
{
"success": false,
"message": "Acme East can't be added: it is already below Acme West.",
"code": "HIERARCHY_CYCLE"
}
Messages are built from company names, so the text changes per request.
Not available through the API
- Reading link access back.
corporateLinkAccessis write-only: it is not returned by any Get endpoint. - Per-user access settings.
- Access for pairs of companies that skip a level.
- Setting parents when creating a company.
parentCompaniesis accepted by Update Company only. - Webhooks for hierarchy changes made through the API.
POSTandPUT /corporates, andPUT /companieswithparentCompanies, do not fire the corporate webhooks. - Reading your store's own list of permission keys. The defaults are listed above, and the role editor in the Admin Portal shows the full list.
Example: assign a company two parents
Companies P1 and P2 exist, and company C has no parents. One call to the child side links both:
curl --location --request PUT '<BASE_URL>/companies/<C>' \
--header 'accessToken: <ACCESS_TOKEN>' \
--header 'Content-Type: application/json' \
--data '{
"parentCompanies": ["<P1>", "<P2>"],
"corporateLinkAccess": [
{ "companyId": "<P1>", "allAccess": true },
{ "companyId": "<P2>", "accessList": ["CREATE_ORDERS", "VIEW_OTHERS_ORDERS"] }
]
}'
Use keys from your store's customer permissions.
The response, with other fields left out, returns both parents:
{
"success": true,
"message": "Company updated successfully",
"data": {
"id": "<C>",
"isSubCompany": true,
"parents": ["<P1>", "<P2>"],
"parentId": "<P1>",
"parentIds": ["<P1>", "<P2>"]
}
}
Without this, you would edit each parent's corporate and read-modify-write its subCompanies. A parent that has no corporate yet gets one automatically.
To stop P2's users acting in C without removing the link, send an empty accessList for C on P2's corporate:
curl --location --request PUT '<BASE_URL>/corporates/<P2_CORPORATE_ID>' \
--header 'accessToken: <ACCESS_TOKEN>' \
--header 'Content-Type: application/json' \
--data '{
"corporateLinkAccess": [
{ "companyId": "<C>", "accessList": [] }
]
}'
Sending C as a parent of P1 would put P1 below itself, because C is already below P1. The request fails and nothing is changed. Here P1 is named Acme West and C is named Acme East:
curl --location --request PUT '<BASE_URL>/companies/<P1>' \
--header 'accessToken: <ACCESS_TOKEN>' \
--header 'Content-Type: application/json' \
--data '{ "parentCompanies": ["<C>"] }'
{
"success": false,
"message": "Acme East can't be added: it is already below Acme West.",
"code": "HIERARCHY_CYCLE"
}
Migrating from single-parent behaviour
No endpoint changed its path or required fields, but some behaviour moved.
- A company can now have several parents, and be a parent itself, up to 5 links deep.
parentIdslists all parents. parentIdis deprecated. It is now alwaysparentIds[0]. Before, it could be any one of the parents, so an integration that readsparentIdfor a company with several parents may see a different value. ReadparentIdsinstead.- Update Company now accepts
parentCompaniesandcorporateLinkAccessto set a company's direct parents, and returnsparentIdandparentIdsindata. SendingparentCompaniesreplaces the full parent list. Leaving it out changes nothing. POST /corporatesandPUT /corporates/{id}acceptcorporateLinkAccess, reject cycles and over-deep chains with acode, skip unknown sub-company IDs (skippedSubCompanies), and either all succeed or change nothing.- Deleting a company now detaches it from every corporate it belongs to.