跳转到内容

Variables

搜索和更新集合中的设计变量。

Type reference
// Search and update variables within a collection. collectionId is required on all methods.
// Use variable_collections to create full token sets (collection + modes + variables in one call).
// ---
// query: prefix match first, then substring. "bg/" matches bg/canvas, bg/surface, etc.
// valuesByMode: values keyed by mode name. On create, value sets all modes; on update, value sets the default mode only.
// Aliases in variable values use {type: "VARIABLE_ALIAS", name: "other/variable"}.
// Paint[] VariableAlias uses {type:"VARIABLE_ALIAS", id:"<VariableID>"}; get IDs from variables.get/list or variable_collections.get. Prefer *VariableName helpers when available.
// scopes: ALL_SCOPES, TEXT_CONTENT, WIDTH_HEIGHT, GAP, CORNER_RADIUS, ALL_FILLS, FRAME_FILL, SHAPE_FILL,
// TEXT_FILL, STROKE_COLOR, STROKE_FLOAT, EFFECT_FLOAT, EFFECT_COLOR, OPACITY, FONT_FAMILY, FONT_STYLE,
// FONT_WEIGHT, FONT_SIZE, LINE_HEIGHT, LETTER_SPACING, PARAGRAPH_SPACING, PARAGRAPH_INDENT
// 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.

5 methods available.

Search variables within a collection

Example

variables(method:"list", collectionId:"Tokens", query:"bg/")
ParameterTypeRequiredDescription
collectionIdstringCollection ID or name
querystringSearch query — prefix match first, then substring fallback
type"COLOR" | "FLOAT" | "STRING" | "BOOLEAN"Filter by variable type
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[]
idstringFigma VariableID. Use as VariableAlias.id in Paint[] when needed.
namestring
typestringCOLOR | FLOAT | STRING | BOOLEAN
valuesByModeobjectValues keyed by mode name
scopesstring[]
descriptionstring

Get variable detail by name

ParameterTypeRequiredDescription
namestringVariable name (unique within collection)
collectionIdstringCollection 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
idstringFigma VariableID. Use as VariableAlias.id in Paint[] when needed.
namestring
type"COLOR" | "FLOAT" | "STRING" | "BOOLEAN"
collectionIdstringCollection display name
valuesByModeobjectValues keyed by mode name (e.g. "Light", "Dark")
descriptionstringVariable description
scopesstring[]Where this variable can be applied

Create variables in a collection. Use valuesByMode for per-mode control, or value to set all modes at once.

Example

variables(method:"create", collectionId:"Tokens", items:[{name:"bg/warning", type:"COLOR", value:"#F59E0B", scopes:["ALL_FILLS"]}])
ParameterTypeRequiredDescription
collectionIdstringCollection ID or name
itemsobject[]Array of variables to create
namestringVariable name (must be 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"}). Takes precedence over value.
descriptionstringVariable description
scopesstring[]Restrict where variable can be applied (default: ALL_SCOPES)

Response

FieldTypeDescription
resultsobject[]One entry per input item
idstringFigma VariableID. Use as VariableAlias.id in Paint[] when needed.
namestringName of the created variable

Update variable metadata and/or set values

Example

variables(method:"update", collectionId:"Tokens", items:[{name:"bg/accent", value:"#1D4ED8"}])
ParameterTypeRequiredDescription
collectionIdstringCollection ID or name
itemsobject[]Array of variable updates
namestringVariable name
renamestringRename the variable
descriptionstringSet description
scopesstring[]Update scopes
valueanyShorthand — sets the default mode value. Use valuesByMode for multi-mode.
valuesByModeobjectValues keyed by mode name. Takes precedence over value.

Response

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

Delete variables

ParameterTypeRequiredDescription
collectionIdstringCollection ID or name
namestringVariable name
itemsobject[]Batch: [{name}, ...]
namestring

Response

FieldTypeDescription
resultsstring[]Array of "ok" per item