Skip to content

Vonage Media

github-actions edited this page Oct 17, 2024 · 56 revisions

Vonage MediaDocs


Documentation / Vonage Media

Vonage Media

Classes

Media

Client class to interact with the Media API which enables users to manage their media items programmatically.

Remarks

This client is only available as a standalone client. It cannot be instantiated from the server-sdk package.

Example

Create a standalone Secret client

import { Media } from '@vonage/media';

const mediaClient = new Media({
 apiKey: VONAGE_API_KEY,
 apiSecret: VONAGE_API_SECRET
});

Extends

Constructors

new Media()
new Media(credentials, options?): Media

Creates a new instance of the Client.

Parameters

credentials: AuthInterface | AuthParams

The authentication credentials or an authentication instance.

options?: ConfigParams

Optional configuration settings for the client.

Returns

Media

Inherited from

Client.constructor

Defined in

server-client/dist/lib/client.d.ts:35

Properties

auth
protected auth: AuthInterface;

The authentication instance responsible for generating authentication headers and query parameters.

Inherited from

Client.auth

Defined in

server-client/dist/lib/client.d.ts:24

authType
protected authType: AuthenticationType = AuthenticationType.JWT;

The type of authentication used for the client's requests.

Overrides

Client.authType

Defined in

media/lib/media.ts:33

config
protected config: ConfigParams;

Configuration settings for the client, including default hosts for various services and other request settings.

Inherited from

Client.config

Defined in

server-client/dist/lib/client.d.ts:28

transformers
static transformers: object;

Static property containing utility transformers.

camelCaseObjectKeys
camelCaseObjectKeys: PartialTransformFunction;
kebabCaseObjectKeys
kebabCaseObjectKeys: PartialTransformFunction;
omit()
omit: (keys, obj) => TransformedObject;
Parameters

keys: string[]

obj: ObjectToTransform

Returns

TransformedObject

snakeCaseObjectKeys
snakeCaseObjectKeys: PartialTransformFunction;
Inherited from

Client.transformers

Defined in

server-client/dist/lib/client.d.ts:11

Methods

addAuthenticationToRequest()
addAuthenticationToRequest(request): Promise<VetchOptions>

Adds the appropriate authentication headers or parameters to the request based on the authentication type.

Parameters

request: VetchOptions

The request options to which authentication needs to be added.

Returns

Promise<VetchOptions>

  • The request options with the added authentication.
Inherited from

Client.addAuthenticationToRequest

Defined in

server-client/dist/lib/client.d.ts:43

addBasicAuthToRequest()
protected addBasicAuthToRequest(request): Promise<VetchOptions>

Adds basic authentication headers to the request.

Parameters

request: VetchOptions

The request options to which authentication needs to be added.

Returns

Promise<VetchOptions>

  • The request options with the added authentication.
Inherited from

Client.addBasicAuthToRequest

Defined in

server-client/dist/lib/client.d.ts:71

addJWTToRequest()
protected addJWTToRequest(request): Promise<VetchOptions>

Adds a JWT to the request.

Parameters

request: VetchOptions

The request options to which authentication needs to be added.

Returns

Promise<VetchOptions>

  • The request options with the added authentication.
Inherited from

Client.addJWTToRequest

Defined in

server-client/dist/lib/client.d.ts:64

addQueryKeySecretToRequest()
protected addQueryKeySecretToRequest(request): Promise<VetchOptions>

Adds API key and secret to the request.

Parameters

request: VetchOptions

The request options to which authentication needs to be added.

Returns

Promise<VetchOptions>

  • The request options with the added authentication.
Inherited from

Client.addQueryKeySecretToRequest

Defined in

server-client/dist/lib/client.d.ts:57

addQueryKeySecretToRequestBody()
protected addQueryKeySecretToRequestBody(request): Promise<VetchOptions>

Adds API key and secret to the request body.

Parameters

request: VetchOptions

The request options to which authentication needs to be added.

Returns

Promise<VetchOptions>

  • The request options with the added authentication.
Inherited from

Client.addQueryKeySecretToRequestBody

Defined in

server-client/dist/lib/client.d.ts:50

