Quickstart
Like the Console UI and the Serverless Toolkit, create and manage your Services, Functions, and Assets with the Serverless API. This API lets you create custom Build and Deployment automations that suit your specific needs.
Classic Functions and Assets unavailable through the API
This API can't access classic Functions and Assets. Nor can the classic Functions and Assets interface access API-generated Functions and Assets.
-
Create a Service that contains your Environments. The value of the
uniqueNameparameter becomes part of your hostname for your Function.For example: A Service with the unique name
Hootcreates a hostname ofhttps://hoot-3234.twil.io.View the Create Service exampleThe response contains a Service SID, in the format
ZSXX..XX. -
Create an Environment using the Service SID.
View the Create Environment example-
The request returns an empty Environment as a hostname like
demo-X4HX-dev.twil.io. -
To view the hostname, fetch the Environment for your Environment using the
ZEXX..XXSID.View the Fetch Environment Hostname example
-
-
Create a Function with a
FriendlyNameparameter.- The response includes a Function SID in the format
ZHxxx. - Save this SID. To create the first version of this Function, you need this SID.
View the Create Function example - The response includes a Function SID in the format
-
Write the code for your Function and save it as
firstfunc.js.View the example Function code -
Create the first version of your Function using a
POSTrequest.- Function or Asset versions define the path, Visibility (public, protected, or private), and file content.
- Replace
ZSXX..XXwith your Service SID andZHXX..XXwith your Function SID. - The response returns a Version SID (
ZNXX..XX).
View the Upload Function example -
To compile your Function and Asset versions into a single, deployable package, create a Build.
- Twilio stores this Build on your behalf.
- The response returns a
statusproperty.
View the Create Build without dependencies exampleView the Create Build with dependencies example -
To check the status of the Build, repeat sending the following
GETrequest until"status": "completed".View the Fetch Build example -
Associate the Build with the Environment you created. Twilio calls this association a Deployment.
View the Create Deployment exampleAfter the Deployment completes, your Function goes live.
-
To access your function, go to a URL that resembles
https://demo-X4HX-dev.twil.io/thanos. Replacedemo-X4HX-dev.twil.iowith your Environment's hostname.
Upload Assets by following the same pattern you used for Functions:
-
Create an
Asset. -
Create the
Asset Versionwith aPOSTrequest toserverless-uploads.twilio.com. -
When you create the Build, include the
AssetVersionSIDs, anyFunctionVersions, and dependencies.View the example
To learn more about Twilio Functions, see the API reference for all Serverless resources. Consider Variables. These let you define conditional values for a given Environment.