Skip to content

createOrganizationInvitationBulk return type does not match Backend API response shape #8740

Description

@MisterJimson

Package + version

@clerk/backend@3.5.0

Description

clerkClient.organizations.createOrganizationInvitationBulk() is typed as returning Promise<OrganizationInvitation[]>, but the Backend API endpoint it wraps returns an object with a data array and total_count.

The latest published declaration in @clerk/backend@3.5.0 still has:

createOrganizationInvitationBulk(
  organizationId: string,
  params: CreateBulkOrganizationInvitationParams,
): Promise<OrganizationInvitation[]>;

The compiled implementation appears to return the raw request result without unwrapping data:

async createOrganizationInvitationBulk(organizationId, params) {
  this.requireId(organizationId);
  return this.request({
    method: "POST",
    path: joinPaths(basePath19, organizationId, "invitations", "bulk"),
    bodyParams: params
  });
}

However, the Backend API reference for POST /v1/organizations/{organization_id}/invitations/bulk shows a response shaped like:

{
  "data": [
    {
      "object": "organization_invitation",
      "id": "string"
    }
  ],
  "total_count": 1
}

Docs reference: https://clerk.com/docs/reference/backend-api/tag/organization-invitations/POST/organizations/%7Borganization_id%7D/invitations/bulk

SDK reference currently says Promise<OrganizationInvitation[]>: https://clerk.com/docs/reference/backend/organization/create-organization-invitation-bulk

Expected behavior

Either:

  1. the SDK should unwrap and return OrganizationInvitation[], matching the current TypeScript declaration, or
  2. the TypeScript declaration and SDK docs should reflect the actual returned object shape, likely something like Promise<PaginatedResourceResponse<OrganizationInvitation[]>> or { data: OrganizationInvitation[]; totalCount: number }.

Actual behavior

Runtime returns an object with a data array, while TypeScript says the method returns an array.

This makes code like this type-check but fail at runtime:

const invitations = await clerkClient.organizations.createOrganizationInvitationBulk(orgId, params);

for (const invitation of invitations) {
  // invitations is not iterable if the runtime response is { data: [...] }
}

Workaround

const response = await clerkClient.organizations.createOrganizationInvitationBulk(orgId, params) as
  | OrganizationInvitation[]
  | { data: OrganizationInvitation[]; totalCount?: number; total_count?: number };

const invitations = Array.isArray(response) ? response : response.data;

Notes

The response shape shown in the Backend API reference is also consistent with other list-style Clerk responses that expose data and count metadata.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions