Subsidiaries API

This guide covers the API endpoints for managing subsidiaries in the Revenue Recognition System. Subsidiaries represent distinct business units within an organization and are used to track financial information separately for different parts of the business.

Schema

FieldTypeDescriptionRequired
idUUIDUnique identifier (system-generated)Read-only
organizationIdUUIDOrganization this subsidiary belongs toRead-only
nameStringName of the subsidiaryYes
codeStringUnique code for the subsidiaryYes
descriptionStringOptional descriptionNo
parentIdUUIDParent subsidiary (for hierarchical structures)No
isActiveBooleanWhether the subsidiary is active (default: true)No
createdAtDateTimeWhen the record was createdRead-only
updatedAtDateTimeWhen the record was last updatedRead-only

Authentication

All subsidiary API endpoints require authentication with a valid session. The session must include an organization context, which determines which subsidiaries are visible and modifiable. Organization context is provided through the x-stytch-organization-id header.

Endpoints

Create Subsidiary

Create a new subsidiary within your organization.

  • Name
    Endpoint
    Type
    POST /api/v1/subsidiaries
    Description
  • Name
    Content-Type
    Type
    application/json
    Description

Request Body

  • Name
    name
    Type
    string
    Required
    Description

    Name of the subsidiary

  • Name
    code
    Type
    string
    Required
    Description

    Unique code for the subsidiary within your organization

  • Name
    description
    Type
    string
    Description

    Optional description of the subsidiary

  • Name
    parentId
    Type
    string (UUID)
    Description

    ID of the parent subsidiary, if this is a child subsidiary

  • Name
    isActive
    Type
    boolean
    Description

    Whether the subsidiary is active

Request

curl -X POST https://api.example.com/api/v1/subsidiaries \
  -H "Content-Type: application/json" \
  -H "x-stytch-organization-id: ba3b8cdf-efc1-4a60-88be-ac203d263fe2" \
  -d '{
    "name": "West Coast Operations",
    "code": "WCO",
    "description": "Subsidiary handling west coast sales and operations",
    "isActive": true
  }'

Response

{
  "subsidiary": {
    "id": "f67f0ea2-77bd-4578-8c76-0116d473cc27",
    "organizationId": "ba3b8cdf-efc1-4a60-88be-ac203d263fe2",
    "name": "West Coast Operations",
    "code": "WCO",
    "description": "Subsidiary handling west coast sales and operations",
    "parentId": null,
    "isActive": true,
    "createdAt": "2025-05-11T12:33:59.048Z",
    "updatedAt": "2025-05-11T12:33:59.048Z"
  }
}

List Subsidiaries

Retrieve a paginated list of subsidiaries in your organization.

  • Name
    Endpoint
    Type
    GET /api/v1/subsidiaries
    Description

Query Parameters

  • Name
    page
    Type
    number
    Description

    Page number for pagination

  • Name
    limit
    Type
    number
    Description

    Number of items per page (max: 100)

  • Name
    orderBy
    Type
    string
    Description

    Field to sort by (name, code, createdAt)

  • Name
    orderDirection
    Type
    string
    Description

    Sort direction (asc, desc)

  • Name
    isActive
    Type
    boolean
    Description

    Filter by active status

  • Name
    parentId
    Type
    string (UUID)
    Description

    Filter by parent subsidiary (use "null" for top-level subsidiaries)

Request

curl -X GET "https://api.example.com/api/v1/subsidiaries?page=1&limit=10&isActive=true" \
  -H "x-stytch-organization-id: ba3b8cdf-efc1-4a60-88be-ac203d263fe2"

Response

{
  "data": [
    {
      "id": "f67f0ea2-77bd-4578-8c76-0116d473cc27",
      "organizationId": "ba3b8cdf-efc1-4a60-88be-ac203d263fe2",
      "name": "West Coast Operations",
      "code": "WCO",
      "description": "Subsidiary handling west coast sales and operations",
      "parentId": null,
      "isActive": true,
      "createdAt": "2025-05-11T12:33:59.048Z",
      "updatedAt": "2025-05-11T12:33:59.048Z"
    },
    {
      "id": "a23c7de4-9821-4f56-9ab3-0c245b88e129",
      "organizationId": "ba3b8cdf-efc1-4a60-88be-ac203d263fe2",
      "name": "East Coast Division",
      "code": "ECD",
      "description": "East coast sales and support",
      "parentId": null,
      "isActive": true,
      "createdAt": "2025-05-10T15:22:31.452Z",
      "updatedAt": "2025-05-10T15:22:31.452Z"
    }
  ],
  "total": 8,
  "page": 1,
  "limit": 10,
  "totalPages": 1
}

Get Subsidiary

Retrieve a specific subsidiary by ID.

  • Name
    Endpoint
    Type
    GET /api/v1/subsidiaries/{id}
    Description

Path Parameters

  • Name
    id
    Type
    string (UUID)
    Required
    Description

    ID of the subsidiary to retrieve

Request

curl -X GET https://api.example.com/api/v1/subsidiaries/f67f0ea2-77bd-4578-8c76-0116d473cc27 \
  -H "x-stytch-organization-id: ba3b8cdf-efc1-4a60-88be-ac203d263fe2"

Response

{
  "subsidiary": {
    "id": "f67f0ea2-77bd-4578-8c76-0116d473cc27",
    "organizationId": "ba3b8cdf-efc1-4a60-88be-ac203d263fe2",
    "name": "West Coast Operations",
    "code": "WCO",
    "description": "Subsidiary handling west coast sales and operations",
    "parentId": null,
    "isActive": true,
    "createdAt": "2025-05-11T12:33:59.048Z",
    "updatedAt": "2025-05-11T12:33:59.048Z"
  }
}

