• Blog
  • Docs
  • Pricing
  • We’re hiring!
Log inSign up
nholden

nholden

workos-create-org

Public
Like
1
workos-create-org
Home
Code
3
README.md
H
index.ts
main.tsx
Branches
1
Pull requests
Remixes
History
Environment variables
1
Val Town is a collaborative website to build and scale JavaScript apps.
Deploy APIs, crons, & store data – all from the browser, and deployed in milliseconds.
Sign up now
Code
/
README.md
Code
/
README.md
Search
6/30/2025
Viewing readonly version of main branch: v6
View latest version
README.md

WorkOS Organization Creator

This Val provides an HTTP endpoint for creating organizations and organization memberships in WorkOS with JWT authentication.

Features

  • JWT Authentication: Validates WorkOS JWTs using JWKS
  • Organization Creation: Creates new organizations in WorkOS
  • Membership Management: Automatically creates admin membership for the authenticated user
  • Error Handling: Comprehensive error handling for WorkOS API and JWT validation

Endpoints

POST /create-organization

Creates a new organization and organization membership for the authenticated user.

Authentication: Bearer token (WorkOS JWT)

Request Body:

{ "name": "Organization Name", "domains": ["example.com"] // optional }

Response:

{ "organization": { "id": "org_123", "name": "Organization Name", "domains": ["example.com"], "createdAt": "2023-01-01T00:00:00.000Z", "updatedAt": "2023-01-01T00:00:00.000Z" }, "membership": { "id": "om_456", "userId": "user_789", "organizationId": "org_123", "role": "admin", "status": "active" } }

GET /health

Health check endpoint.

Response:

{ "status": "ok", "timestamp": "2023-01-01T00:00:00.000Z" }

Environment Variables

The following environment variables must be configured in Val Town:

  • WORKOS_API_KEY: Your WorkOS API key (starts with sk_)
  • JWKS_URL: The JWKS URL for JWT verification (e.g., https://api.workos.com/sso/jwks/{connection_id})

Usage Example

// Client-side usage const response = await fetch('https://your-val-url.web.val.run/create-organization', { method: 'POST', headers: { 'Authorization': `Bearer ${workosJWT}`, 'Content-Type': 'application/json' }, body: JSON.stringify({ name: 'My New Organization', domains: ['mycompany.com'] }) }); const result = await response.json(); console.log('Created organization:', result.organization);

Error Responses

The API returns appropriate HTTP status codes and error messages:

  • 400: Bad request (missing organization name, WorkOS API errors)
  • 401: Unauthorized (missing/invalid JWT token)
  • 500: Internal server error (configuration issues, unexpected errors)

Security

  • JWT tokens are verified using JWKS from WorkOS
  • Only authenticated users can create organizations
  • Users are automatically assigned admin role in organizations they create
  • All WorkOS API calls are made server-side to protect API keys

Development

To test the endpoint locally, ensure you have:

  1. Valid WorkOS API key set in environment variables
  2. Proper JWKS URL configured
  3. Valid WorkOS JWT token for testing

The health endpoint can be used to verify the service is running without authentication.

FeaturesVersion controlCode intelligenceCLIMCP
Use cases
TeamsAI agentsSlackGTM
DocsShowcaseTemplatesNewestTrendingAPI examplesNPM packages
PricingNewsletterBlogAboutCareers
We’re hiring!
Brandhi@val.townStatus
X (Twitter)
Discord community
GitHub discussions
YouTube channel
Bluesky
Open Source Pledge
Terms of usePrivacy policyAbuse contact
© 2026 Val Town, Inc.