Skip to contentSkip to navigationSkip to topbar
Rate this page:
On this page

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 nameTypePIIDescription
sidSID<ZN>
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

account_sidSID<AC>

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

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

service_sidSID<ZS>

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

asset_sidSID<ZH>

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
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>

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

Possible values:
publicprivateprotected

urlstring<uri>

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 Asset

upload-asset page anchor
Node.js
Python
C#
Java
PHP
Ruby
curl

_36
const fs = require('fs');
_36
// Before running this code, install "form-data" and "axios" using `npm install form-data axios`
_36
const FormData = require('form-data');
_36
const axios = require('axios');
_36
_36
// Find your Account SID and Auth Token at twilio.com/console
_36
// and set the environment variables. See http://twil.io/secure
_36
const apiKey = process.env.TWILIO_API_KEY;
_36
const apiSecret = process.env.TWILIO_API_SECRET;
_36
_36
const serviceSid = 'ZSXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX';
_36
const assetSid = 'ZHXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX';
_36
_36
const serviceUrl = `https://serverless-upload.twilio.com/v1/Services/${serviceSid}`;
_36
const uploadUrl = `${serviceUrl}/Assets/${assetSid}/Versions`;
_36
_36
const form = new FormData();
_36
form.append('Path', '/my-asset.png');
_36
form.append('Visibility', 'public');
_36
form.append('Content', fs.createReadStream('my-asset.png'), {
_36
contentType: 'image/png',
_36
});
_36
_36
// Create a new Asset Version
_36
axios
_36
.post(uploadUrl, form, {
_36
auth: {
_36
username: apiKey,
_36
password: apiSecret,
_36
},
_36
headers: form.getHeaders(),
_36
})
_36
.then((response) => {
_36
const newVersionSid = response.data.sid;
_36
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 Helper Libraries 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
ServiceSidstringrequired

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

Fetch an Asset Version resource

fetch-an-asset-version-resource page anchor
Node.js
Python
C#
Java
Go
PHP
Ruby
twilio-cli
curl

_12
// Download the helper library from https://www.twilio.com/docs/node/install
_12
// Find your Account SID and Auth Token at twilio.com/console
_12
// and set the environment variables. See http://twil.io/secure
_12
const accountSid = process.env.TWILIO_ACCOUNT_SID;
_12
const authToken = process.env.TWILIO_AUTH_TOKEN;
_12
const client = require('twilio')(accountSid, authToken);
_12
_12
client.serverless.v1.services('ZSXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX')
_12
.assets('ZHXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX')
_12
.assetVersions('ZNXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX')
_12
.fetch()
_12
.then(asset_version => console.log(asset_version.sid));

Output

_10
{
_10
"sid": "ZNXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
_10
"account_sid": "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
_10
"service_sid": "ZSXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
_10
"asset_sid": "ZHXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
_10
"path": "/test-path",
_10
"visibility": "public",
_10
"date_created": "2018-11-10T20:00:00Z",
_10
"url": "https://serverless.twilio.com/v1/Services/ZSXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/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
ServiceSidstringrequired

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
PageSizeintegerOptional

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

Minimum: 1Maximum: 1000

PageintegerOptional

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

Minimum: 0

PageTokenstringOptional

The page token. This is provided by the API.

Read multiple Asset Version resources

read-multiple-asset-version-resources page anchor
Node.js
Python
C#
Java
Go
PHP
Ruby
twilio-cli
curl

_12
// Download the helper library from https://www.twilio.com/docs/node/install
_12
// Find your Account SID and Auth Token at twilio.com/console
_12
// and set the environment variables. See http://twil.io/secure
_12
const accountSid = process.env.TWILIO_ACCOUNT_SID;
_12
const authToken = process.env.TWILIO_AUTH_TOKEN;
_12
const client = require('twilio')(accountSid, authToken);
_12
_12
client.serverless.v1.services('ZSXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX')
_12
.assets('ZHXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX')
_12
.assetVersions
_12
.list({limit: 20})
_12
.then(assetVersions => assetVersions.forEach(a => console.log(a.sid)));

Output

_12
{
_12
"asset_versions": [],
_12
"meta": {
_12
"first_page_url": "https://serverless.twilio.com/v1/Services/ZSXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Assets/ZH00000000000000000000000000000000/Versions?PageSize=50&Page=0",
_12
"key": "asset_versions",
_12
"next_page_url": "https://serverless.twilio.com/v1/Services/ZSXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Assets/ZH00000000000000000000000000000000/Versions?PageSize=50&Page=1",
_12
"page": 0,
_12
"page_size": 50,
_12
"previous_page_url": "https://serverless.twilio.com/v1/Services/ZSXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Assets/ZH00000000000000000000000000000000/Versions?PageSize=50&Page=0",
_12
"url": "https://serverless.twilio.com/v1/Services/ZSXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Assets/ZH00000000000000000000000000000000/Versions?PageSize=50&Page=0"
_12
}
_12
}


Rate this page: