Create Tokenset
Creates a new tokenset within a workspace.
PRO Plan Required - This endpoint requires a PRO or TEAM subscription plan. API write access is not available on the FREE plan.
Endpoint
POST /api/v1/workspaces/{id}/tokensets
Authentication
Requires a valid API token in the Authorization header.
Request
| Header | Value | Required |
|---|
Authorization | Bearer token | Yes |
Content-Type | application/json | Yes |
Path Parameters
| Parameter | Type | Required | Description |
|---|
id | string | Yes | Workspace ID |
Body Parameters
| Parameter | Type | Required | Description |
|---|
name | string | Yes | Tokenset name (max 255 characters) |
description | string | No | Optional description |
Request Body
{
"name": "Colors",
"description": "Color tokens for the design system"
}
Response
Success Response
Status: 201 Created
{
"id": "tokenset-123",
"workspace_id": "550e8400-e29b-41d4-a716-446655440000",
"name": "Colors",
"description": "Color tokens for the design system",
"created_at": "2025-01-15T10:00:00Z",
"updated_at": "2025-01-15T10:00:00Z"
}
Examples
curl -X POST https://app.tokencraft.dev/api/v1/workspaces/550e8400-e29b-41d4-a716-446655440000/tokensets \
-H "Authorization: Bearer dtk_your_token_here" \
-H "Content-Type: application/json" \
-d '{
"name": "Colors",
"description": "Color tokens for the design system"
}'
Error Responses
400 Bad Request
{
"error": "Name is required and must be a non-empty string"
}
404 Not Found
{
"error": "Workspace not found"
}
Causes:
- Workspace ID doesn’t exist
- Workspace belongs to a different user
Use Cases
1. Create Multiple Tokensets
const categories = ['Colors', 'Typography', 'Spacing', 'Shadows'];
for (const category of categories) {
await createTokenset(workspaceId, {
name: category,
description: `${category} tokens`
});
}
2. Create with Default Mode
After creating a tokenset, you may want to create modes:
const tokenset = await createTokenset(workspaceId, {
name: 'Colors'
});
// Create light and dark modes
await createMode(tokenset.id, { name: 'Light', is_default: true });
await createMode(tokenset.id, { name: 'Dark' });
Next Steps