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

Asset Version


Asset Versions are specific instances of static files that you can host at a particular domain in an Environment.

The steps to create Assets are as follows:

  1. Create an Asset
  2. Create an Asset Version (this resource)

You will need the Asset Version SID that the create request returns to include this Asset in a Build.


Asset Version properties

asset-version-properties page anchor
Property nameTypeRequiredDescriptionChild properties
sidSID<ZN>

Optional

Not PII

The unique string that we created to identify the Asset Version resource.

Pattern: ^ZN[0-9a-fA-F]{32}$Min length: 34Max length: 34

accountSidSID<AC>

Optional

The SID of the Account that created the Asset Version resource.

Pattern: ^AC[0-9a-fA-F]{32}$Min length: 34Max length: 34

serviceSidSID<ZS>

Optional

The SID of the Service that the Asset Version resource is associated with.

Pattern: ^ZS[0-9a-fA-F]{32}$Min length: 34Max length: 34

assetSidSID<ZH>

Optional

The SID of the Asset resource that is the parent of the Asset Version.

Pattern: ^ZH[0-9a-fA-F]{32}$Min length: 34Max length: 34

pathstring

Optional

PII MTL: 7 days

The URL-friendly string by which the Asset Version can be referenced. It can be a maximum of 255 characters. All paths begin with a forward slash ('/'). If an Asset Version creation request is submitted with a path not containing a leading slash, the path will automatically be prepended with one.


visibilityenum<string>

Optional

The access control that determines how the Asset Version resource can be accessed. Can be: public, protected, or private.

Possible values:
publicprivateprotected

dateCreatedstring<date-time>

Optional


urlstring<uri>

Optional

The absolute URL of the Asset Version resource.


Create an Asset Version resource

create-an-asset-version-resource page anchor

Create an Asset Version resource to upload a file to an Asset resource. The Asset Version resource is created by making a POST request to a dedicated URL—a URL that is different from the URL used to read and fetch the resource.

https://serverless-upload.twilio.com/v1/Services/ {ServiceSid}/Assets/{AssetSid}/Versions

The following example creates an Asset Version resource using the language of your choice (or curl) and an external file, my-asset.png, which contains the Asset to upload.

Upload AssetLink to code sample: Upload Asset
1
const fs = require('fs');
2
// Before running this code, install "form-data" and "axios" using `npm install form-data axios`
3
const FormData = require('form-data');
4
const axios = require('axios');
5
6
// Find your Account SID and Auth Token at twilio.com/console
7
// and set the environment variables. See https://twil.io/secure
8
const apiKey = process.env.TWILIO_API_KEY;
9
const apiSecret = process.env.TWILIO_API_SECRET;
10
11
const serviceSid = 'ZSXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX';
12
const assetSid = 'ZHXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX';
13
14
const serviceUrl = `https://serverless-upload.twilio.com/v1/Services/${serviceSid}`;
15
const uploadUrl = `${serviceUrl}/Assets/${assetSid}/Versions`;
16
17
const form = new FormData();
18
form.append('Path', '/my-asset.png');
19
form.append('Visibility', 'public');
20
form.append('Content', fs.createReadStream('my-asset.png'), {
21
contentType: 'image/png',
22
});
23
24
// Create a new Asset Version
25
axios
26
.post(uploadUrl, form, {
27
auth: {
28
username: apiKey,
29
password: apiSecret,
30
},
31
headers: form.getHeaders(),
32
})
33
.then((response) => {
34
const newVersionSid = response.data.sid;
35
console.log(newVersionSid);
36
});
(warning)

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:

ParameterDescription
ContentThe asset to upload.
AssetSidThe SID of the Asset resource to upload this asset to.
PathThe path to assign the asset. Must be URL Friendly, without fragments, and ;,?:@+&$()' " are disallowed).
ServiceSidThe SID of the Asset's Service.
VisibilityThe visibility of the asset. Can be public, protected, or private.

Fetch an AssetVersion resource

fetch-an-assetversion-resource page anchor

