Skip to contentSkip to navigationSkip to topbar
On this page

Variable


Variables are key/value pairs that you can add to a specific Environment. Use these for storing configuration like API keys rather than hardcoding them into your Functions. Environment Variables are encrypted, so they are the preferred way to store API keys, passwords, and any other secrets that your Function needs to use.


Variable Properties

variable-properties page anchor
Property nameTypeRequiredDescriptionChild properties
sidSID<ZV>

Optional

Not PII

The unique string that we created to identify the Variable resource.

Pattern: ^ZV[0-9a-fA-F]{32}$Min length: 34Max length: 34

account_sidSID<AC>

Optional

The SID of the Account that created the Variable resource.

Pattern: ^AC[0-9a-fA-F]{32}$Min length: 34Max length: 34

service_sidSID<ZS>

Optional

The SID of the Service that the Variable resource is associated with.

Pattern: ^ZS[0-9a-fA-F]{32}$Min length: 34Max length: 34

environment_sidSID<ZE>

Optional

The SID of the Environment in which the Variable exists.

Pattern: ^ZE[0-9a-fA-F]{32}$Min length: 34Max length: 34

keystring

Optional

PII MTL: 7 days

A string by which the Variable resource can be referenced.


valuestring

Optional

A string that contains the actual value of the Variable.


date_updatedstring<date-time>

Optional

The date and time in GMT when the Variable resource was last updated specified in ISO 8601(link takes you to an external page) format.


urlstring<uri>

Optional

The absolute URL of the Variable resource.


Create a Variable resource

create-a-variable-resource page anchor
POST https://serverless.twilio.com/v1/Services/{ServiceSid}/Environments/{EnvironmentSid}/Variables

Path parameters

path-parameters page anchor
Property nameTypeRequiredPIIDescription
ServiceSidstringrequired

The SID of the Service to create the Variable resource under.


EnvironmentSidSID<ZE>required

The SID of the Environment in which the Variable resource exists.

Pattern: ^ZE[0-9a-fA-F]{32}$Min length: 34Max length: 34
Encoding type:application/x-www-form-urlencoded
SchemaExample
Property nameTypeRequiredDescriptionChild properties
Keystringrequired

A string by which the Variable resource can be referenced. It can be a maximum of 128 characters.


Valuestringrequired

A string that contains the actual value of the Variable. It can be a maximum of 450 bytes in size.

Create a VariableLink to code sample: Create a Variable
1
// Download the helper library from https://www.twilio.com/docs/node/install
2
const twilio = require("twilio"); // Or, for ESM: import twilio from "twilio";
3
4
// Find your Account SID and Auth Token at twilio.com/console
5
// and set the environment variables. See http://twil.io/secure
6
const accountSid = process.env.TWILIO_ACCOUNT_SID;
7
const authToken = process.env.TWILIO_AUTH_TOKEN;
8
const client = twilio(accountSid, authToken);
9
10
async function createVariable() {
11
const variable = await client.serverless.v1
12
.services("ServiceSid")
13
.environments("ZEaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")
14
.variables.create({
15
key: "Key",
16
value: "Value",
17
});
18
19
console.log(variable.sid);
20
}
21
22
createVariable();

Output

1
{
2
"sid": "ZV00000000000000000000000000000000",
3
"account_sid": "ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
4
"service_sid": "ServiceSid",
5
"environment_sid": "ZEaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
6
"key": "Key",
7
"value": "Value",
8
"date_created": "2018-11-10T20:00:00Z",
9
"date_updated": "2018-11-10T20:00:00Z",
10
"url": "https://serverless.twilio.com/v1/Services/ZS00000000000000000000000000000000/Environments/ZE00000000000000000000000000000000/Variables/ZV00000000000000000000000000000000"
11
}

Fetch a Variable resource

fetch-a-variable-resource page anchor
GET https://serverless.twilio.com/v1/Services/{ServiceSid}/Environments/{EnvironmentSid}/Variables/{Sid}

