Skip to contentSkip to navigationSkip to topbar
Page toolsOn this page
Looking for more inspiration?Visit the

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.

(warning)

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.


Deploying a single Function

deploying-a-single-function page anchor
  1. Create a Service that contains your Environments. The value of the uniqueName parameter becomes part of your hostname for your Function.

    For example: A Service with the unique name Hoot creates a hostname of https://hoot-3234.twil.io.

    The response contains a Service SID, in the format ZSXX..XX.

  2. Create an Environment using the Service SID.

    • 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..XX SID.

  3. Create a Function with a FriendlyName parameter.

    • 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.
  4. Write the code for your Function and save it as firstfunc.js.

  5. Create the first version of your Function using a POST request.

  6. 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 status property.
  7. To check the status of the Build, repeat sending the following GET request until "status": "completed".

  8. Associate the Build with the Environment you created. Twilio calls this association a Deployment.

    After the Deployment completes, your Function goes live.

  9. To access your function, go to a URL that resembles https://demo-X4HX-dev.twil.io/thanos. Replace demo-X4HX-dev.twil.io with your Environment's hostname.


Upload Assets by following the same pattern you used for Functions:

  1. Create an Asset.

  2. Create the Asset Version with a POST request to serverless-uploads.twilio.com.

  3. When you create the Build, include the AssetVersion SIDs, any FunctionVersions, and dependencies.


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.