Functions are JavaScript Node.js code that execute at a particular domain.
The steps to create Functions are as follows:
serverless.twilio.com
We will need the Function Version SID to include this Function in a Build.
The unique string that we created to identify the Function resource.
^ZH[0-9a-fA-F]{32}$
Min length: 34
Max length: 34
The SID of the Account that created the Function resource.
^AC[0-9a-fA-F]{32}$
Min length: 34
Max length: 34
The SID of the Service that the Function resource is associated with.
^ZS[0-9a-fA-F]{32}$
Min length: 34
Max length: 34
The string that you assigned to describe the Function resource. It can be a maximum of 255 characters.
The date and time in GMT when the Function resource was created specified in ISO 8601 format.
The date and time in GMT when the Function resource was last updated specified in ISO 8601 format.
The URLs of nested resources of the Function resource.
POST https://serverless.twilio.com/v1/Services/{ServiceSid}/Functions
The SID of the Service to create the Function resource under.
application/x-www-form-urlencoded
A descriptive string that you create to describe the Function resource. It can be a maximum of 255 characters.
1// Download the helper library from https://www.twilio.com/docs/node/install2const twilio = require("twilio"); // Or, for ESM: import twilio from "twilio";34// Find your Account SID and Auth Token at twilio.com/console5// and set the environment variables. See http://twil.io/secure6const accountSid = process.env.TWILIO_ACCOUNT_SID;7const authToken = process.env.TWILIO_AUTH_TOKEN;8const client = twilio(accountSid, authToken);910async function createFunction() {11const func = await client.serverless.v112.services("ServiceSid")13.functions.create({ friendlyName: "FriendlyName" });1415console.log(func.sid);16}1718createFunction();
1{2"sid": "ZH00000000000000000000000000000000",3"account_sid": "ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",4"service_sid": "ServiceSid",5"friendly_name": "FriendlyName",6"date_created": "2018-11-10T20:00:00Z",7"date_updated": "2018-11-10T20:00:00Z",8"url": "https://serverless.twilio.com/v1/Services/ZS00000000000000000000000000000000/Functions/ZH00000000000000000000000000000000",9"links": {10"function_versions": "https://serverless.twilio.com/v1/Services/ZS00000000000000000000000000000000/Functions/ZH00000000000000000000000000000000/Versions"11}12}
GET https://serverless.twilio.com/v1/Services/{ServiceSid}/Functions/{Sid}
The SID of the Function resource to fetch.
^ZH[0-9a-fA-F]{32}$
Min length: 34
Max length: 34
1// Download the helper library from https://www.twilio.com/docs/node/install2const twilio = require("twilio"); // Or, for ESM: import twilio from "twilio";34// Find your Account SID and Auth Token at twilio.com/console5// and set the environment variables. See http://twil.io/secure6const accountSid = process.env.TWILIO_ACCOUNT_SID;7const authToken = process.env.TWILIO_AUTH_TOKEN;8const client = twilio(accountSid, authToken);910async function fetchFunction() {11const func = await client.serverless.v112.services("ServiceSid")13.functions("ZHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")14.fetch();1516console.log(func.sid);17}1819fetchFunction();
1{2"sid": "ZHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",3"account_sid": "ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",4"service_sid": "ServiceSid",5"friendly_name": "test-function",6"date_created": "2018-11-10T20:00:00Z",7"date_updated": "2018-11-10T20:00:00Z",8"url": "https://serverless.twilio.com/v1/Services/ZS00000000000000000000000000000000/Functions/ZH00000000000000000000000000000000",9"links": {10"function_versions": "https://serverless.twilio.com/v1/Services/ZS00000000000000000000000000000000/Functions/ZH00000000000000000000000000000000/Versions"11}12}
GET https://serverless.twilio.com/v1/Services/{ServiceSid}/Functions
The SID of the Service to read the Function resources from.
How many resources to return in each list page. The default is 50, and the maximum is 1000.
1
Maximum: 1000
The page token. This is provided by the API.
1// Download the helper library from https://www.twilio.com/docs/node/install2const twilio = require("twilio"); // Or, for ESM: import twilio from "twilio";34// Find your Account SID and Auth Token at twilio.com/console5// and set the environment variables. See http://twil.io/secure6const accountSid = process.env.TWILIO_ACCOUNT_SID;7const authToken = process.env.TWILIO_AUTH_TOKEN;8const client = twilio(accountSid, authToken);910async function listFunction() {11const funcs = await client.serverless.v112.services("ServiceSid")13.functions.list({ limit: 20 });1415funcs.forEach((f) => console.log(f.sid));16}1718listFunction();
1{2"functions": [],3"meta": {4"first_page_url": "https://serverless.twilio.com/v1/Services/ZS00000000000000000000000000000000/Functions?PageSize=50&Page=0",5"key": "functions",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/Functions?PageSize=50&Page=0"11}12}
POST https://serverless.twilio.com/v1/Services/{ServiceSid}/Functions/{Sid}
application/x-www-form-urlencoded
A descriptive string that you create to describe the Function resource. It can be a maximum of 255 characters.
1// Download the helper library from https://www.twilio.com/docs/node/install2const twilio = require("twilio"); // Or, for ESM: import twilio from "twilio";34// Find your Account SID and Auth Token at twilio.com/console5// and set the environment variables. See http://twil.io/secure6const accountSid = process.env.TWILIO_ACCOUNT_SID;7const authToken = process.env.TWILIO_AUTH_TOKEN;8const client = twilio(accountSid, authToken);910async function updateFunction() {11const func = await client.serverless.v112.services("ServiceSid")13.functions("ZHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")14.update({ friendlyName: "FriendlyName" });1516console.log(func.sid);17}1819updateFunction();
1{2"sid": "ZHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",3"account_sid": "ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",4"service_sid": "ServiceSid",5"friendly_name": "FriendlyName",6"date_created": "2018-11-10T20:00:00Z",7"date_updated": "2018-11-10T20:00:00Z",8"url": "https://serverless.twilio.com/v1/Services/ZS00000000000000000000000000000000/Functions/ZH00000000000000000000000000000000",9"links": {10"function_versions": "https://serverless.twilio.com/v1/Services/ZS00000000000000000000000000000000/Functions/ZH00000000000000000000000000000000/Versions"11}12}
DELETE https://serverless.twilio.com/v1/Services/{ServiceSid}/Functions/{Sid}
The SID of the Function resource to delete.
^ZH[0-9a-fA-F]{32}$
Min length: 34
Max length: 34
1// Download the helper library from https://www.twilio.com/docs/node/install2const twilio = require("twilio"); // Or, for ESM: import twilio from "twilio";34// Find your Account SID and Auth Token at twilio.com/console5// and set the environment variables. See http://twil.io/secure6const accountSid = process.env.TWILIO_ACCOUNT_SID;7const authToken = process.env.TWILIO_AUTH_TOKEN;8const client = twilio(accountSid, authToken);910async function deleteFunction() {11await client.serverless.v112.services("ServiceSid")13.functions("ZHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")14.remove();15}1617deleteFunction();