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

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


service_sidtype: SID<ZS>Not PII

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


friendly_nametype: stringPII MTL: 7 days

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


date_createdtype: string<DATE TIME>Not PII

The date and time in GMT when the Function 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 Function 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 Function resource.


linkstype: object<URI MAP>Not PII

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

Parameters

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

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


Request body parameters
FriendlyNametype: stringPII MTL: 7 days
Required

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

_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
.functions
_11
.create({friendlyName: 'friendly_name'})
_11
.then(function_ => console.log(function_.sid));

Output

_12
{
_12
"sid": "ZH00000000000000000000000000000000",
_12
"account_sid": "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
_12
"service_sid": "ZSXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
_12
"friendly_name": "function-friendly",
_12
"date_created": "2018-11-10T20:00:00Z",
_12
"date_updated": "2018-11-10T20:00:00Z",
_12
"url": "https://serverless.twilio.com/v1/Services/ZSXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Functions/ZH00000000000000000000000000000000",
_12
"links": {
_12
"function_versions": "https://serverless.twilio.com/v1/Services/ZSXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/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}

URI parameters
ServiceSidtype: stringNot PII
Path Parameter

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


Sidtype: SID<ZH>Not PII
Path Parameter

The SID of the Function resource to fetch.

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
.functions('ZHXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX')
_11
.fetch()
_11
.then(function_ => console.log(function_.friendlyName));

Output

_12
{
_12
"sid": "ZHXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
_12
"account_sid": "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
_12
"service_sid": "ZSXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
_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/ZSXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Functions/ZH00000000000000000000000000000000",
_12
"links": {
_12
"function_versions": "https://serverless.twilio.com/v1/Services/ZSXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Functions/ZH00000000000000000000000000000000/Versions"
_12
}
_12
}


Read multiple Function resources

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

URI parameters
ServiceSidtype: stringNot PII
Path Parameter

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


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

_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
.functions
_11
.list({limit: 20})
_11
.then(functions => functions.forEach(f => console.log(f.sid)));

Output

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

URI parameters
ServiceSidtype: stringNot PII
Path Parameter

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


Sidtype: SID<ZH>Not PII
Path Parameter

The SID of the Function resource to update.


Request body parameters
FriendlyNametype: stringPII MTL: 7 days
Required

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

_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
.functions('ZHXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX')
_11
.update({friendlyName: 'friendly_name'})
_11
.then(function_ => console.log(function_.friendlyName));

Output

_12
{
_12
"sid": "ZHXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
_12
"account_sid": "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
_12
"service_sid": "ZSXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
_12
"friendly_name": "function-friendly-update",
_12
"date_created": "2018-11-10T20:00:00Z",
_12
"date_updated": "2018-11-10T20:00:00Z",
_12
"url": "https://serverless.twilio.com/v1/Services/ZSXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Functions/ZH00000000000000000000000000000000",
_12
"links": {
_12
"function_versions": "https://serverless.twilio.com/v1/Services/ZSXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/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.

URI parameters
ServiceSidtype: stringNot PII
Path Parameter

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


Sidtype: SID<ZH>Not PII
Path Parameter

The SID of the Function resource to delete.

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

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


Rate this page: