Create Taxonomy

Create a new taxonomy to organize categories and control access through roles and languages.

Endpoint

POST /v1/workspaces/{workspaceId}/taxonomy

Authentication

This endpoint requires a Bearer token obtained through the two-step authentication flow:

  1. First, generate an access token using your API key
  2. Use that access token in the Authorization header

See Authentication for the complete authentication flow.

Request

# Step 1: Generate access token (do this once, reuse for multiple requests)
ACCESS_TOKEN=$(curl -s -X POST \
  'https://api.sharely.ai/workspaces/{workspaceId}/generate-access-key-token' \
  -H 'Content-Type: application/json' \
  -H 'x-api-key: sk-sharely-your-api-key' \
  -d '{}' | jq -r '.token')
 
# Step 2: Create taxonomy using the access token
curl -X POST \
  'https://api.sharely.ai/v1/workspaces/{workspaceId}/taxonomy' \
  -H "Authorization: Bearer $ACCESS_TOKEN" \
  -H 'Content-Type: application/json' \
  -H 'organizationid: your-organization-id' \
  -d '{
    "name": "Medical Knowledge Taxonomy",
    "description": "Organized medical knowledge by specialty"
  }'

Path Parameters

ParameterTypeRequiredDescription
workspaceIdstring (UUID)YesThe unique identifier of the workspace

Headers

HeaderTypeRequiredDescription
AuthorizationstringYesBearer token with access token
organizationidstring (UUID)YesYour organization ID
Content-TypestringYesMust be application/json

Body Parameters

ParameterTypeRequiredDescription
namestringYesTaxonomy name
descriptionstringNoTaxonomy description

Response

Success Response (201 Created)

{
  "id": "taxonomy-uuid",
  "workspaceId": "workspace-uuid",
  "name": "Medical Knowledge Taxonomy",
  "description": "Organized medical knowledge by specialty",
  "published": false,
  "createdAt": "2024-11-14T15:30:00Z",
  "updatedAt": "2024-11-14T15:30:00Z"
}

Response Fields

FieldTypeDescription
idstring (UUID)Taxonomy unique identifier
workspaceIdstring (UUID)Parent workspace ID
namestringTaxonomy name
descriptionstringTaxonomy description
publishedbooleanPublication status (always false for new taxonomies)
createdAtstring (ISO 8601)Creation timestamp
updatedAtstring (ISO 8601)Last update timestamp

Example Usage

const fetch = require('node-fetch');
 
const API_KEY = 'sk-sharely-your-api-key';
const WORKSPACE_ID = 'your-workspace-id';
const ORGANIZATION_ID = 'your-organization-id';
const API_BASE_URL = 'https://api.sharely.ai';
 
// Step 1: Generate access token
async function getAccessToken() {
  const response = await fetch(
    `${API_BASE_URL}/workspaces/${WORKSPACE_ID}/generate-access-key-token`,
    {
      method: 'POST',
      headers: {
        'Content-Type': 'application/json',
        'x-api-key': API_KEY
      },
      body: JSON.stringify({})
    }
  );
  const data = await response.json();
  return data.token;
}
 
// Step 2: Create taxonomy
async function createTaxonomy(accessToken, data) {
  const response = await fetch(
    `${API_BASE_URL}/v1/workspaces/${WORKSPACE_ID}/taxonomy`,
    {
      method: 'POST',
      headers: {
        'Authorization': `Bearer ${accessToken}`,
        'Content-Type': 'application/json',
        'organizationid': ORGANIZATION_ID
      },
      body: JSON.stringify(data)
    }
  );
 
  if (!response.ok) {
    throw new Error(`Failed to create taxonomy: ${response.status}`);
  }
 
  return await response.json();
}
 
// Usage
const accessToken = await getAccessToken();
const taxonomy = await createTaxonomy(accessToken, {
  name: 'Medical Knowledge',
  description: 'Medical specialty taxonomy'
});
 
console.log('Created taxonomy:', taxonomy.id);

Next Steps

After creating a taxonomy:

  1. Assign languages to support multilingual content
  2. Assign roles for RBAC
  3. Assign categories to organize content
  4. Publish the taxonomy to make it active

Related Endpoints