> For the complete documentation index, see [llms.txt](https://docs.n8n.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.n8n.io/connect/n8n-api/variables.md).

# Variables

Operations about variables

## Retrieve variables

> Retrieve variables from your instance.

```json
{"openapi":"3.0.0","info":{"title":"n8n Public API","version":"1.1.1"},"tags":[{"name":"Variables","description":"Operations about variables"}],"servers":[{"url":"/api/v1","description":"Current n8n instance (self-hosted built-in playground)"},{"url":"{url}/api/v1","description":"Self-hosted n8n instance","variables":{"url":{"default":"https://example.com"}}}],"security":[{"ApiKeyAuth":[]},{"BearerAuth":[]}],"components":{"securitySchemes":{"ApiKeyAuth":{"type":"apiKey","in":"header","name":"X-N8N-API-KEY"},"BearerAuth":{"type":"http","scheme":"bearer","bearerFormat":"JWT"}},"parameters":{"limit":{"name":"limit","in":"query","description":"The maximum number of items to return.","required":false,"schema":{"type":"number","default":100,"maximum":250}},"cursor":{"name":"cursor","in":"query","description":"Paginate by setting the cursor parameter to the nextCursor attribute returned by the previous request's response. Default value fetches the first \"page\" of the collection. See pagination for more detail.","required":false,"style":"form","schema":{"type":"string"}}},"schemas":{"variableList":{"type":"object","properties":{"data":{"type":"array","items":{"$ref":"#/components/schemas/variable"}},"nextCursor":{"type":"string","description":"Paginate through variables by setting the cursor parameter to a nextCursor attribute returned by a previous request. Default value fetches the first \"page\" of the collection.","nullable":true}}},"variable":{"type":"object","additionalProperties":false,"required":["key","value"],"properties":{"id":{"type":"string","readOnly":true},"key":{"type":"string"},"value":{"type":"string"},"type":{"type":"string","readOnly":true},"project":{"$ref":"#/components/schemas/project"}}},"project":{"type":"object","additionalProperties":false,"required":["name"],"properties":{"id":{"type":"string","readOnly":true},"name":{"type":"string"},"type":{"type":"string","readOnly":true}}}},"responses":{"unauthorized":{"description":"Unauthorized"}}},"paths":{"/variables":{"get":{"tags":["Variables"],"summary":"Retrieve variables","description":"Retrieve variables from your instance.","parameters":[{"$ref":"#/components/parameters/limit"},{"$ref":"#/components/parameters/cursor"},{"name":"projectId","in":"query","required":false,"explode":false,"allowReserved":true,"schema":{"type":"string"}},{"name":"state","in":"query","required":false,"schema":{"type":"string","enum":["empty"]}}],"responses":{"200":{"description":"Operation successful.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/variableList"}}}},"401":{"$ref":"#/components/responses/unauthorized"}}}}}}
```

## Create a variable

> Create a variable in your instance.

```json
{"openapi":"3.0.0","info":{"title":"n8n Public API","version":"1.1.1"},"tags":[{"name":"Variables","description":"Operations about variables"}],"servers":[{"url":"/api/v1","description":"Current n8n instance (self-hosted built-in playground)"},{"url":"{url}/api/v1","description":"Self-hosted n8n instance","variables":{"url":{"default":"https://example.com"}}}],"security":[{"ApiKeyAuth":[]},{"BearerAuth":[]}],"components":{"securitySchemes":{"ApiKeyAuth":{"type":"apiKey","in":"header","name":"X-N8N-API-KEY"},"BearerAuth":{"type":"http","scheme":"bearer","bearerFormat":"JWT"}},"schemas":{"variable.create":{"type":"object","additionalProperties":false,"required":["key","value"],"properties":{"id":{"type":"string","readOnly":true},"key":{"type":"string"},"value":{"type":"string"},"type":{"type":"string","readOnly":true},"projectId":{"type":"string","nullable":true}}}},"responses":{"badRequest":{"description":"The request is invalid or provides malformed data."},"unauthorized":{"description":"Unauthorized"}}},"paths":{"/variables":{"post":{"tags":["Variables"],"summary":"Create a variable","description":"Create a variable in your instance.","requestBody":{"description":"Payload for variable to create.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/variable.create"}}},"required":true},"responses":{"201":{"description":"Operation successful."},"400":{"$ref":"#/components/responses/badRequest"},"401":{"$ref":"#/components/responses/unauthorized"}}}}}}
```

## Update a variable

> Update a variable from your instance.

```json
{"openapi":"3.0.0","info":{"title":"n8n Public API","version":"1.1.1"},"tags":[{"name":"Variables","description":"Operations about variables"}],"servers":[{"url":"/api/v1","description":"Current n8n instance (self-hosted built-in playground)"},{"url":"{url}/api/v1","description":"Self-hosted n8n instance","variables":{"url":{"default":"https://example.com"}}}],"security":[{"ApiKeyAuth":[]},{"BearerAuth":[]}],"components":{"securitySchemes":{"ApiKeyAuth":{"type":"apiKey","in":"header","name":"X-N8N-API-KEY"},"BearerAuth":{"type":"http","scheme":"bearer","bearerFormat":"JWT"}},"parameters":{"variableId":{"name":"id","in":"path","description":"The ID of the variable.","required":true,"schema":{"type":"string"}}},"schemas":{"variable.create":{"type":"object","additionalProperties":false,"required":["key","value"],"properties":{"id":{"type":"string","readOnly":true},"key":{"type":"string"},"value":{"type":"string"},"type":{"type":"string","readOnly":true},"projectId":{"type":"string","nullable":true}}}},"responses":{"badRequest":{"description":"The request is invalid or provides malformed data."},"unauthorized":{"description":"Unauthorized"},"forbidden":{"description":"Forbidden"},"notFound":{"description":"The specified resource was not found."}}},"paths":{"/variables/{id}":{"put":{"tags":["Variables"],"summary":"Update a variable","description":"Update a variable from your instance.","parameters":[{"$ref":"#/components/parameters/variableId"}],"requestBody":{"description":"Payload for variable to update.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/variable.create"}}},"required":true},"responses":{"204":{"description":"Operation successful."},"400":{"$ref":"#/components/responses/badRequest"},"401":{"$ref":"#/components/responses/unauthorized"},"403":{"$ref":"#/components/responses/forbidden"},"404":{"$ref":"#/components/responses/notFound"}}}}}}
```

## Delete a variable

> Delete a variable from your instance.

```json
{"openapi":"3.0.0","info":{"title":"n8n Public API","version":"1.1.1"},"tags":[{"name":"Variables","description":"Operations about variables"}],"servers":[{"url":"/api/v1","description":"Current n8n instance (self-hosted built-in playground)"},{"url":"{url}/api/v1","description":"Self-hosted n8n instance","variables":{"url":{"default":"https://example.com"}}}],"security":[{"ApiKeyAuth":[]},{"BearerAuth":[]}],"components":{"securitySchemes":{"ApiKeyAuth":{"type":"apiKey","in":"header","name":"X-N8N-API-KEY"},"BearerAuth":{"type":"http","scheme":"bearer","bearerFormat":"JWT"}},"parameters":{"variableId":{"name":"id","in":"path","description":"The ID of the variable.","required":true,"schema":{"type":"string"}}},"responses":{"unauthorized":{"description":"Unauthorized"},"notFound":{"description":"The specified resource was not found."}}},"paths":{"/variables/{id}":{"delete":{"tags":["Variables"],"summary":"Delete a variable","description":"Delete a variable from your instance.","parameters":[{"$ref":"#/components/parameters/variableId"}],"responses":{"204":{"description":"Operation successful."},"401":{"$ref":"#/components/responses/unauthorized"},"404":{"$ref":"#/components/responses/notFound"}}}}}}
```
