Variable API
VariableClient manages n8n environment variables.
Access
const variable = client.variables();
Methods
list(params?)
List variables with optional filters.
const { data, nextCursor } = await client.variables().list({
limit: 50,
projectId: 'proj-1',
state: 'empty',
});
get(id, params?)
Get a variable by ID. The n8n API has no direct GET /variables/{id} endpoint, so this method paginates through all results to find the matching variable. On instances with many variables this is an O(n) scan across pages.
const variable = await client.variables().get('var-123', { projectId: 'proj-1' });
create(data)
Create a new variable.
await client.variables().create({
key: 'MY_API_KEY',
value: 'secret-value',
projectId: 'proj-1',
});
update(id, data)
Update a variable.
await client.variables().update('var-123', {
key: 'MY_API_KEY',
value: 'new-value',
});
delete(id)
Delete a variable.
await client.variables().delete('var-123');
VariableResource
Use getResource() or listResources() to get a bound VariableResource instance.
const resource = await client.variables().getResource('var-123', { projectId: 'proj-1' });
Properties
| Property | Type | Description |
|---|---|---|
id | string | Variable ID |
key | string | Variable key |
value | string | Variable value |
Methods
| Method | Returns | Description |
|---|---|---|
refresh() | this | Re-fetch the variable from the API via paginated list |
update(data) | this | Update the variable — merges local snapshot |
patch(data) | this | Convenience update — merges partial fields into the current variable snapshot before updating |
delete() | void | Delete the variable |
Snapshot management
refresh() calls replaceSnapshot() with the fresh variable data. update() and patch() call mergeSnapshot() locally since the n8n API returns no body on update.