Schemas
Vertical metadata schema definitions. Schemas allow you to define custom metadata structures for assets within specific verticals, providing type validation and standardization across your organization.
Methods​
| Method (TypeScript) | Method (Python) | Description | HTTP |
|---|---|---|---|
create(schema) | create(schema) | Create new schema | POST /schemas |
get(schemaId) | get(schema_id) | Retrieve schema by ID | GET /schemas/{id} |
list(options?) | list(options=None) | List schemas | GET /schemas |
update(schemaId, schema) | update(schema_id, schema) | Update schema definition | PATCH /schemas/{id} |
delete(schemaId) | delete(schema_id) | Delete schema | DELETE /schemas/{id} |
validate(schemaId, data) | validate(schema_id, data) | Validate data against schema | POST /schemas/{id}/validate |
Example​
- TypeScript
- Python
import { OptropicClient } from 'optropic';
const client = new OptropicClient({ apiKey: 'optr_live_...' });
// Create a schema for electronics vertical
const schema = await client.schemas.create({
name: 'Electronics Product',
vertical: 'electronics',
fields: [
{ name: 'sku', type: 'string', required: true },
{ name: 'manufacturer', type: 'string', required: true },
{ name: 'warranty_months', type: 'number', required: false },
{ name: 'certifications', type: 'array', items: 'string' }
]
});
// Validate data against schema
const validation = await client.schemas.validate(
schema.id,
{ sku: 'SKU-123', manufacturer: 'TechCorp' }
);
console.log(`Valid: ${validation.isValid}`);
from optropic import Optropic
client = Optropic(api_key="optr_live_...")
# Create a schema for electronics vertical
schema = client.schemas.create({
'name': 'Electronics Product',
'vertical': 'electronics',
'fields': [
{'name': 'sku', 'type': 'string', 'required': True},
{'name': 'manufacturer', 'type': 'string', 'required': True},
{'name': 'warranty_months', 'type': 'number', 'required': False},
{'name': 'certifications', 'type': 'array', 'items': 'string'}
]
})
# Validate data against schema
validation = client.schemas.validate(
schema['id'],
{'sku': 'SKU-123', 'manufacturer': 'TechCorp'}
)
print(f"Valid: {validation['isValid']}")