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.
| Field | Type | Required | Description |
|---|---|---|---|
parentCompany | String | Yes | ID of the parent company. |
name | String | No | Name of the corporate. Defaults to the parent company's name. When the corporate already exists, it is only changed if sent. |
active | Boolean | No | Whether 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. |
subCompanies | Array | No | IDs of all sub-companies. Replaces the current list. |
corporateLinkAccess | Array | No | Access settings for individual sub-companies. See below. |
Corporate Link Access Object
| Field | Type | Required | Description |
|---|---|---|---|
companyId | String | Yes | ID of a sub-company of this corporate. List each sub-company only once. |
allAccess | Boolean | No | true gives the parent company's users full access in this sub-company. See below. |
accessList | Array | No | Permissions the parent company's users have in this sub-company, for example ORDERS, CREATE_ORDERS. See below. |
How allAccess and accessList work:
allAccess: truegrants everything the parent company's users' roles allow in the sub-company, including permissions added later.accessListis ignored whenallAccessistrue.accessListreplaces the permission list for this sub-company. Values are permission keys from the store's customer permissions. See Permission keys. Keys are case-sensitive, soordersis rejected. A key that is not in the store's customer permissions returns400withcodeACCESS_UNKNOWN_KEYS.- Sending a sub-permission also grants its group. For example,
CREATE_ORDERSimpliesORDERS. CORPORATEandMANAGE_SUBCOMPANIESare never rejected as unknown, but they cannot be granted through a link and are not part of whatallAccess: truegrants.- An empty
accessListwithallAccessomitted orfalseleaves 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
companyIdmust also be insubCompanies(or already in the corporate, whensubCompaniesis omitted). Otherwise the request returns400with"<id>" is not a sub-company of this corporate. - A
companyIdlisted twice returns400. 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 }, withstatusinstead ofsuccess.
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
| Field | Type | Description |
|---|---|---|
success | Boolean | Whether the request succeeded. |
message | String | Corporate created successfully, or Corporate updated successfully if the parent company already had a corporate. |
data | Object | The corporate. See below. |
Corporate Data
| Field | Type | Description |
|---|---|---|
id | String | Unique identifier of the corporate. |
name | String | Name of the corporate. |
skippedSubCompanies | Array | IDs 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.
code | Meaning |
|---|---|
HIERARCHY_SELF | A company cannot be linked to itself. |
HIERARCHY_CYCLE | A company cannot be placed below one of its own sub-companies. |
HIERARCHY_TOO_DEEP | The chain would have more than 5 links. |
ACCESS_UNKNOWN_KEYS | accessList contains a permission that is not recognised. |
USER_ERROR | Any other validation failure. |
Notes
- Sub-companies that are not in
subCompaniesare removed from the corporate. Leave outsubCompaniesto keep the current list. - A new sub-company without a
corporateLinkAccessentry 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,isSubCompanyand the deprecatedparentIdare updated in the same step. - See Corporate Hierarchy and Access for the full rules.