Property nameTypeRequiredPIIDescription
ServiceSidstringrequired

The SID of the Service to fetch the Variable resource from.


EnvironmentSidSID<ZE>required

The SID of the Environment with the Variable resource to fetch.

Pattern: ^ZE[0-9a-fA-F]{32}$Min length: 34Max length: 34

SidSID<ZV>required

The SID of the Variable resource to fetch.

Pattern: ^ZV[0-9a-fA-F]{32}$Min length: 34Max length: 34
1
// Download the helper library from https://www.twilio.com/docs/node/install
2
const twilio = require("twilio"); // Or, for ESM: import twilio from "twilio";
3
4
// Find your Account SID and Auth Token at twilio.com/console
5
// and set the environment variables. See http://twil.io/secure
6
const accountSid = process.env.TWILIO_ACCOUNT_SID;
7
const authToken = process.env.TWILIO_AUTH_TOKEN;
8
const client = twilio(accountSid, authToken);
9
10
async function fetchVariable() {
11
const variable = await client.serverless.v1
12
.services("ServiceSid")
13
.environments("ZEaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")
14
.variables("ZVaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")
15
.fetch();
16
17
console.log(variable.sid);
18
}
19
20
fetchVariable();

Output

1
{
2
"sid": "ZVaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
3
"account_sid": "ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
4
"service_sid": "ServiceSid",
5
"environment_sid": "ZEaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
6
"key": "test-key",
7
"value": "test-value",
8
"date_created": "2018-11-10T20:00:00Z",
9
"date_updated": "2018-11-10T20:00:00Z",
10
"url": "https://serverless.twilio.com/v1/Services/ZS00000000000000000000000000000000/Environments/ZE00000000000000000000000000000000/Variables/ZV00000000000000000000000000000000"
11
}

Read multiple Variable resources

read-multiple-variable-resources page anchor
GET https://serverless.twilio.com/v1/Services/{ServiceSid}/Environments/{EnvironmentSid}/Variables

Property nameTypeRequiredPIIDescription
ServiceSidstringrequired

The SID of the Service to read the Variable resources from.


EnvironmentSidSID<ZE>required

The SID of the Environment with the Variable resources to read.

Pattern: ^ZE[0-9a-fA-F]{32}$Min length: 34Max length: 34
Property nameTypeRequiredPIIDescription
PageSizeinteger

Optional

How many resources to return in each list page. The default is 50, and the maximum is 1000.

Minimum: 1Maximum: 1000

Pageinteger

Optional

The page index. This value is simply for client state.

Minimum: 0

PageTokenstring

Optional

The page token. This is provided by the API.

1
// Download the helper library from https://www.twilio.com/docs/node/install
2
const twilio = require("twilio"); // Or, for ESM: import twilio from "twilio";
3
4
// Find your Account SID and Auth Token at twilio.com/console
5
// and set the environment variables. See http://twil.io/secure
6
const accountSid = process.env.TWILIO_ACCOUNT_SID;
7
const authToken = process.env.TWILIO_AUTH_TOKEN;
8
const client = twilio(accountSid, authToken);
9
10
async function listVariable() {
11
const variables = await client.serverless.v1
12
.services("ServiceSid")
13
.environments("ZEaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")
14
.variables.list({ limit: 20 });
15
16
variables.forEach((v) => console.log(v.sid));
17
}
18
19
listVariable();

Output

1
{
2
"variables": [],
3
"meta": {
4
"first_page_url": "https://serverless.twilio.com/v1/Services/ZS00000000000000000000000000000000/Environments/ZE00000000000000000000000000000000/Variables?PageSize=50&Page=0",
5
"key": "variables",
6
"next_page_url": null,
7
"page": 0,
8
"page_size": 50,
9
"previous_page_url": null,
10
"url": "https://serverless.twilio.com/v1/Services/ZS00000000000000000000000000000000/Environments/ZE00000000000000000000000000000000/Variables?PageSize=50&Page=0"
11
}
12
}

