Skip to main content

Create Corporate

Creates a corporate that links a parent company to its sub-companies, and sets what the parent company's users can do in each sub-company. If the parent company already has a corporate, that corporate is updated instead.

For the rules that apply across all corporate endpoints, see Corporate Hierarchy and Access.

HTTP Request​

  • URL: /corporates
  • Method: POST
  • Headers:
    • accessToken: Required. Your API access token.
    • Content-Type: application/json
  • Required scope: READ_WRITE_COMPANY

Request Body​

Send a JSON object with the corporate details.

FieldTypeRequiredDescription
parentCompanyStringYesID of the parent company.
nameStringNoName of the corporate. Defaults to the parent company's name. When the corporate already exists, it is only changed if sent.
activeBooleanNoWhether the corporate is active. Default is true. false stops the parent company's users acting in every sub-company and every level below them. When the corporate already exists, it is only changed if sent.
subCompaniesArrayNoIDs of all sub-companies. Replaces the current list.
corporateLinkAccessArrayNoAccess settings for individual sub-companies. See below.
FieldTypeRequiredDescription
companyIdStringYesID of a sub-company of this corporate. List each sub-company only once.
allAccessBooleanNotrue gives the parent company's users full access in this sub-company. See below.
accessListArrayNoPermissions the parent company's users have in this sub-company, for example ORDERS, CREATE_ORDERS. See below.

How allAccess and accessList work:

  • allAccess: true grants everything the parent company's users' roles allow in the sub-company, including permissions added later. accessList is ignored when allAccess is true.
  • accessList replaces the permission list for this sub-company. Values are permission keys from the store's customer permissions. See Permission keys. Keys are case-sensitive, so orders is rejected. A key that is not in the store's customer permissions returns 400 with code ACCESS_UNKNOWN_KEYS.
  • Sending a sub-permission also grants its group. For example, CREATE_ORDERS implies ORDERS.
  • CORPORATE and MANAGE_SUBCOMPANIES are never rejected as unknown, but they cannot be granted through a link and are not part of what allAccess: true grants.
  • An empty accessList with allAccess omitted or false leaves the parent company's users with no access in the sub-company. This switches a link off without removing it.
  • Access only narrows. A user's effective access is their role's permissions limited to this list, and to their own per-user list if one exists.
  • Leave out the entry to keep the current access of an existing link, or to give a new link full access.

Rules for corporateLinkAccess entries:

  • Every companyId must also be in subCompanies (or already in the corporate, when subCompanies is omitted). Otherwise the request returns 400 with "<id>" is not a sub-company of this corporate.
  • A companyId listed twice returns 400. Entries for companies that do not exist are ignored.
  • Access can only be set here for direct sub-companies. Access for a lower company that is not a direct sub-company is managed in the Admin Portal.

cURL Example​

curl --location '<BASE_URL>/corporates' \
--header 'accessToken: <ACCESS_TOKEN>' \
--header 'Content-Type: application/json' \
--data '{
"parentCompany": "67bd7732e2c361f0b15a1c18",
"name": "Keystone Holdings",
"active": true,
"subCompanies": ["64f72a721e63ec3bf06acd65", "64ae9fbb401a953a2b8988a1"],
"corporateLinkAccess": [
{
"companyId": "64ae9fbb401a953a2b8988a1",
"allAccess": false,
"accessList": ["ORDERS", "CREATE_ORDERS", "VIEW_OTHERS_ORDERS"]
}
]
}'

Response​

  • 200 OK: The corporate was created or updated successfully.
  • 400 Bad Request: A field is missing or not valid, a sub-company cannot be linked, or a permission is not recognised. See Error Codes.
  • 401 Unauthorized: The access token is missing or invalid.
  • 403 Forbidden: The access token does not have the required scope.
  • 404 Not Found: The parent company does not exist. The body is { "status": false, "message": "...", "data": null }, with status instead of success.

Unlike the Get endpoints, this endpoint returns 401, 403 and 404 as their own status codes.

Sample JSON Response​

{
"success": true,
"message": "Corporate created successfully",
"data": {
"id": "67bd786f177125410d15d694",
"name": "Keystone Holdings"
}
}

Response Details​

FieldTypeDescription
successBooleanWhether the request succeeded.
messageStringCorporate created successfully, or Corporate updated successfully if the parent company already had a corporate.
dataObjectThe corporate. See below.

Corporate Data​

FieldTypeDescription
idStringUnique identifier of the corporate.
nameStringName of the corporate.
skippedSubCompaniesArrayIDs from subCompanies that were skipped because no company matches them. Only present when needed.

When an ID in subCompanies does not match a company, the request still succeeds and links the IDs that exist:

{
"success": true,
"message": "Corporate created successfully",
"data": {
"id": "67bd786f177125410d15d694",
"name": "Keystone Holdings",
"skippedSubCompanies": ["64f72a721e63ec3bf06acd99"]
}
}

A link that is rejected, such as one that would create a cycle or make the chain too deep, is not skipped. It fails the whole request.

Error Codes​

Hierarchy errors include a code next to success and message. Match on code when it is present, because messages can change.

codeMeaning
HIERARCHY_SELFA company cannot be linked to itself.
HIERARCHY_CYCLEA company cannot be placed below one of its own sub-companies.
HIERARCHY_TOO_DEEPThe chain would have more than 5 links.
ACCESS_UNKNOWN_KEYSaccessList contains a permission that is not recognised.
USER_ERRORAny other validation failure.

Notes​

  • Sub-companies that are not in subCompanies are removed from the corporate. Leave out subCompanies to keep the current list.
  • A new sub-company without a corporateLinkAccess entry gets full access.
  • A company can belong to more than one parent company. A chain can have at most 5 links, so up to 6 companies from the top company to the lowest sub-company. A company cannot be added below one of its own sub-companies.
  • The request is all-or-nothing. If any link is rejected, nothing is changed.
  • Each linked company's parents, parentIds, isSubCompany and the deprecated parentId are updated in the same step.
  • See Corporate Hierarchy and Access for the full rules.