deleteMediaItem()
deleteMediaItem(mediaId): Promise<void>

Deletes a specific media item by its unique identifier.

Parameters

mediaId: string

The unique identifier of the media item to be deleted.

Returns

Promise<void>

A promise that resolves once the media item is successfully deleted.

Example

Delete a media item

await mediaClient.deleteMediaItem('my-media-id');
Defined in

media/lib/media.ts:172

getConfig()
getConfig(): ConfigParams
Returns

ConfigParams

Inherited from

Client.getConfig

Defined in

server-client/dist/lib/client.d.ts:36

getMediaItem()
getMediaItem(mediaId): Promise<MediaItem>

Retrieves information about a specific media item by its unique identifier.

Parameters

mediaId: string

The unique identifier of the media item.

Returns

Promise<MediaItem>

A promise that resolves to a MediaItem object representing the retrieved media item.

Example

Retrieve a media item by its ID

const media = await mediaClient.getMediaItem('my-media-id');
console.log(`Media item ${media.id} is ${media.public ? 'public' : 'private'}`);
console.log(`  - Title: ${media.title}`);
console.log(`  - Description: ${media.description}`);
Defined in

media/lib/media.ts:120

getMediaPage()
getMediaPage(params): Promise<MediaItemPageResponse>

Retrieves a page of media items based on the specified parameters.

Parameters

params: MediaParameters = {}

Optional parameters for customizing the media page request.

Returns

Promise<MediaItemPageResponse>

A promise that resolves to a MediaItemPageResponse object representing the page of media items.

Example

List the first page of media items

const resp = await mediaClient.getMediaPage();

console.log(`There are ${resp.count} media items in total`);
console.log(`Showing ${resp._embedded.media.length} media items on this page`);
Defined in

media/lib/media.ts:93

listAllMediaItems()
listAllMediaItems(params): AsyncGenerator<MediaItem, void & MediaItem, undefined>

Retrieves a paginated list of media items, yielding each item sequentially.

Parameters

params: MediaParameters = {}

Optional parameters for customizing the media list request.

Returns

AsyncGenerator<MediaItem, undefined>

An asynchronous generator that yields MediaItem objects.

Examples

List all media items

for await (const media of mediaClient.listAllMediaItems()) {
  console.log(`Media item ${media.id} is ${media.public ? 'public' : 'private'}`);
  console.log(`  - Title: ${media.title}`);
  console.log(`  - Description: ${media.description}`);
};

List all public media items

for await (const media of mediaClient.listAllMediaItems({ public: true })) {
  console.log(`Media item ${media.id} is public`);
  console.log(`  - Title: ${media.title}`);
  console.log(`  - Description: ${media.description}`);
};
Defined in

media/lib/media.ts:61

parseResponse()
protected parseResponse<T>(request, response): Promise<VetchResponse<T>>

Parses the response based on its content type.

Type Parameters

T

The expected type of the parsed response data.

Parameters

request: VetchOptions

The request options.

response: Response

The raw response from the request.

Returns

Promise<VetchResponse<T>>

  • The parsed response.
Inherited from

Client.parseResponse

Defined in

server-client/dist/lib/client.d.ts:168

prepareBody()
protected prepareBody(request): undefined | string

Prepares the body for the request based on the content type.

Parameters

request: VetchOptions

The request options.

Returns

undefined | string

  • The prepared request body as a string or undefined.
Inherited from

Client.prepareBody

Defined in

server-client/dist/lib/client.d.ts:158

prepareRequest()
protected prepareRequest(request): Promise<VetchOptions>

Prepares the request with necessary headers, authentication, and query parameters.

Parameters

request: VetchOptions

The initial request options.

Returns

Promise<VetchOptions>

  • The modified request options.
Inherited from

Client.prepareRequest

Defined in

server-client/dist/lib/client.d.ts:151

sendDeleteRequest()
sendDeleteRequest<T>(url): Promise<VetchResponse<T>>

Sends a DELETE request to the specified URL.

Type Parameters

T

Parameters

url: string

The URL endpoint for the DELETE request.

Returns

Promise<VetchResponse<T>>

  • The response from the DELETE request.
Inherited from

Client.sendDeleteRequest

Defined in

server-client/dist/lib/client.d.ts:78

sendFormSubmitRequest()
sendFormSubmitRequest<T>(url, payload?): Promise<VetchResponse<T>>

Sends a POST request with form data to the specified URL.

Type Parameters

T

Parameters

url: string

The URL endpoint for the POST request.

payload?: Record<string, string>

Optional payload containing form data to send with the POST request.

Returns

Promise<VetchResponse<T>>

  • The response from the POST request.
Inherited from

Client.sendFormSubmitRequest

Defined in

server-client/dist/lib/client.d.ts:86

sendGetRequest()
sendGetRequest<T>(url, queryParams?): Promise<VetchResponse<T>>

Sends a GET request to the specified URL with optional query parameters.

Type Parameters

T

Parameters

url: string

The URL endpoint for the GET request.

queryParams?

Optional query parameters to append to the URL. These should be compatible with Node's URLSearchParams.

Returns

Promise<VetchResponse<T>>

  • The response from the GET request.
Inherited from

Client.sendGetRequest

Defined in

server-client/dist/lib/client.d.ts:94

sendPatchRequest()
sendPatchRequest<T>(url, payload?): Promise<VetchResponse<T>>

Sends a PATCH request to the specified URL with an optional payload.

Type Parameters

T

Parameters

url: string

The URL endpoint for the PATCH request.

payload?

Optional payload to be sent as the body of the PATCH request.

Returns

Promise<VetchResponse<T>>

  • The response from the PATCH request.
Inherited from

Client.sendPatchRequest

Defined in

server-client/dist/lib/client.d.ts:104

sendPostRequest()
sendPostRequest<T>(url, payload?): Promise<VetchResponse<T>>

Sends a POST request to the specified URL with an optional payload.

Type Parameters

T

Parameters

url: string

The URL endpoint for the POST request.

payload?

Optional payload to be sent as the body of the POST request.

Returns

Promise<VetchResponse<T>>

  • The response from the POST request.
Inherited from

Client.sendPostRequest

Defined in

server-client/dist/lib/client.d.ts:114

sendPutRequest()
sendPutRequest<T>(url, payload?): Promise<VetchResponse<T>>

Sends a PUT request to the specified URL with an optional payload.

Type Parameters

T

Parameters

url: string

The URL endpoint for the PUT request.

payload?

Optional payload to be sent as the body of the PUT request.

Returns

Promise<VetchResponse<T>>

  • The response from the PUT request.
Inherited from

Client.sendPutRequest

Defined in

server-client/dist/lib/client.d.ts:124

sendRequest()
sendRequest<T>(request): Promise<VetchResponse<T>>

Sends a request adding necessary headers, handling authentication, and parsing the response.

Type Parameters

T

Parameters

request: VetchOptions

The options defining the request, including URL, method, headers, and data.

Returns

Promise<VetchResponse<T>>

  • The parsed response from the request.
Inherited from

Client.sendRequest

Defined in

server-client/dist/lib/client.d.ts:144

sendRequestWithData()
sendRequestWithData<T>(
   method, 
   url, 
payload?): Promise<VetchResponse<T>>

Sends a request with JSON-encoded data to the specified URL using the provided HTTP method.

Type Parameters

T

Parameters

method: POST | PUT | PATCH

The HTTP method to be used for the request (only POST, PATCH, or PUT are acceptable).

url: string

The URL endpoint for the request.

payload?

Optional payload to be sent as the body of the request, JSON-encoded.

Returns

Promise<VetchResponse<T>>

  • The response from the request.
Inherited from

Client.sendRequestWithData

Defined in

server-client/dist/lib/client.d.ts:135

updateMediaItem()
updateMediaItem(media): Promise<void>

Updates the information of a specific media item based on the provided data.

Parameters

media: MediaItem

The updated media item data.

Returns

Promise<void>

A promise that resolves once the media item is successfully updated.

Example

Update a media item

const media = await mediaClient.getMediaItem('my-media-id');
media.title = 'My new title';
media.description = 'My new description';
await mediaClient.updateMediaItem(media);
Defined in

