# Function Version

Function Versions are specific versions of JavaScript Node.js code that execute at a particular domain.

The steps to create Functions are as follows:

1. Create a [Function](/docs/serverless/api/resource/function)
2. [Create a Function Version](#create-a-function-version-resource) (this resource) by making a `POST` request to `https://serverless-upload.twilio.com`

You will need the Function Version SID that the create request returns to include this Function in a [Build](/docs/serverless/api/resource/build).

## Function Version properties

```json
{"type":"object","refName":"serverless.v1.service.function.function_version","modelName":"serverless_v1_service_function_function_version","properties":{"sid":{"type":"string","minLength":34,"maxLength":34,"pattern":"^ZN[0-9a-fA-F]{32}$","nullable":true,"description":"The unique string that we created to identify the Function Version resource."},"account_sid":{"type":"string","minLength":34,"maxLength":34,"pattern":"^AC[0-9a-fA-F]{32}$","nullable":true,"description":"The SID of the [Account](/docs/iam/api/account) that created the Function Version resource."},"service_sid":{"type":"string","minLength":34,"maxLength":34,"pattern":"^ZS[0-9a-fA-F]{32}$","nullable":true,"description":"The SID of the Service that the Function Version resource is associated with."},"function_sid":{"type":"string","minLength":34,"maxLength":34,"pattern":"^ZH[0-9a-fA-F]{32}$","nullable":true,"description":"The SID of the Function resource that is the parent of the Function Version resource."},"path":{"type":"string","nullable":true,"description":"The URL-friendly string by which the Function Version resource can be referenced. It can be a maximum of 255 characters. All paths begin with a forward slash ('/'). If a Function Version creation request is submitted with a path not containing a leading slash, the path will automatically be prepended with one.","x-twilio":{"pii":{"handling":"standard","deleteSla":7}}},"visibility":{"type":"string","enum":["public","private","protected"],"description":"The access control that determines how the Function Version resource can be accessed. Can be: `public`, `protected`, or `private`.","refName":"function_version_enum_visibility","modelName":"function_version_enum_visibility"},"date_created":{"type":"string","format":"date-time","nullable":true,"description":"The date and time in GMT when the Function Version resource was created specified in [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) format."},"url":{"type":"string","format":"uri","nullable":true,"description":"The absolute URL of the Function Version resource."},"links":{"type":"object","format":"uri-map","nullable":true}}}
```

## Create a Function Version resource

A Function Version resource is created by making a `POST` request to the following, dedicated URL:

`https://serverless-upload.twilio.com/v1/Services/{ServiceSid}/Functions/{FunctionSid}/Versions`

The following example creates a Function Version resource using the language of your choice (or curl) and an external file, `firstfunc.js`, which contains the function body.

Upload Function body

```js
const fs = require('fs');
// Before running this code, install "form-data" and "axios" using `npm install form-data axios`
const FormData = require('form-data');
const axios = require('axios');

// Provision API Keys at twilio.com/console/runtime/api-keys
// and set the environment variables. See https://twil.io/secure
const apiKey = process.env.TWILIO_API_KEY;
const apiSecret = process.env.TWILIO_API_SECRET;

const serviceSid = 'ZSXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX';
const functionSid = 'ZHXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX';

const serviceUrl = `https://serverless-upload.twilio.com/v1/Services/${serviceSid}`;
const uploadUrl = `${serviceUrl}/Functions/${functionSid}/Versions`;

const form = new FormData();
form.append('Path', '/thanos');
form.append('Visibility', 'public');
form.append('Content', fs.createReadStream('firstfunc.js'), {
  contentType: 'application/javascript',
});

// Create a new Function Version
axios
  .post(uploadUrl, form, {
    auth: {
      username: apiKey,
      password: apiSecret,
    },
    headers: form.getHeaders(),
  })
  .then((response) => {
    const newVersionSid = response.data.sid;
    console.log(newVersionSid);
  });
```

```py
import os
import requests
import json

# Provision API Keys at twilio.com/console/runtime/api-keys
# and set the environment variables. See https://twil.io/secure
api_key = os.environ['TWILIO_API_KEY']
api_secret = os.environ['TWILIO_API_SECRET']

service_sid = 'ZSXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
function_sid = 'ZHXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'

service_url = f'https://serverless-upload.twilio.com/v1/Services/{service_sid}'
upload_url = f'{service_url}/Functions/{function_sid}/Versions'

file_contents = open('firstfunc.js', 'rb')

# Create a new Function Version
response = requests.post(
    upload_url,
    auth=(api_key, api_secret),
    files={
        'Content': ('firstfunc.js', file_contents, 'application/javascript')
    },
    data={
        'Path': '/thanos',
        'Visibility': 'public',
    },
)

new_version_sid = json.loads(response.text).get("sid")
print(new_version_sid)
```

```java
import java.io.File;

import kong.unirest.HttpResponse;
import kong.unirest.JsonNode;
import kong.unirest.Unirest;
import kong.unirest.json.JSONObject;

public class UploadFunctionExample {
  public static void main(String[] args) {
    // Provision API Keys at twilio.com/console/runtime/api-keys
    // and set the environment variables. See https://twil.io/secure
    String TWILIO_API_KEY = System.getenv("TWILIO_API_KEY");
    String TWILIO_API_SECRET = System.getenv("TWILIO_API_SECRET");

    String service_sid = "ZSXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
    String function_sid = "ZHXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";

    String service_url = "https://serverless-upload.twilio.com/v1/Services/" + service_sid;
    String upload_url = service_url + "/Functions/" + function_sid + "/Versions";

    HttpResponse<JsonNode> response = Unirest.post(upload_url)
        .basicAuth(TWILIO_API_KEY, TWILIO_API_SECRET)
        .field("Content", new File("firstfunc.js"), "application/javascript")
        .field("Path", "/thanos")
        .field("Visibility", "public")
        .charset(null)
        .asJson();

    JSONObject function_version = response.getBody().getObject();
    String function_version_sid = function_version.get("sid").toString();
    System.out.println(function_version_sid);
  }
}
```

```php
<?php

# Provision API Keys at twilio.com/console/runtime/api-keys
# and set the environment variables. See https://twil.io/secure
$api_key = getenv("TWILIO_API_KEY");
$api_secret = getenv("TWILIO_API_SECRET");

$service_sid = "ZSXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
$function_sid = "ZHXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";

$curl = curl_init();

curl_setopt_array($curl, array(
  CURLOPT_URL => "https://serverless-upload.twilio.com/v1/Services/${service_sid}" .
    "/Functions/${function_sid}/Versions",
  CURLOPT_POST => true,
  CURLOPT_POSTFIELDS => array(
    'Content' => new CURLFile(
      'firstfunc.js',
      'application/javascript',
      'firstfunc.js'
    ),
    'Path' => '/thanos',
    'Visibility' => 'public'
  ),
  CURLOPT_USERPWD => $api_key . ":" . $api_secret,
  CURLOPT_RETURNTRANSFER => true
));

# Create a new Function Version
$response = curl_exec($curl);
curl_close($curl);

$data = json_decode($response);
echo $data->sid;
```

```rb
require 'uri'
require 'http'
require 'json'

# Provision API Keys at twilio.com/console/runtime/api-keys
# and set the environment variables. See https://twil.io/secure
api_key = ENV['TWILIO_API_KEY']
api_secret = ENV['TWILIO_API_SECRET']

service_sid = 'ZSXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
function_sid = 'ZHXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'

service_url = "https://serverless-upload.twilio.com/v1/Services/#{service_sid}"
upload_url = URI("#{service_url}/Functions/#{function_sid}/Versions")

response = HTTP
           .basic_auth(user: api_key, pass: api_secret)
           .post(upload_url, form: {
                   'Content' => HTTP::FormData::File.new(
                     'firstfunc.js',
                     content_type: 'application/javascript',
                     filename: 'firstfunc.js'
                   ),
                   'Path' => '/thanos',
                   'Visibility' => 'public'
                 })

data = response.parse
puts data['sid']
```

```bash
curl -X POST "https://serverless-upload.twilio.com/v1/Services/ZSxxx/Functions/ZHxxx/Versions" \
-F "Content=@firstfunc.js; type=application/javascript" \
-F "Path=/thanos" \
-F "Visibility=public" \
-u "TWILIO_API_KEY:TWILIO_API_SECRET"
```

> \[!WARNING]
>
> Note that the Serverless upload endpoint is on a different subdomain from the rest of the Serverless API (`serverless-upload.twilio.com` instead of `serverless.twilio.com`), and is not supported by the Twilio SDKs at this time.

The `create` action accepts these parameters:

| **Parameter** | **Description**                                                                                                              |
| ------------- | ---------------------------------------------------------------------------------------------------------------------------- |
| `Content`     | The Function code to upload as a JavaScript file.                                                                            |
| `FunctionSid` | The SID of the Function resource to upload this code to.                                                                     |
| `Path`        | The path to assign the Function. Must be URL Friendly, without fragments, and the characters `;,?:@+&$()' "` are disallowed. |
| `ServiceSid`  | The SID of the Function's Service.                                                                                           |
| `Visibility`  | The [visibility](/docs/serverless/functions-assets/visibility) of the Function. Can be `public`, `protected`, or `private`.  |

## Fetch a FunctionVersion resource

`GET https://serverless.twilio.com/v1/Services/{ServiceSid}/Functions/{FunctionSid}/Versions/{Sid}`

### Path parameters

```json
[{"name":"ServiceSid","in":"path","description":"The SID of the Service to fetch the Function Version resource from.","schema":{"type":"string"},"required":true},{"name":"FunctionSid","in":"path","description":"The SID of the function that is the parent of the Function Version resource to fetch.","schema":{"type":"string","minLength":34,"maxLength":34,"pattern":"^ZH[0-9a-fA-F]{32}$"},"required":true},{"name":"Sid","in":"path","description":"The SID of the Function Version resource to fetch.","schema":{"type":"string","minLength":34,"maxLength":34,"pattern":"^ZN[0-9a-fA-F]{32}$"},"required":true}]
```

Fetch a Function Version resource

```js
// Download the helper library from https://www.twilio.com/docs/node/install
const twilio = require("twilio"); // Or, for ESM: import twilio from "twilio";

// Find your Account SID and Auth Token at twilio.com/console
// and set the environment variables. See http://twil.io/secure
const accountSid = process.env.TWILIO_ACCOUNT_SID;
const authToken = process.env.TWILIO_AUTH_TOKEN;
const client = twilio(accountSid, authToken);

async function fetchFunctionVersion() {
  const functionVersion = await client.serverless.v1
    .services("ServiceSid")
    .functions("ZHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")
    .functionVersions("ZNaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")
    .fetch();

  console.log(functionVersion.sid);
}

fetchFunctionVersion();
```

```python
# Download the helper library from https://www.twilio.com/docs/python/install
import os
from twilio.rest import Client

# Find your Account SID and Auth Token at twilio.com/console
# and set the environment variables. See http://twil.io/secure
account_sid = os.environ["TWILIO_ACCOUNT_SID"]
auth_token = os.environ["TWILIO_AUTH_TOKEN"]
client = Client(account_sid, auth_token)

function_version = (
    client.serverless.v1.services("ServiceSid")
    .functions("ZHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")
    .function_versions("ZNaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")
    .fetch()
)

print(function_version.sid)
```

```csharp
// Install the C# / .NET helper library from twilio.com/docs/csharp/install

using System;
using Twilio;
using Twilio.Rest.Serverless.V1.Service.Function;
using System.Threading.Tasks;

class Program {
    public static async Task Main(string[] args) {
        // Find your Account SID and Auth Token at twilio.com/console
        // and set the environment variables. See http://twil.io/secure
        string accountSid = Environment.GetEnvironmentVariable("TWILIO_ACCOUNT_SID");
        string authToken = Environment.GetEnvironmentVariable("TWILIO_AUTH_TOKEN");

        TwilioClient.Init(accountSid, authToken);

        var functionVersion = await FunctionVersionResource.FetchAsync(
            pathServiceSid: "ServiceSid",
            pathFunctionSid: "ZHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
            pathSid: "ZNaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa");

        Console.WriteLine(functionVersion.Sid);
    }
}
```

```java
// Install the Java helper library from twilio.com/docs/java/install

import com.twilio.Twilio;
import com.twilio.rest.serverless.v1.service.function.FunctionVersion;

public class Example {
    // Find your Account SID and Auth Token at twilio.com/console
    // and set the environment variables. See http://twil.io/secure
    public static final String ACCOUNT_SID = System.getenv("TWILIO_ACCOUNT_SID");
    public static final String AUTH_TOKEN = System.getenv("TWILIO_AUTH_TOKEN");

    public static void main(String[] args) {
        Twilio.init(ACCOUNT_SID, AUTH_TOKEN);
        FunctionVersion functionVersion =
            FunctionVersion
                .fetcher("ServiceSid", "ZHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "ZNaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")
                .fetch();

        System.out.println(functionVersion.getSid());
    }
}
```

```go
// Download the helper library from https://www.twilio.com/docs/go/install
package main

import (
	"fmt"
	"github.com/twilio/twilio-go"
	"os"
)

func main() {
	// Find your Account SID and Auth Token at twilio.com/console
	// and set the environment variables. See http://twil.io/secure
	// Make sure TWILIO_ACCOUNT_SID and TWILIO_AUTH_TOKEN exists in your environment
	client := twilio.NewRestClient()

	resp, err := client.ServerlessV1.FetchFunctionVersion("ServiceSid",
		"ZHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
		"ZNaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")
	if err != nil {
		fmt.Println(err.Error())
		os.Exit(1)
	} else {
		if resp.Sid != nil {
			fmt.Println(*resp.Sid)
		} else {
			fmt.Println(resp.Sid)
		}
	}
}
```

```php
<?php

// Update the path below to your autoload.php,
// see https://getcomposer.org/doc/01-basic-usage.md
require_once "/path/to/vendor/autoload.php";

use Twilio\Rest\Client;

// Find your Account SID and Auth Token at twilio.com/console
// and set the environment variables. See http://twil.io/secure
$sid = getenv("TWILIO_ACCOUNT_SID");
$token = getenv("TWILIO_AUTH_TOKEN");
$twilio = new Client($sid, $token);

$function_version = $twilio->serverless->v1
    ->services("ServiceSid")
    ->functions("ZHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")
    ->functionVersions("ZNaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")
    ->fetch();

print $function_version->sid;
```

```ruby
# Download the helper library from https://www.twilio.com/docs/ruby/install
require 'twilio-ruby'

# Find your Account SID and Auth Token at twilio.com/console
# and set the environment variables. See http://twil.io/secure
account_sid = ENV['TWILIO_ACCOUNT_SID']
auth_token = ENV['TWILIO_AUTH_TOKEN']
@client = Twilio::REST::Client.new(account_sid, auth_token)

function_version = @client
                   .serverless
                   .v1
                   .services('ServiceSid')
                   .functions('ZHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa')
                   .function_versions('ZNaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa')
                   .fetch

puts function_version.sid
```

```bash
# Install the twilio-cli from https://twil.io/cli

twilio api:serverless:v1:services:functions:versions:fetch \
   --service-sid ServiceSid \
   --function-sid ZHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa \
   --sid ZNaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
```

```bash
curl -X GET "https://serverless.twilio.com/v1/Services/ServiceSid/Functions/ZHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Versions/ZNaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" \
-u $TWILIO_ACCOUNT_SID:$TWILIO_AUTH_TOKEN
```

```json
{
  "sid": "ZNaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
  "account_sid": "ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
  "service_sid": "ServiceSid",
  "function_sid": "ZHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
  "path": "/test-path",
  "visibility": "public",
  "date_created": "2018-11-10T20:00:00Z",
  "url": "https://serverless.twilio.com/v1/Services/ZS00000000000000000000000000000000/Functions/ZH00000000000000000000000000000000/Versions/ZN00000000000000000000000000000000",
  "links": {
    "function_version_content": "https://serverless.twilio.com/v1/Services/ZS00000000000000000000000000000000/Functions/ZH00000000000000000000000000000000/Versions/ZN00000000000000000000000000000000/Content"
  }
}
```

## Read multiple FunctionVersion resources

`GET https://serverless.twilio.com/v1/Services/{ServiceSid}/Functions/{FunctionSid}/Versions`

### Path parameters

```json
[{"name":"ServiceSid","in":"path","description":"The SID of the Service to read the Function Version resources from.","schema":{"type":"string"},"required":true},{"name":"FunctionSid","in":"path","description":"The SID of the function that is the parent of the Function Version resources to read.","schema":{"type":"string","minLength":34,"maxLength":34,"pattern":"^ZH[0-9a-fA-F]{32}$"},"required":true}]
```

### Query parameters

```json
[{"name":"PageSize","in":"query","description":"How many resources to return in each list page. The default is 50, and the maximum is 1000.","schema":{"type":"integer","format":"int64","minimum":1,"maximum":1000}},{"name":"Page","in":"query","description":"The page index. This value is simply for client state.","schema":{"type":"integer","minimum":0}},{"name":"PageToken","in":"query","description":"The page token. This is provided by the API.","schema":{"type":"string"}}]
```

Read multiple Function Version resources

```js
// Download the helper library from https://www.twilio.com/docs/node/install
const twilio = require("twilio"); // Or, for ESM: import twilio from "twilio";

// Find your Account SID and Auth Token at twilio.com/console
// and set the environment variables. See http://twil.io/secure
const accountSid = process.env.TWILIO_ACCOUNT_SID;
const authToken = process.env.TWILIO_AUTH_TOKEN;
const client = twilio(accountSid, authToken);

async function listFunctionVersion() {
  const functionVersions = await client.serverless.v1
    .services("ServiceSid")
    .functions("ZHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")
    .functionVersions.list({ limit: 20 });

  functionVersions.forEach((f) => console.log(f.sid));
}

listFunctionVersion();
```

```python
# Download the helper library from https://www.twilio.com/docs/python/install
import os
from twilio.rest import Client

# Find your Account SID and Auth Token at twilio.com/console
# and set the environment variables. See http://twil.io/secure
account_sid = os.environ["TWILIO_ACCOUNT_SID"]
auth_token = os.environ["TWILIO_AUTH_TOKEN"]
client = Client(account_sid, auth_token)

function_versions = (
    client.serverless.v1.services("ServiceSid")
    .functions("ZHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")
    .function_versions.list(limit=20)
)

for record in function_versions:
    print(record.sid)
```

```csharp
// Install the C# / .NET helper library from twilio.com/docs/csharp/install

using System;
using Twilio;
using Twilio.Rest.Serverless.V1.Service.Function;
using System.Threading.Tasks;

class Program {
    public static async Task Main(string[] args) {
        // Find your Account SID and Auth Token at twilio.com/console
        // and set the environment variables. See http://twil.io/secure
        string accountSid = Environment.GetEnvironmentVariable("TWILIO_ACCOUNT_SID");
        string authToken = Environment.GetEnvironmentVariable("TWILIO_AUTH_TOKEN");

        TwilioClient.Init(accountSid, authToken);

        var functionVersions = await FunctionVersionResource.ReadAsync(
            pathServiceSid: "ServiceSid",
            pathFunctionSid: "ZHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
            limit: 20);

        foreach (var record in functionVersions) {
            Console.WriteLine(record.Sid);
        }
    }
}
```

```java
// Install the Java helper library from twilio.com/docs/java/install

import com.twilio.Twilio;
import com.twilio.rest.serverless.v1.service.function.FunctionVersion;
import com.twilio.base.ResourceSet;

public class Example {
    // Find your Account SID and Auth Token at twilio.com/console
    // and set the environment variables. See http://twil.io/secure
    public static final String ACCOUNT_SID = System.getenv("TWILIO_ACCOUNT_SID");
    public static final String AUTH_TOKEN = System.getenv("TWILIO_AUTH_TOKEN");

    public static void main(String[] args) {
        Twilio.init(ACCOUNT_SID, AUTH_TOKEN);
        ResourceSet<FunctionVersion> functionVersions =
            FunctionVersion.reader("ServiceSid", "ZHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa").limit(20).read();

        for (FunctionVersion record : functionVersions) {
            System.out.println(record.getSid());
        }
    }
}
```

```go
// Download the helper library from https://www.twilio.com/docs/go/install
package main

import (
	"fmt"
	"github.com/twilio/twilio-go"
	serverless "github.com/twilio/twilio-go/rest/serverless/v1"
	"os"
)

func main() {
	// Find your Account SID and Auth Token at twilio.com/console
	// and set the environment variables. See http://twil.io/secure
	// Make sure TWILIO_ACCOUNT_SID and TWILIO_AUTH_TOKEN exists in your environment
	client := twilio.NewRestClient()

	params := &serverless.ListFunctionVersionParams{}
	params.SetLimit(20)

	resp, err := client.ServerlessV1.ListFunctionVersion("ServiceSid",
		"ZHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
		params)
	if err != nil {
		fmt.Println(err.Error())
		os.Exit(1)
	} else {
		for record := range resp {
			if resp[record].Sid != nil {
				fmt.Println(*resp[record].Sid)
			} else {
				fmt.Println(resp[record].Sid)
			}
		}
	}
}
```

```php
<?php

// Update the path below to your autoload.php,
// see https://getcomposer.org/doc/01-basic-usage.md
require_once "/path/to/vendor/autoload.php";

use Twilio\Rest\Client;

// Find your Account SID and Auth Token at twilio.com/console
// and set the environment variables. See http://twil.io/secure
$sid = getenv("TWILIO_ACCOUNT_SID");
$token = getenv("TWILIO_AUTH_TOKEN");
$twilio = new Client($sid, $token);

$functionVersions = $twilio->serverless->v1
    ->services("ServiceSid")
    ->functions("ZHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")
    ->functionVersions->read(20);

foreach ($functionVersions as $record) {
    print $record->sid;
}
```

```ruby
# Download the helper library from https://www.twilio.com/docs/ruby/install
require 'twilio-ruby'

# Find your Account SID and Auth Token at twilio.com/console
# and set the environment variables. See http://twil.io/secure
account_sid = ENV['TWILIO_ACCOUNT_SID']
auth_token = ENV['TWILIO_AUTH_TOKEN']
@client = Twilio::REST::Client.new(account_sid, auth_token)

function_versions = @client
                    .serverless
                    .v1
                    .services('ServiceSid')
                    .functions('ZHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa')
                    .function_versions
                    .list(limit: 20)

function_versions.each do |record|
   puts record.sid
end
```

```bash
# Install the twilio-cli from https://twil.io/cli

twilio api:serverless:v1:services:functions:versions:list \
   --service-sid ServiceSid \
   --function-sid ZHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
```

```bash
curl -X GET "https://serverless.twilio.com/v1/Services/ServiceSid/Functions/ZHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Versions?PageSize=20" \
-u $TWILIO_ACCOUNT_SID:$TWILIO_AUTH_TOKEN
```

```json
{
  "function_versions": [],
  "meta": {
    "first_page_url": "https://serverless.twilio.com/v1/Services/ZS00000000000000000000000000000000/Functions/ZH00000000000000000000000000000000/Versions?PageSize=50&Page=0",
    "key": "function_versions",
    "next_page_url": null,
    "page": 0,
    "page_size": 50,
    "previous_page_url": null,
    "url": "https://serverless.twilio.com/v1/Services/ZS00000000000000000000000000000000/Functions/ZH00000000000000000000000000000000/Versions?PageSize=50&Page=0"
  }
}
```

> \[!NOTE]
>
> There is no API endpoint for deleting a Function Version, only [Functions](/docs/serverless/api/resource/function). Function Versions are automatically purged if they are not used by a Build for 30 days. See our [retention policy](/docs/serverless/api#retention-policy) to learn more.
