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:
- the SDK should unwrap and return
OrganizationInvitation[], matching the current TypeScript declaration, or
- 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.
Package + version
@clerk/backend@3.5.0Description
clerkClient.organizations.createOrganizationInvitationBulk()is typed as returningPromise<OrganizationInvitation[]>, but the Backend API endpoint it wraps returns an object with adataarray andtotal_count.The latest published declaration in
@clerk/backend@3.5.0still has:The compiled implementation appears to return the raw request result without unwrapping
data:However, the Backend API reference for
POST /v1/organizations/{organization_id}/invitations/bulkshows 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-bulkExpected behavior
Either:
OrganizationInvitation[], matching the current TypeScript declaration, orPromise<PaginatedResourceResponse<OrganizationInvitation[]>>or{ data: OrganizationInvitation[]; totalCount: number }.Actual behavior
Runtime returns an object with a
dataarray, while TypeScript says the method returns an array.This makes code like this type-check but fail at runtime:
Workaround
Notes
The response shape shown in the Backend API reference is also consistent with other list-style Clerk responses that expose
dataand count metadata.