GET https://serverless.twilio.com/v1/Services/{ServiceSid}/Assets/{AssetSid}/Versions/{Sid}

Path parameters

path-parameters page anchor
Property nameTypeRequiredPIIDescription
serviceSidstring
required

The SID of the Service to fetch the Asset Version resource from.


assetSidSID<ZH>
required

The SID of the Asset resource that is the parent of the Asset Version resource to fetch.

Pattern: ^ZH[0-9a-fA-F]{32}$Min length: 34Max length: 34

sidSID<ZN>
required

The SID of the Asset Version resource to fetch.

Pattern: ^ZN[0-9a-fA-F]{32}$Min length: 34Max length: 34
1
// Download the helper library from https://www.twilio.com/docs/node/install
2
const twilio = require("twilio"); // Or, for ESM: import twilio from "twilio";
3
4
// Find your Account SID and Auth Token at twilio.com/console
5
// and set the environment variables. See http://twil.io/secure
6
const accountSid = process.env.TWILIO_ACCOUNT_SID;
7
const authToken = process.env.TWILIO_AUTH_TOKEN;
8
const client = twilio(accountSid, authToken);
9
10
async function fetchAssetVersion() {
11
const assetVersion = await client.serverless.v1
12
.services("ServiceSid")
13
.assets("ZHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")
14
.assetVersions("ZNaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")
15
.fetch();
16
17
console.log(assetVersion.sid);
18
}
19
20
fetchAssetVersion();

Response

Note about this response
1
{
2
"sid": "ZNaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
3
"account_sid": "ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
4
"service_sid": "ServiceSid",
5
"asset_sid": "ZHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
6
"path": "/test-path",
7
"visibility": "public",
8
"date_created": "2018-11-10T20:00:00Z",
9
"url": "https://serverless.twilio.com/v1/Services/ZS00000000000000000000000000000000/Assets/ZH00000000000000000000000000000000/Versions/ZN00000000000000000000000000000000"
10
}

Read multiple AssetVersion resources

read-multiple-assetversion-resources page anchor

GET https://serverless.twilio.com/v1/Services/{ServiceSid}/Assets/{AssetSid}/Versions

Property nameTypeRequiredPIIDescription
serviceSidstring
required

The SID of the Service to read the Asset Version resource from.


assetSidSID<ZH>
required

The SID of the Asset resource that is the parent of the Asset Version resources to read.

Pattern: ^ZH[0-9a-fA-F]{32}$Min length: 34Max length: 34
Property nameTypeRequiredPIIDescription
pageSizeinteger<int64>

Optional

How many resources to return in each list page. The default is 50, and the maximum is 1000.

Minimum: 1Maximum: 1000

pageinteger

Optional

The page index. This value is simply for client state.

Minimum: 0

pageTokenstring

Optional

The page token. This is provided by the API.

1
// Download the helper library from https://www.twilio.com/docs/node/install
2
const twilio = require("twilio"); // Or, for ESM: import twilio from "twilio";
3
4
// Find your Account SID and Auth Token at twilio.com/console
5
// and set the environment variables. See http://twil.io/secure
6
const accountSid = process.env.TWILIO_ACCOUNT_SID;
7
const authToken = process.env.TWILIO_AUTH_TOKEN;
8
const client = twilio(accountSid, authToken);
9
10
async function listAssetVersion() {
11
const assetVersions = await client.serverless.v1
12
.services("ServiceSid")
13
.assets("ZHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")
14
.assetVersions.list({ limit: 20 });
15
16
assetVersions.forEach((a) => console.log(a.sid));
17
}
18
19
listAssetVersion();

Response

Note about this response
1
{
2
"asset_versions": [],
3
"meta": {
4
"first_page_url": "https://serverless.twilio.com/v1/Services/ZS00000000000000000000000000000000/Assets/ZH00000000000000000000000000000000/Versions?PageSize=50&Page=0",
5
"key": "asset_versions",
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/Assets/ZH00000000000000000000000000000000/Versions?PageSize=50&Page=0"
11
}
12
}