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
Resource properties
sidtype: SID<ZV>Not PII

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


service_sidtype: SID<ZS>Not PII

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


environment_sidtype: SID<ZE>Not PII

The SID of the Environment in which the Variable exists.


keytype: stringPII MTL: 7 days

A string by which the Variable resource can be referenced.


valuetype: stringPII MTL: 7 days

A string that contains the actual value of the Variable.


date_createdtype: string<DATE TIME>Not PII

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


date_updatedtype: string<DATE TIME>Not PII

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.


urltype: string<URI>Not PII

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

Parameters

create-parameters page anchor
URI parameters
ServiceSidtype: stringNot PII
Path Parameter

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


EnvironmentSidtype: SID<ZE>Not PII
Path Parameter

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


Request body parameters
Keytype: stringPII MTL: 7 days
Required

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


Valuetype: stringPII MTL: 7 days
Required

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

_12
// Download the helper library from https://www.twilio.com/docs/node/install
_12
// Find your Account SID and Auth Token at twilio.com/console
_12
// and set the environment variables. See http://twil.io/secure
_12
const accountSid = process.env.TWILIO_ACCOUNT_SID;
_12
const authToken = process.env.TWILIO_AUTH_TOKEN;
_12
const client = require('twilio')(accountSid, authToken);
_12
_12
client.serverless.v1.services('ZSXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX')
_12
.environments('ZEXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX')
_12
.variables
_12
.create({key: 'key', value: 'value'})
_12
.then(variable => console.log(variable.sid));

Output

_11
{
_11
"sid": "ZV00000000000000000000000000000000",
_11
"account_sid": "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
_11
"service_sid": "ZSXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
_11
"environment_sid": "ZEXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
_11
"key": "new-key",
_11
"value": "new-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/ZSXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/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}

URI parameters
ServiceSidtype: stringNot PII
Path Parameter

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


EnvironmentSidtype: SID<ZE>Not PII
Path Parameter

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


Sidtype: SID<ZV>Not PII
Path Parameter

The SID of the Variable resource to fetch.

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

_12
// Download the helper library from https://www.twilio.com/docs/node/install
_12
// Find your Account SID and Auth Token at twilio.com/console
_12
// and set the environment variables. See http://twil.io/secure
_12
const accountSid = process.env.TWILIO_ACCOUNT_SID;
_12
const authToken = process.env.TWILIO_AUTH_TOKEN;
_12
const client = require('twilio')(accountSid, authToken);
_12
_12
client.serverless.v1.services('ZSXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX')
_12
.environments('ZEXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX')
_12
.variables('ZVXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX')
_12
.fetch()
_12
.then(variable => console.log(variable.sid));

Output

_11
{
_11
"sid": "ZVXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
_11
"account_sid": "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
_11
"service_sid": "ZSXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
_11
"environment_sid": "ZEXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
_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/ZSXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/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

URI parameters
ServiceSidtype: stringNot PII
Path Parameter

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


EnvironmentSidtype: SID<ZE>Not PII
Path Parameter

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


PageSizetype: integerNot PII
Query Parameter

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


Pagetype: integerNot PII
Query Parameter

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


PageTokentype: stringNot PII
Query Parameter

The page token. This is provided by the API.

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

_12
// Download the helper library from https://www.twilio.com/docs/node/install
_12
// Find your Account SID and Auth Token at twilio.com/console
_12
// and set the environment variables. See http://twil.io/secure
_12
const accountSid = process.env.TWILIO_ACCOUNT_SID;
_12
const authToken = process.env.TWILIO_AUTH_TOKEN;
_12
const client = require('twilio')(accountSid, authToken);
_12
_12
client.serverless.v1.services('ZSXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX')
_12
.environments('ZEXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX')
_12
.variables
_12
.list({limit: 20})
_12
.then(variables => variables.forEach(v => console.log(v.sid)));

Output

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

URI parameters
ServiceSidtype: stringNot PII
Path Parameter

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


EnvironmentSidtype: SID<ZE>Not PII
Path Parameter

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


Sidtype: SID<ZV>Not PII
Path Parameter

The SID of the Variable resource to update.


Request body parameters
Keytype: stringPII MTL: 7 days

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


Valuetype: stringPII MTL: 7 days

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

_12
// Download the helper library from https://www.twilio.com/docs/node/install
_12
// Find your Account SID and Auth Token at twilio.com/console
_12
// and set the environment variables. See http://twil.io/secure
_12
const accountSid = process.env.TWILIO_ACCOUNT_SID;
_12
const authToken = process.env.TWILIO_AUTH_TOKEN;
_12
const client = require('twilio')(accountSid, authToken);
_12
_12
client.serverless.v1.services('ZSXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX')
_12
.environments('ZEXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX')
_12
.variables('ZVXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX')
_12
.update({key: 'key'})
_12
.then(variable => console.log(variable.sid));

Output

_11
{
_11
"sid": "ZVXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
_11
"account_sid": "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
_11
"service_sid": "ZSXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
_11
"environment_sid": "ZEXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
_11
"key": "update-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/ZSXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/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}

URI parameters
ServiceSidtype: stringNot PII
Path Parameter

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


EnvironmentSidtype: SID<ZE>Not PII
Path Parameter

The SID of the Environment with the Variables to delete.


Sidtype: SID<ZV>Not PII
Path Parameter

The SID of the Variable resource to delete.

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

_11
// Download the helper library from https://www.twilio.com/docs/node/install
_11
// Find your Account SID and Auth Token at twilio.com/console
_11
// and set the environment variables. See http://twil.io/secure
_11
const accountSid = process.env.TWILIO_ACCOUNT_SID;
_11
const authToken = process.env.TWILIO_AUTH_TOKEN;
_11
const client = require('twilio')(accountSid, authToken);
_11
_11
client.serverless.v1.services('ZSXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX')
_11
.environments('ZEXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX')
_11
.variables('ZVXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX')
_11
.remove();


Rate this page: