Skip to content
Get started
TypeScript

Assets

API reference for enhanced asset methods.

The assets resource is enhanced so that retrieve() and update() return responses where response.asset has a .download() method. All other asset methods (create, list, delete) are inherited unchanged.


Get an asset by ID. Returns an enhanced response where response.asset has .download().

Signature

client.assets.retrieve(
assetID: string,
query?: AssetRetrieveParams | null,
options?: RequestOptions,
): APIPromise<WithAsset<AssetRetrieveResponse>>

Parameters

NameTypeDescription
assetIDstringThe asset ID to retrieve.
query?AssetRetrieveParams | nullOptional query parameters.

Returns

APIPromise<WithAsset<AssetRetrieveResponse>> — the standard retrieve response with asset enhanced:

PropertyTypeDescription
assetAssetRetrieveResponse.Asset & AssetMethodsAll original asset fields plus .download().

Example

import Scenario from '@scenario-labs/sdk';
const client = new Scenario({ apiKey: '...' });
const { asset } = await client.assets.retrieve('asset_...');
console.log(asset.id); // original field
console.log(asset.url); // original field

Update an asset. Returns an enhanced response where response.asset has .download().

Signature

client.assets.update(
assetID: string,
params: AssetUpdateParams,
options?: RequestOptions,
): APIPromise<WithAsset<AssetUpdateResponse>>

Parameters

NameTypeDescription
assetIDstringThe asset ID to update.
paramsAssetUpdateParamsFields to update (see API Reference).

Returns

APIPromise<WithAsset<AssetUpdateResponse>> — the update response with asset enhanced.


Available on response.asset after calling client.assets.retrieve() or client.assets.update(). Fetches the asset’s content as bytes using the signed url field on the asset. Works in Node ≥ 18 and in browsers with no extra setup.

Signature

asset.download(): Promise<Uint8Array>

Parameters

None.

Returns

Promise<Uint8Array> — the raw bytes of the asset.

Errors

Throws Error if the HTTP response is not OK (e.g. Failed to download asset asset_...: 403 Forbidden).

Example

import Scenario from '@scenario-labs/sdk';
import fs from 'node:fs/promises';
const client = new Scenario({ apiKey: '...' });
const { asset } = await client.assets.retrieve('asset_...');
const bytes = await asset.download();
await fs.writeFile('out.png', bytes);