Update Subsidiary

Update an existing subsidiary.

  • Name
    Endpoint
    Type
    PUT /api/v1/subsidiaries/{id}
    Description
  • Name
    Content-Type
    Type
    application/json
    Description

Path Parameters

  • Name
    id
    Type
    string (UUID)
    Required
    Description

    ID of the subsidiary to update

Request Body

  • Name
    name
    Type
    string
    Description

    Name of the subsidiary

  • Name
    code
    Type
    string
    Description

    Unique code for the subsidiary

  • Name
    description
    Type
    string
    Description

    Description of the subsidiary

  • Name
    parentId
    Type
    string (UUID) | null
    Description

    ID of the parent subsidiary, or null to make it a top-level subsidiary

  • Name
    isActive
    Type
    boolean
    Description

    Whether the subsidiary is active

Request

curl -X PUT https://api.example.com/api/v1/subsidiaries/f67f0ea2-77bd-4578-8c76-0116d473cc27 \
  -H "Content-Type: application/json" \
  -H "x-stytch-organization-id: ba3b8cdf-efc1-4a60-88be-ac203d263fe2" \
  -d '{
    "name": "West Coast Operations Division",
    "description": "Updated description for west coast operations",
    "isActive": true
  }'

Response

{
  "subsidiary": {
    "id": "f67f0ea2-77bd-4578-8c76-0116d473cc27",
    "organizationId": "ba3b8cdf-efc1-4a60-88be-ac203d263fe2",
    "name": "West Coast Operations Division",
    "code": "WCO",
    "description": "Updated description for west coast operations",
    "parentId": null,
    "isActive": true,
    "createdAt": "2025-05-11T12:33:59.048Z",
    "updatedAt": "2025-05-11T13:45:22.183Z"
  }
}

Delete Subsidiary

Delete a subsidiary. Note that subsidiaries with child subsidiaries cannot be deleted.

  • Name
    Endpoint
    Type
    DELETE /api/v1/subsidiaries/{id}
    Description

Path Parameters

  • Name
    id
    Type
    string (UUID)
    Required
    Description

    ID of the subsidiary to delete

Request

curl -X DELETE https://api.example.com/api/v1/subsidiaries/f67f0ea2-77bd-4578-8c76-0116d473cc27 \
  -H "x-stytch-organization-id: ba3b8cdf-efc1-4a60-88be-ac203d263fe2"

Response

{
  "success": true,
  "message": "Subsidiary deleted successfully"
}

Error Responses

The API returns standard HTTP status codes and error messages in a consistent format.

{
  "message": "Error description",
  "code": "ERROR_CODE",
  "details": { ... }
}

Common errors include:

Status CodeError CodeDescription
400VALIDATION_ERRORRequest data failed validation
400DUPLICATE_SUBSIDIARY_CODEA subsidiary with the provided code already exists
400PARENT_SUBSIDIARY_NOT_FOUNDThe specified parent subsidiary does not exist
400INVALID_PARENT_REFERENCEA subsidiary cannot be its own parent
400CIRCULAR_REFERENCEThe parent relationship would create a circular reference
400SUBSIDIARY_HAS_CHILDRENCannot delete a subsidiary that has child subsidiaries
401MISSING_ORGANIZATION_CONTEXTOrganization context is required for this operation
404SUBSIDIARY_NOT_FOUNDThe requested subsidiary was not found

Hierarchical Relationships

Subsidiaries can be organized in a hierarchical structure using the parentId field. When a subsidiary has a parentId, it indicates that it is a child of another subsidiary. This allows for creating organizational structures that match your business needs.

Some important constraints on hierarchical relationships:

  1. A subsidiary cannot be its own parent
  2. Circular references are not allowed (e.g., A → B → C → A)
  3. Subsidiaries with children cannot be deleted (you must delete or reassign the children first)

Example: Creating a Hierarchical Structure

// Create parent subsidiary
const parent = await apiClient.subsidiaries.create({
  name: "Global Operations",
  code: "GLOBAL",
  description: "Parent subsidiary for all regional operations"
});

// Create child subsidiary referencing the parent
const child = await apiClient.subsidiaries.create({
  name: "Asia Pacific Division",
  code: "APAC",
  description: "Asia Pacific regional operations",
  parentId: parent.subsidiary.id
});

Code Example

Here's an example of how to use the subsidiaries API with the client library:

import { apiClient } from '@/lib/db-adapter';

// List all subsidiaries
async function listAllSubsidiaries() {
  try {
    const result = await apiClient.subsidiaries.list({
      isActive: true,
      orderBy: 'name',
      orderDirection: 'asc'
    });
    
    console.log(`Found ${result.total} subsidiaries`);
    return result.data;
  } catch (error) {
    console.error('Error listing subsidiaries:', error);
    throw error;
  }
}

// Create a new subsidiary
async function createSubsidiary(data) {
  try {
    const result = await apiClient.subsidiaries.create({
      name: data.name,
      code: data.code,
      description: data.description,
      parentId: data.parentId
    });
    
    console.log('Subsidiary created:', result.subsidiary);
    return result.subsidiary;
  } catch (error) {
    console.error('Error creating subsidiary:', error);
    throw error;
  }
}

Was this page helpful?