media/lib/media.ts:144

Type Aliases

MediaItem

type MediaItem: object;

Represents a media item.

Type declaration

accountId
accountId: string;

The ID of your Nexmo account. This is the same as your API key.

description?
optional description: string;

An optional description of the media file.

etag
etag: string;

An identifier for the content. This will change if the content of the file has been changed (i.e., if you upload a new version of the file). For more information, see Wikipedia: HTTP ETag.

id
id: string;

A UUID representing the object.

maxDownloadsAllowed
maxDownloadsAllowed: number;

The maximum number of times the file may be downloaded.

mediaSize
mediaSize: number;

The size of the file in bytes.

metadataPrimary?
optional metadataPrimary: string | null;

A user-set string containing metadata about the media file.

metadataSecondary?
optional metadataSecondary: string | null;

A user-set string containing further metadata about the media file.

mimeType
mimeType: string;

The IETF MIME type of the file.

originalFileName
originalFileName: string;

The filename of the object as it was originally uploaded.

public
public: boolean;

Whether the item is available for download without authentication.

storeId
storeId: string;

An internal identifier of how the file is stored.

timeCreated
timeCreated: string;

A timestamp for the time that the file was created.

timeLastUpdated
timeLastUpdated: string;

A timestamp for the time that the file was last modified.

timesDownloaded
timesDownloaded: number;

The number of times the file has been downloaded.

title?
optional title: string;

An optional title for the media file.

Defined in

media/lib/types/mediaItem.ts:4


MediaItemPageResponse

type MediaItemPageResponse: object & APILinks;

Represents the response data for a page of media items.

Type declaration

_embedded
_embedded: object;

A collection of media items.

_embedded.media
_embedded.media: MediaItemResponse[];
count
count: number;

The total number of records returned by your request.

page_index
page_index: number;

The page_index used in your request.

page_size
page_size: number;

The amount of records returned in this response.

Remarks

Vonage API's will return information using snake_case. This represents the pure response before the client will transform the keys into camelCase.

Defined in

media/lib/types/Responses/mediaItemResponsePage.ts:11


MediaItemResponse

type MediaItemResponse: object;

Represents the response data for a media item.

Type declaration

account_id
account_id: string;

The ID of your Nexmo account. This is the same as your API key.

etag
etag: string;

An identifier for the content. This will change if the content of the file has been changed (i.e., if you upload a new version of the file). For more information, see Wikipedia: HTTP ETag.

id
id: string;

A UUID representing the object.

max_downloads_allowed
max_downloads_allowed: number;

The maximum number of times the file may be downloaded.

media_size
media_size: number;

The size of the file in bytes.

metadata_primary?
optional metadata_primary: string | null;

A user-set string containing metadata about the media file.

metadata_secondary?
optional metadata_secondary: string | null;

A user-set string containing further metadata about the media file.

mime_type
mime_type: string;

The IETF MIME type of the file.

original_file_name
original_file_name: string;

The filename of the object as it was originally uploaded.

public
public: boolean;

Whether the item is available for download without authentication.

store_id
store_id: string;

An internal identifier of how the file is stored.

time_created
time_created: string;

A timestamp for the time that the file was created.

time_last_updated
time_last_updated: string;

A timestamp for the time that the file was last modified.

times_downloaded
times_downloaded: number;

The number of times the file has been downloaded.

Remarks

Vonage API's will return information using snake_case. This represents the pure response before the client will transform the keys into camelCase.

Defined in

media/lib/types/Responses/mediaItemResponse.ts:8


MediaParameters

type MediaParameters: object;

Represents parameters for querying media items.

Type declaration

endTime?
optional endTime: string;

Retrieve results created on or before this timestamp.

order?
optional order: "ascending" | "descending";

The order of search results. Must be one of 'ascending' or 'descending'.

pageIndex?
optional pageIndex: number;

Which page to retrieve in pagination.

pageSize?
optional pageSize: number;

How many items at most per page.

startTime?
optional startTime: string;

Retrieve results created on or after this timestamp.

Defined in

media/lib/types/mediaParameters.ts:4

Clone this wiki locally