Skip to contentSkip to navigationSkip to topbar
Rate this page:
On this page

Function


Functions are JavaScript Node.js code that execute at a particular domain.

The steps to create Functions are as follows:

  1. Create a Function (this resource)
  2. Create a Function Version via serverless.twilio.com

We will need the Function Version SID to include this Function in a Build.


Function Properties

function-properties page anchor
Property nameTypePIIDescription
sidSID<ZH>
Not PII

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

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

account_sidSID<AC>

The SID of the Account that created the Function resource.

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

service_sidSID<ZS>

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

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

friendly_namestring
PII MTL: 7 days

The string that you assigned to describe the Function resource. It can be a maximum of 255 characters.


date_updatedstring<date-time>

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


urlstring<uri>

The absolute URL of the Function resource.


linksobject<uri-map>

The URLs of nested resources of the Function resource.


Create a Function resource

create-a-function-resource page anchor
POST https://serverless.twilio.com/v1/Services/{ServiceSid}/Functions

Path parameters

path-parameters page anchor
Property nameTypeRequiredPIIDescription
ServiceSidstringrequired

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

Property nameTypeRequiredPIIDescription
FriendlyNamestringrequired

A descriptive string that you create to describe the Function resource. It can be a maximum of 255 characters.

Create a Function

create-a-function page anchor
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 createFunction() {
_18
const func = await client.serverless.v1
_18
.services("ServiceSid")
_18
.functions.create({ friendlyName: "FriendlyName" });
_18
_18
console.log(func.sid);
_18
}
_18
_18
createFunction();

Output

_12
{
_12
"sid": "ZH00000000000000000000000000000000",
_12
"account_sid": "ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
_12
"service_sid": "ServiceSid",
_12
"friendly_name": "FriendlyName",
_12
"date_created": "2018-11-10T20:00:00Z",
_12
"date_updated": "2018-11-10T20:00:00Z",
_12
"url": "https://serverless.twilio.com/v1/Services/ZS00000000000000000000000000000000/Functions/ZH00000000000000000000000000000000",
_12
"links": {
_12
"function_versions": "https://serverless.twilio.com/v1/Services/ZS00000000000000000000000000000000/Functions/ZH00000000000000000000000000000000/Versions"
_12
}
_12
}


Fetch a Function resource

fetch-a-function-resource page anchor
GET https://serverless.twilio.com/v1/Services/{ServiceSid}/Functions/{Sid}

Property nameTypeRequiredPIIDescription
ServiceSidstringrequired

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


SidSID<ZH>required

The SID of the Function resource to fetch.

Pattern: ^ZH[0-9a-fA-F]{32}$Min length: 34Max length: 34
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 fetchFunction() {
_19
const func = await client.serverless.v1
_19
.services("ServiceSid")
_19
.functions("ZHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")
_19
.fetch();
_19
_19
console.log(func.sid);
_19
}
_19
_19
fetchFunction();

Output

_12
{
_12
"sid": "ZHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
_12
"account_sid": "ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
_12
"service_sid": "ServiceSid",
_12
"friendly_name": "test-function",
_12
"date_created": "2018-11-10T20:00:00Z",
_12
"date_updated": "2018-11-10T20:00:00Z",
_12
"url": "https://serverless.twilio.com/v1/Services/ZS00000000000000000000000000000000/Functions/ZH00000000000000000000000000000000",
_12
"links": {
_12
"function_versions": "https://serverless.twilio.com/v1/Services/ZS00000000000000000000000000000000/Functions/ZH00000000000000000000000000000000/Versions"
_12
}
_12
}


Read multiple Function resources

read-multiple-function-resources page anchor
GET https://serverless.twilio.com/v1/Services/{ServiceSid}/Functions

Property nameTypeRequiredPIIDescription
ServiceSidstringrequired

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

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

_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 listFunction() {
_18
const funcs = await client.serverless.v1
_18
.services("ServiceSid")
_18
.functions.list({ limit: 20 });
_18
_18
funcs.forEach((f) => console.log(f.sid));
_18
}
_18
_18
listFunction();

Output

_12
{
_12
"functions": [],
_12
"meta": {
_12
"first_page_url": "https://serverless.twilio.com/v1/Services/ZS00000000000000000000000000000000/Functions?PageSize=50&Page=0",
_12
"key": "functions",
_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/Functions?PageSize=50&Page=0"
_12
}
_12
}


Update a Function resource

update-a-function-resource page anchor
POST https://serverless.twilio.com/v1/Services/{ServiceSid}/Functions/{Sid}

Property nameTypeRequiredPIIDescription
ServiceSidstringrequired

The SID of the Service to update the Function resource from.


SidSID<ZH>required

The SID of the Function resource to update.

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

A descriptive string that you create to describe the Function resource. It can be a maximum of 255 characters.

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 updateFunction() {
_19
const func = await client.serverless.v1
_19
.services("ServiceSid")
_19
.functions("ZHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")
_19
.update({ friendlyName: "FriendlyName" });
_19
_19
console.log(func.sid);
_19
}
_19
_19
updateFunction();

Output

_12
{
_12
"sid": "ZHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
_12
"account_sid": "ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
_12
"service_sid": "ServiceSid",
_12
"friendly_name": "FriendlyName",
_12
"date_created": "2018-11-10T20:00:00Z",
_12
"date_updated": "2018-11-10T20:00:00Z",
_12
"url": "https://serverless.twilio.com/v1/Services/ZS00000000000000000000000000000000/Functions/ZH00000000000000000000000000000000",
_12
"links": {
_12
"function_versions": "https://serverless.twilio.com/v1/Services/ZS00000000000000000000000000000000/Functions/ZH00000000000000000000000000000000/Versions"
_12
}
_12
}


Delete a Function resource

delete-a-function-resource page anchor
DELETE https://serverless.twilio.com/v1/Services/{ServiceSid}/Functions/{Sid}

(information)

Info

A Function will fail to delete if any of its Versions are referenced by an active Build.

If necessary, create a new Build that does not include the Function to be deleted, and delete the Function only once the Build has completed.

Property nameTypeRequiredPIIDescription
ServiceSidstringrequired

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


SidSID<ZH>required

The SID of the Function resource to delete.

Pattern: ^ZH[0-9a-fA-F]{32}$Min length: 34Max length: 34
Node.js
Python
C#
Java
Go
PHP
Ruby
twilio-cli
curl

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


Rate this page: