Skip to contentSkip to navigationSkip to topbar
Rate this page:
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 nameTypePIIDescription
sidSID<ZV>
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>

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>

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>

The SID of the Environment in which the Variable exists.

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

keystring
PII MTL: 7 days

A string by which the Variable resource can be referenced.


valuestring

A string that contains the actual value of the Variable.


date_updatedstring<date-time>

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>

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
Property nameTypeRequiredPIIDescription
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 Variable

create-a-variable page anchor
Node.js
Python
C#
Java
Go
PHP
Ruby
twilio-cli
curl

_22
// Download the helper library from https://www.twilio.com/docs/node/install
_22
const twilio = require("twilio"); // Or, for ESM: import twilio from "twilio";
_22
_22
// Find your Account SID and Auth Token at twilio.com/console
_22
// and set the environment variables. See http://twil.io/secure
_22
const accountSid = process.env.TWILIO_ACCOUNT_SID;
_22
const authToken = process.env.TWILIO_AUTH_TOKEN;
_22
const client = twilio(accountSid, authToken);
_22
_22
async function createVariable() {
_22
const variable = await client.serverless.v1
_22
.services("ServiceSid")
_22
.environments("ZEaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")
_22
.variables.create({
_22
key: "Key",
_22
value: "Value",
_22
});
_22
_22
console.log(variable.sid);
_22
}
_22
_22
createVariable();

Output

_11
{
_11
"sid": "ZV00000000000000000000000000000000",
_11
"account_sid": "ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
_11
"service_sid": "ServiceSid",
_11
"environment_sid": "ZEaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
_11
"key": "Key",
_11
"value": "Value",
_11
"date_created": "2018-11-10T20:00:00Z",
_11
"date_updated": "2018-11-10T20:00:00Z",
_11
"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
Node.js
Python
C#
Java
Go
PHP
Ruby
twilio-cli
curl

_20
// Download the helper library from https://www.twilio.com/docs/node/install
_20
const twilio = require("twilio"); // Or, for ESM: import twilio from "twilio";
_20
_20
// Find your Account SID and Auth Token at twilio.com/console
_20
// and set the environment variables. See http://twil.io/secure
_20
const accountSid = process.env.TWILIO_ACCOUNT_SID;
_20
const authToken = process.env.TWILIO_AUTH_TOKEN;
_20
const client = twilio(accountSid, authToken);
_20
_20
async function fetchVariable() {
_20
const variable = await client.serverless.v1
_20
.services("ServiceSid")
_20
.environments("ZEaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")
_20
.variables("ZVaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")
_20
.fetch();
_20
_20
console.log(variable.sid);
_20
}
_20
_20
fetchVariable();

Output

_11
{
_11
"sid": "ZVaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
_11
"account_sid": "ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
_11
"service_sid": "ServiceSid",
_11
"environment_sid": "ZEaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
_11
"key": "test-key",
_11
"value": "test-value",
_11
"date_created": "2018-11-10T20:00:00Z",
_11
"date_updated": "2018-11-10T20:00:00Z",
_11
"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
PageSizeintegerOptional

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

Minimum: 1Maximum: 1000

PageintegerOptional

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

Minimum: 0

PageTokenstringOptional

The page token. This is provided by the API.

Node.js
Python
C#
Java
Go
PHP
Ruby
twilio-cli
curl

_19
// Download the helper library from https://www.twilio.com/docs/node/install
_19
const twilio = require("twilio"); // Or, for ESM: import twilio from "twilio";
_19
_19
// Find your Account SID and Auth Token at twilio.com/console
_19
// and set the environment variables. See http://twil.io/secure
_19
const accountSid = process.env.TWILIO_ACCOUNT_SID;
_19
const authToken = process.env.TWILIO_AUTH_TOKEN;
_19
const client = twilio(accountSid, authToken);
_19
_19
async function listVariable() {
_19
const variables = await client.serverless.v1
_19
.services("ServiceSid")
_19
.environments("ZEaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")
_19
.variables.list({ limit: 20 });
_19
_19
variables.forEach((v) => console.log(v.sid));
_19
}
_19
_19
listVariable();

Output

_12
{
_12
"variables": [],
_12
"meta": {
_12
"first_page_url": "https://serverless.twilio.com/v1/Services/ZS00000000000000000000000000000000/Environments/ZE00000000000000000000000000000000/Variables?PageSize=50&Page=0",
_12
"key": "variables",
_12
"next_page_url": null,
_12
"page": 0,
_12
"page_size": 50,
_12
"previous_page_url": null,
_12
"url": "https://serverless.twilio.com/v1/Services/ZS00000000000000000000000000000000/Environments/ZE00000000000000000000000000000000/Variables?PageSize=50&Page=0"
_12
}
_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
Property nameTypeRequiredPIIDescription
KeystringOptional

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


ValuestringOptional

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

Node.js
Python
C#
Java
Go
PHP
Ruby
twilio-cli
curl

_20
// Download the helper library from https://www.twilio.com/docs/node/install
_20
const twilio = require("twilio"); // Or, for ESM: import twilio from "twilio";
_20
_20
// Find your Account SID and Auth Token at twilio.com/console
_20
// and set the environment variables. See http://twil.io/secure
_20
const accountSid = process.env.TWILIO_ACCOUNT_SID;
_20
const authToken = process.env.TWILIO_AUTH_TOKEN;
_20
const client = twilio(accountSid, authToken);
_20
_20
async function updateVariable() {
_20
const variable = await client.serverless.v1
_20
.services("ServiceSid")
_20
.environments("ZEaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")
_20
.variables("ZVaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")
_20
.update({ key: "Key" });
_20
_20
console.log(variable.sid);
_20
}
_20
_20
updateVariable();

Output

_11
{
_11
"sid": "ZVaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
_11
"account_sid": "ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
_11
"service_sid": "ServiceSid",
_11
"environment_sid": "ZEaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
_11
"key": "Key",
_11
"value": "update-value",
_11
"date_created": "2018-11-10T20:00:00Z",
_11
"date_updated": "2018-11-11T20:00:00Z",
_11
"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
Node.js
Python
C#
Java
Go
PHP
Ruby
twilio-cli
curl

_18
// Download the helper library from https://www.twilio.com/docs/node/install
_18
const twilio = require("twilio"); // Or, for ESM: import twilio from "twilio";
_18
_18
// Find your Account SID and Auth Token at twilio.com/console
_18
// and set the environment variables. See http://twil.io/secure
_18
const accountSid = process.env.TWILIO_ACCOUNT_SID;
_18
const authToken = process.env.TWILIO_AUTH_TOKEN;
_18
const client = twilio(accountSid, authToken);
_18
_18
async function deleteVariable() {
_18
await client.serverless.v1
_18
.services("ServiceSid")
_18
.environments("ZEaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")
_18
.variables("ZVaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")
_18
.remove();
_18
}
_18
_18
deleteVariable();


Rate this page: