Files
n8n-docs/docs/source-control-environments/using/manage-variables.md
Deborah Barnard 2a7a66ec2a wip
2023-07-04 23:04:35 +01:00

1.7 KiB

title, description
title description
Manage variables Manage variable values in n8n using the API and source control.

Manage variables

n8n doesn't sync variable values with Git. You must set up the credentials manually when setting up a new instance. You can choose to set up variables manually, or using the API.

Manage variables using the API

n8n syncs variable names, but doesn't push variable values to your Git provider. You can either:

  • Manually set variable values in n8n.
  • Set variable values using the n8n API, using the /pull endpoint.

Managing variables using the API has several advantages:

  • You can automatically update variable values using a CI (continuous integration) tool.
  • You may also be able to protect the values.

For example, you can store values in GitHub secrets{:target=_blank .external-link}, then populate the variables in n8n using an API call from a GitHub Action{:target=_blank .external-link}.

To manage variables using an API call, make a POST request to /source-control/pull:

	curl --location '<YOUR-INSTANCE-URL>/api/v1/source-control/pull' \
	--header 'Content-Type: application/json' \
	--header 'X-N8N-API-KEY: <YOUR-API-KEY>' \
	--data '{
	"force": true,
	"variables": { 
			"key1": "value1",
			"key2": "value2"
	}
	}
	'

If the key already exists in n8n, the API call updates the value. If there is no variable with the key, it creates a new variable.

After setting values using the API, you can safely edit variables in n8n, and push and pull changes.