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.
client.assets.retrieve(assetID)
Section titled “client.assets.retrieve(assetID)”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
| Name | Type | Description |
|---|---|---|
assetID | string | The asset ID to retrieve. |
query? | AssetRetrieveParams | null | Optional query parameters. |
Returns
APIPromise<WithAsset<AssetRetrieveResponse>> — the standard retrieve response with asset enhanced:
| Property | Type | Description |
|---|---|---|
asset | AssetRetrieveResponse.Asset & AssetMethods | All 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 fieldconsole.log(asset.url); // original fieldclient.assets.update(assetID, params)
Section titled “client.assets.update(assetID, params)”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
| Name | Type | Description |
|---|---|---|
assetID | string | The asset ID to update. |
params | AssetUpdateParams | Fields to update (see API Reference). |
Returns
APIPromise<WithAsset<AssetUpdateResponse>> — the update response with asset enhanced.
asset.download()
Section titled “asset.download()”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);