Skip to content

createEnum

The createEnum function creates a new Enum model: a closed list of string values that entity fields of type enum can reference. It is the JavaScript/TypeScript counterpart of the POST /model/enum REST endpoint.

Example:

const { id } = await client.createEnum({
name: 'Size',
values: [{ value: 'S' }, { value: 'M' }, { value: 'L' }],
});
console.log(id);
// Then reference it from an entity field:
await client.createModel({
name: 'Shirt',
fieldList: [{ name: 'size', type: 'enum', relatedModelId: id }],
});

Interface

export interface ApiClient {
createEnum: (params: CreateEnumParams) => Promise<SaveModelResponse>;
// ... other methods
}
export interface CreateEnumParams {
name: string;
values: Array<{ id?: string; value: string }>;
}
export interface SaveModelResponse {
id: string;
}

Parameters

NameDescription
nameThe enum name. Same name rules as a model name, unique across the project.
valuesThe enum values, in order. At least one is required, unique within the enum (case-insensitive). Omit id when creating.

Output

Returns a Promise<SaveModelResponse> resolving to { id } — use it as the relatedModelId of an enum field. On failure it throws a typed ApiClientError (e.g. VALIDATION_ERROR).