Skip to content

Add api keys management api methods#1434

Merged
stanleyphu merged 2 commits intomainfrom
feat/auth-5677-add-api-keys-management-api
Jan 6, 2026
Merged

Add api keys management api methods#1434
stanleyphu merged 2 commits intomainfrom
feat/auth-5677-add-api-keys-management-api

Conversation

@stanleyphu
Copy link
Contributor

Description

This PR adds methods for new API key management API endpoints that we recently added.

  • organizations.listOrganizationApiKeys (GET /organizations/:id/api_keys)
  • organizations.createOrganizationApiKey (POST /organizations/:id/api_keys)
  • apiKeys.deleteApiKey (DELETE /api_keys/:id)

Documentation

Does this require changes to the WorkOS Docs? E.g. the API Reference or code snippets need updates.

[x] Yes

If yes, link a related docs PR and add a docs maintainer as a reviewer. Their approval is required.

@stanleyphu stanleyphu requested a review from a team as a code owner January 5, 2026 19:40
@stanleyphu stanleyphu requested a review from blairworkos January 5, 2026 19:40
@linear
Copy link

linear bot commented Jan 5, 2026

@greptile-apps
Copy link
Contributor

greptile-apps bot commented Jan 5, 2026

Greptile Summary

Added three new API key management methods to the SDK: listOrganizationApiKeys for retrieving API keys with pagination support, createOrganizationApiKey for creating new keys with idempotency support, and deleteApiKey for deletion. Implementation follows existing codebase patterns with proper serialization/deserialization between snake_case API responses and camelCase TypeScript interfaces.

  • Added organizations.listOrganizationApiKeys with pagination (limit, before, after) using AutoPaginatable
  • Added organizations.createOrganizationApiKey with optional idempotency key support
  • Added apiKeys.deleteApiKey for deleting API keys by ID
  • Created comprehensive TypeScript interfaces for CreatedApiKey (includes full value field on creation) and ApiKey (uses obfuscatedValue for listing)
  • Added proper serializers for request/response transformations
  • Comprehensive test coverage including edge cases and pagination options
  • Exported new interfaces via src/index.ts for public API

Confidence Score: 5/5

  • This PR is safe to merge with no issues
  • The implementation follows existing patterns throughout the codebase, includes comprehensive test coverage, properly handles serialization/deserialization, implements pagination correctly, supports idempotency for creation operations, and doesn't introduce security issues. No sensitive data logging detected, and the code adheres to all custom security rules.
  • No files require special attention

Important Files Changed

Filename Overview
src/api-keys/api-keys.ts Added deleteApiKey method following existing patterns, properly uses REST DELETE endpoint
src/organizations/organizations.ts Added listOrganizationApiKeys and createOrganizationApiKey methods with proper serialization, pagination, and idempotency support
src/organizations/organizations.spec.ts Comprehensive test coverage for new API key methods including pagination options and idempotency key handling
src/api-keys/interfaces/created-api-key.interface.ts Defines interfaces for created API key with both camelCase and snake_case variants for proper serialization
src/api-keys/serializers/created-api-key.serializer.ts Properly deserializes API response from snake_case to camelCase following codebase conventions

Sequence Diagram

sequenceDiagram
    participant Client
    participant Organizations
    participant ApiKeys
    participant WorkOS
    participant API

    Note over Client,API: List Organization API Keys
    Client->>Organizations: listOrganizationApiKeys(options)
    Organizations->>WorkOS: fetchAndDeserialize(GET /organizations/:id/api_keys)
    WorkOS->>API: GET /organizations/:id/api_keys
    API-->>WorkOS: SerializedApiKey[]
    WorkOS->>WorkOS: deserializeApiKey()
    WorkOS-->>Organizations: ApiKey[]
    Organizations-->>Client: AutoPaginatable<ApiKey>

    Note over Client,API: Create Organization API Key
    Client->>Organizations: createOrganizationApiKey(options, requestOptions)
    Organizations->>Organizations: serializeCreateOrganizationApiKeyOptions()
    Organizations->>WorkOS: post(POST /organizations/:id/api_keys, payload)
    WorkOS->>API: POST /organizations/:id/api_keys
    API-->>WorkOS: SerializedCreatedApiKey (with value)
    WorkOS->>WorkOS: deserializeCreatedApiKey()
    WorkOS-->>Organizations: CreatedApiKey
    Organizations-->>Client: CreatedApiKey (with full API key value)

    Note over Client,API: Delete API Key
    Client->>ApiKeys: deleteApiKey(id)
    ApiKeys->>WorkOS: delete(DELETE /api_keys/:id)
    WorkOS->>API: DELETE /api_keys/:id
    API-->>WorkOS: 204 No Content
    WorkOS-->>ApiKeys: void
    ApiKeys-->>Client: void
Loading

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

14 files reviewed, no comments

Edit Code Review Agent Settings | Greptile

@stanleyphu stanleyphu merged commit fc9f6fe into main Jan 6, 2026
7 checks passed
@stanleyphu stanleyphu deleted the feat/auth-5677-add-api-keys-management-api branch January 6, 2026 22:26
@stanleyphu stanleyphu mentioned this pull request Jan 6, 2026
stanleyphu added a commit that referenced this pull request Jan 7, 2026
## Description

Includes:
- #1434 
- #1433
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants