跳转到内容

Variable Collections

管理变量集合——设计令牌的文档级 API。

Type reference
// Variable collections group design tokens and define their modes (e.g. Light/Dark, Desktop/Mobile).
// All ID params accept both IDs and display names.
// ---
// valuesByMode: values keyed by mode name, e.g. {"Light": "#FFF", "Dark": "#111"}.
// Aliases in variable values use {type: "VARIABLE_ALIAS", name: "other/variable"}.
// Paint[] VariableAlias uses {type:"VARIABLE_ALIAS", id:"<VariableID>"}; variable_collections.get includes each variable id. Prefer *VariableName helpers when available.
// scopes: see variables endpoint for full list.
// Deleting a collection deletes all variables inside it.
// The default mode cannot be removed. Use add_mode/remove_mode for additional modes.
// Shared types:
// Color: hex "#RGB"|"#RGBA"|"#RRGGBB"|"#RRGGBBAA" or {r: 0-1, g: 0-1, b: 0-1, a?: 0-1}
// VariableAlias: {type: "VARIABLE_ALIAS", id: string}. The id must be a Figma VariableID; discover it via variables.get/list or variable_collections.get. Prefer colorVariableName/fillVariableName/strokeVariableName when available; Paint[] VariableAlias is mainly for precise Paint[] round-trips and gradient stop bindings.
// Transform: [[number, number, number], [number, number, number]] (Figma Plugin API 2×3 matrix)
// BlendMode: "PASS_THROUGH"|"NORMAL"|"DARKEN"|"MULTIPLY"|"LINEAR_BURN"|"COLOR_BURN"|"LIGHTEN"|"SCREEN"|"LINEAR_DODGE"|"COLOR_DODGE"|"OVERLAY"|"SOFT_LIGHT"|"HARD_LIGHT"|"DIFFERENCE"|"EXCLUSION"|"HUE"|"SATURATION"|"COLOR"|"LUMINOSITY"
// ColorStop: {position: 0-1, color: Color, boundVariables?: {color?: VariableAlias}}
// GradientPaint: {type: "GRADIENT_LINEAR"|"GRADIENT_RADIAL"|"GRADIENT_ANGULAR"|"GRADIENT_DIAMOND", gradientTransform: Transform, gradientStops: ColorStop[], visible?: boolean, opacity?: number, blendMode?: BlendMode}. Use gradientTransform + gradientStops (basic left-to-right: [[1,0,0],[0,1,0]]); do not use CSS gradients or REST gradientHandlePositions.
// Paint: Paint[] authoring accepts only SOLID and GRADIENT_LINEAR/GRADIENT_RADIAL/GRADIENT_ANGULAR/GRADIENT_DIAMOND. SolidPaint: {type: "SOLID", color: Color, visible?: boolean, opacity?: number, blendMode?: BlendMode, boundVariables?: {color?: VariableAlias}}. GradientPaint authoring: {type: GRADIENT_*, gradientTransform: Transform, gradientStops: ColorStop[], visible?, opacity?, blendMode?}; bind variables on gradientStops[].boundVariables.color, not top-level gradient boundVariables. Do not pass IMAGE/VIDEO/PATTERN to create/update Paint[]; those may appear only in readback metadata from existing Figma content. Use imageUrl/images for image authoring. VIDEO/PATTERN authoring is not supported here. Do not use CSS gradients or REST gradientHandlePositions.

8 methods available.

List variable collections

ParameterTypeRequiredDescription
fieldsstring[]Property whitelist. Identity fields (id, name, type) always included. Omit for stubs on list, full on get. Pass ["*"] for all.
offsetnumberSkip N items for pagination (default 0) (default: 0)
limitnumberMax items per page (default 100) (default: 100)

Response

FieldTypeDescription
totalCountnumberTotal matching items
returnednumberItems in this page
offsetnumber
limitnumber
itemsobject[]
idstring
namestring
modesstring[]Mode names
variableCountnumberNumber of variables

Get collection with all variables and values (full document)

ParameterTypeRequiredDescription
idstringCollection ID or name
fieldsstring[]Property whitelist. Identity fields (id, name, type) always included. Omit for stubs on list, full on get. Pass ["*"] for all.

Response

FieldTypeDescription
idstring
namestring
modesstring[]Mode names (e.g. ['Light', 'Dark'])
variablesobject[]All variables in this collection
idstringFigma VariableID. Use as VariableAlias.id in Paint[] when needed.
namestring
typestringCOLOR | FLOAT | STRING | BOOLEAN
valuesByModeobjectValues keyed by mode name
scopesstring[]
descriptionstring

Create a collection with modes and variables in one call

Example

variable_collections(method:"create", items:[{name:"Tokens", variables:[{name:"bg/canvas", type:"COLOR", value:"#F7F8FA", scopes:["ALL_FILLS"]}, {name:"bg/surface", type:"COLOR", value:"#FFFFFF", scopes:["ALL_FILLS"]}, {name:"bg/accent", type:"COLOR", value:"#2563EB", scopes:["ALL_FILLS"]}, {name:"bg/muted", type:"COLOR", value:"#E5E7EB", scopes:["ALL_FILLS"]}, {name:"text/primary", type:"COLOR", value:"#111827", scopes:["TEXT_FILL"]}, {name:"text/secondary", type:"COLOR", value:"#4B5563", scopes:["TEXT_FILL"]}, {name:"text/inverse", type:"COLOR", value:"#FFFFFF", scopes:["TEXT_FILL"]}, {name:"border/subtle", type:"COLOR", value:"#D1D5DB", scopes:["STROKE_COLOR"]}, {name:"icon/primary", type:"COLOR", value:{type:"VARIABLE_ALIAS", name:"text/primary"}, scopes:["ALL_FILLS","STROKE_COLOR"]}, {name:"status/success", type:"COLOR", value:"#16A34A", scopes:["ALL_FILLS"]}, {name:"space/8", type:"FLOAT", value:8, scopes:["GAP"]}, {name:"space/12", type:"FLOAT", value:12, scopes:["GAP"]}, {name:"space/16", type:"FLOAT", value:16, scopes:["GAP"]}, {name:"space/24", type:"FLOAT", value:24, scopes:["GAP"]}, {name:"radius/8", type:"FLOAT", value:8, scopes:["CORNER_RADIUS"]}, {name:"radius/12", type:"FLOAT", value:12, scopes:["CORNER_RADIUS"]}, {name:"radius/16", type:"FLOAT", value:16, scopes:["CORNER_RADIUS"]}, {name:"stroke/1", type:"FLOAT", value:1, scopes:["STROKE_FLOAT"]}]}])
ParameterTypeRequiredDescription
itemsobject[]Array of collection documents
namestringCollection name
modesstring[]Mode names (e.g. ['Light', 'Dark']). Omit for single-mode collection.
variablesobject[]Variables to create inside this collection
namestringVariable name (unique within collection)
type"COLOR" | "FLOAT" | "STRING" | "BOOLEAN"Variable type
valueanySets all modes to this value. Use valuesByMode for per-mode control.
valuesByModeobjectValues keyed by mode name (e.g. {"Light": "#FFF", "Dark": "#111"})
descriptionstring
scopesstring[]Restrict where variable can be applied (default: ALL_SCOPES)

Response

FieldTypeDescription
resultsobject[]One entry per input item
idstring

Rename collections

ParameterTypeRequiredDescription
itemsobject[]Array of {id, name}
idstringCollection ID or name
namestringNew name

Response

FieldTypeDescription
resultsany[]Array of "ok" or {error} per item

Delete collections

ParameterTypeRequiredDescription
idstringCollection ID or name
itemsobject[]Batch: [{id}, ...]
idstring

Response

FieldTypeDescription
resultsstring[]Array of "ok" per item

Add a mode to a collection

ParameterTypeRequiredDescription
itemsobject[]Array of {collectionId, name}
collectionIdstringCollection ID or name
namestringMode name

Response

FieldTypeDescription
resultsobject[]One entry per input item
modeIdstring

Rename a mode

ParameterTypeRequiredDescription
itemsobject[]Array of {collectionId, modeId, name}
collectionIdstringCollection ID or name
modeIdstringMode ID or name (e.g. "Dark")
namestringNew name

Response

FieldTypeDescription
resultsany[]Array of "ok" or {error} per item

Remove a mode from a collection

ParameterTypeRequiredDescription
itemsobject[]Array of {collectionId, modeId}
collectionIdstringCollection ID or name
modeIdstringMode ID or name (e.g. "Dark")

Response

FieldTypeDescription
resultsstring[]Array of "ok" per item