Update a Variable resource

update-a-variable-resource page anchor
POST https://serverless.twilio.com/v1/Services/{ServiceSid}/Environments/{EnvironmentSid}/Variables/{Sid}

Property nameTypeRequiredPIIDescription
ServiceSidstringrequired

The SID of the Service to update the Variable resource under.


EnvironmentSidSID<ZE>required

The SID of the Environment with the Variable resource to update.

Pattern: ^ZE[0-9a-fA-F]{32}$Min length: 34Max length: 34

SidSID<ZV>required

The SID of the Variable resource to update.

Pattern: ^ZV[0-9a-fA-F]{32}$Min length: 34Max length: 34
Encoding type:application/x-www-form-urlencoded
SchemaExample
Property nameTypeRequiredDescriptionChild properties
Keystring

Optional

A string by which the Variable resource can be referenced. It can be a maximum of 128 characters.


Valuestring

Optional

A string that contains the actual value of the Variable. It can be a maximum of 450 bytes in size.

1
// Download the helper library from https://www.twilio.com/docs/node/install
2
const twilio = require("twilio"); // Or, for ESM: import twilio from "twilio";
3
4
// Find your Account SID and Auth Token at twilio.com/console
5
// and set the environment variables. See http://twil.io/secure
6
const accountSid = process.env.TWILIO_ACCOUNT_SID;
7
const authToken = process.env.TWILIO_AUTH_TOKEN;
8
const client = twilio(accountSid, authToken);
9
10
async function updateVariable() {
11
const variable = await client.serverless.v1
12
.services("ServiceSid")
13
.environments("ZEaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")
14
.variables("ZVaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")
15
.update({ key: "Key" });
16
17
console.log(variable.sid);
18
}
19
20
updateVariable();

Output

1
{
2
"sid": "ZVaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
3
"account_sid": "ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
4
"service_sid": "ServiceSid",
5
"environment_sid": "ZEaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
6
"key": "Key",
7
"value": "update-value",
8
"date_created": "2018-11-10T20:00:00Z",
9
"date_updated": "2018-11-11T20:00:00Z",
10
"url": "https://serverless.twilio.com/v1/Services/ZS00000000000000000000000000000000/Environments/ZE00000000000000000000000000000000/Variables/ZV00000000000000000000000000000000"
11
}

Delete a Variable resource

delete-a-variable-resource page anchor
DELETE https://serverless.twilio.com/v1/Services/{ServiceSid}/Environments/{EnvironmentSid}/Variables/{Sid}

Property nameTypeRequiredPIIDescription
ServiceSidstringrequired

The SID of the Service to delete the Variable resource from.


EnvironmentSidSID<ZE>required

The SID of the Environment with the Variables to delete.

Pattern: ^ZE[0-9a-fA-F]{32}$Min length: 34Max length: 34

SidSID<ZV>required

The SID of the Variable resource to delete.

Pattern: ^ZV[0-9a-fA-F]{32}$Min length: 34Max length: 34
1
// Download the helper library from https://www.twilio.com/docs/node/install
2
const twilio = require("twilio"); // Or, for ESM: import twilio from "twilio";
3
4
// Find your Account SID and Auth Token at twilio.com/console
5
// and set the environment variables. See http://twil.io/secure
6
const accountSid = process.env.TWILIO_ACCOUNT_SID;
7
const authToken = process.env.TWILIO_AUTH_TOKEN;
8
const client = twilio(accountSid, authToken);
9
10
async function deleteVariable() {
11
await client.serverless.v1
12
.services("ServiceSid")
13
.environments("ZEaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")
14
.variables("ZVaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")
15
.remove();
16
}
17
18
deleteVariable();

Need some help?

Terms of service

Copyright © 2024 Twilio Inc.