-
Notifications
You must be signed in to change notification settings - Fork 181
Vonage Media
Vonage Media • Docs
Documentation / Vonage Media
Client class to interact with the Media API which enables users to manage their media items programmatically.
This client is only available as a standalone client. It cannot be instantiated from the server-sdk package.
Create a standalone Secret client
import { Media } from '@vonage/media';
const mediaClient = new Media({
apiKey: VONAGE_API_KEY,
apiSecret: VONAGE_API_SECRET
});
new Media(credentials, options?): Media
Creates a new instance of the Client.
• credentials: AuthInterface
| AuthParams
The authentication credentials or an authentication instance.
• options?: ConfigParams
Optional configuration settings for the client.
server-client/dist/lib/client.d.ts:35
protected auth: AuthInterface;
The authentication instance responsible for generating authentication headers and query parameters.
server-client/dist/lib/client.d.ts:24
protected authType: AuthenticationType = AuthenticationType.JWT;
The type of authentication used for the client's requests.
protected config: ConfigParams;
Configuration settings for the client, including default hosts for various services and other request settings.
server-client/dist/lib/client.d.ts:28
static transformers: object;
Static property containing utility transformers.
camelCaseObjectKeys: PartialTransformFunction;
kebabCaseObjectKeys: PartialTransformFunction;
omit: (keys, obj) => TransformedObject;
• keys: string
[]
• obj: ObjectToTransform
snakeCaseObjectKeys: PartialTransformFunction;
server-client/dist/lib/client.d.ts:11
addAuthenticationToRequest(request): Promise<VetchOptions>
Adds the appropriate authentication headers or parameters to the request based on the authentication type.
• request: VetchOptions
The request options to which authentication needs to be added.
Promise
<VetchOptions
>
- The request options with the added authentication.
Client
.addAuthenticationToRequest
server-client/dist/lib/client.d.ts:43
protected addBasicAuthToRequest(request): Promise<VetchOptions>
Adds basic authentication headers to the request.
• request: VetchOptions
The request options to which authentication needs to be added.
Promise
<VetchOptions
>
- The request options with the added authentication.
server-client/dist/lib/client.d.ts:71
protected addJWTToRequest(request): Promise<VetchOptions>
Adds a JWT to the request.
• request: VetchOptions
The request options to which authentication needs to be added.
Promise
<VetchOptions
>
- The request options with the added authentication.
server-client/dist/lib/client.d.ts:64
protected addQueryKeySecretToRequest(request): Promise<VetchOptions>
Adds API key and secret to the request.
• request: VetchOptions
The request options to which authentication needs to be added.
Promise
<VetchOptions
>
- The request options with the added authentication.
Client
.addQueryKeySecretToRequest
server-client/dist/lib/client.d.ts:57
protected addQueryKeySecretToRequestBody(request): Promise<VetchOptions>
Adds API key and secret to the request body.
• request: VetchOptions
The request options to which authentication needs to be added.
Promise
<VetchOptions
>
- The request options with the added authentication.
Client
.addQueryKeySecretToRequestBody
server-client/dist/lib/client.d.ts:50
deleteMediaItem(mediaId): Promise<void>
Deletes a specific media item by its unique identifier.
• mediaId: string
The unique identifier of the media item to be deleted.
Promise
<void
>
A promise that resolves once the media item is successfully deleted.
Delete a media item
await mediaClient.deleteMediaItem('my-media-id');
getConfig(): ConfigParams
server-client/dist/lib/client.d.ts:36
getMediaItem(mediaId): Promise<MediaItem>
Retrieves information about a specific media item by its unique identifier.
• mediaId: string
The unique identifier of the media item.
Promise
<MediaItem
>
A promise that resolves to a MediaItem object representing the retrieved media item.
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}`);
getMediaPage(params): Promise<MediaItemPageResponse>
Retrieves a page of media items based on the specified parameters.
• params: MediaParameters
= {}
Optional parameters for customizing the media page request.
Promise
<MediaItemPageResponse
>
A promise that resolves to a MediaItemPageResponse object representing the page of media items.
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`);
listAllMediaItems(params): AsyncGenerator<MediaItem, void & MediaItem, undefined>
Retrieves a paginated list of media items, yielding each item sequentially.
• params: MediaParameters
= {}
Optional parameters for customizing the media list request.
AsyncGenerator
<MediaItem
, undefined
>
An asynchronous generator that yields MediaItem objects.
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}`);
};
protected parseResponse<T>(request, response): Promise<VetchResponse<T>>
Parses the response based on its content type.
• T
The expected type of the parsed response data.
• request: VetchOptions
The request options.
• response: Response
The raw response from the request.
Promise
<VetchResponse
<T
>>
- The parsed response.
server-client/dist/lib/client.d.ts:168
protected prepareBody(request): undefined | string
Prepares the body for the request based on the content type.
• request: VetchOptions
The request options.
undefined
| string
- The prepared request body as a string or undefined.
server-client/dist/lib/client.d.ts:158
protected prepareRequest(request): Promise<VetchOptions>
Prepares the request with necessary headers, authentication, and query parameters.
• request: VetchOptions
The initial request options.
Promise
<VetchOptions
>
- The modified request options.
server-client/dist/lib/client.d.ts:151
sendDeleteRequest<T>(url): Promise<VetchResponse<T>>
Sends a DELETE request to the specified URL.
• T
• url: string
The URL endpoint for the DELETE request.
Promise
<VetchResponse
<T
>>
- The response from the DELETE request.
server-client/dist/lib/client.d.ts:78
sendFormSubmitRequest<T>(url, payload?): Promise<VetchResponse<T>>
Sends a POST request with form data to the specified URL.
• T
• url: string
The URL endpoint for the POST request.
• payload?: Record
<string
, string
>
Optional payload containing form data to send with the POST request.
Promise
<VetchResponse
<T
>>
- The response from the POST request.
server-client/dist/lib/client.d.ts:86
sendGetRequest<T>(url, queryParams?): Promise<VetchResponse<T>>
Sends a GET request to the specified URL with optional query parameters.
• T
• 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.
Promise
<VetchResponse
<T
>>
- The response from the GET request.
server-client/dist/lib/client.d.ts:94
sendPatchRequest<T>(url, payload?): Promise<VetchResponse<T>>
Sends a PATCH request to the specified URL with an optional payload.
• T
• url: string
The URL endpoint for the PATCH request.
• payload?
Optional payload to be sent as the body of the PATCH request.
Promise
<VetchResponse
<T
>>
- The response from the PATCH request.
server-client/dist/lib/client.d.ts:104
sendPostRequest<T>(url, payload?): Promise<VetchResponse<T>>
Sends a POST request to the specified URL with an optional payload.
• T
• url: string
The URL endpoint for the POST request.
• payload?
Optional payload to be sent as the body of the POST request.
Promise
<VetchResponse
<T
>>
- The response from the POST request.
server-client/dist/lib/client.d.ts:114
sendPutRequest<T>(url, payload?): Promise<VetchResponse<T>>
Sends a PUT request to the specified URL with an optional payload.
• T
• url: string
The URL endpoint for the PUT request.
• payload?
Optional payload to be sent as the body of the PUT request.
Promise
<VetchResponse
<T
>>
- The response from the PUT request.
server-client/dist/lib/client.d.ts:124
sendRequest<T>(request): Promise<VetchResponse<T>>
Sends a request adding necessary headers, handling authentication, and parsing the response.
• T
• request: VetchOptions
The options defining the request, including URL, method, headers, and data.
Promise
<VetchResponse
<T
>>
- The parsed response from the request.
server-client/dist/lib/client.d.ts:144
sendRequestWithData<T>(
method,
url,
payload?): Promise<VetchResponse<T>>
Sends a request with JSON-encoded data to the specified URL using the provided HTTP method.
• T
• 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.
Promise
<VetchResponse
<T
>>
- The response from the request.
server-client/dist/lib/client.d.ts:135
updateMediaItem(media): Promise<void>
Updates the information of a specific media item based on the provided data.
• media: MediaItem
The updated media item data.
Promise
<void
>
A promise that resolves once the media item is successfully updated.
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);
type MediaItem: object;
Represents a media item.
accountId: string;
The ID of your Nexmo account. This is the same as your API key.
optional description: string;
An optional description of the media file.
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: string;
A UUID representing the object.
maxDownloadsAllowed: number;
The maximum number of times the file may be downloaded.
mediaSize: number;
The size of the file in bytes.
optional metadataPrimary: string | null;
A user-set string containing metadata about the media file.
optional metadataSecondary: string | null;
A user-set string containing further metadata about the media file.
mimeType: string;
The IETF MIME type of the file.
originalFileName: string;
The filename of the object as it was originally uploaded.
public: boolean;
Whether the item is available for download without authentication.
storeId: string;
An internal identifier of how the file is stored.
timeCreated: string;
A timestamp for the time that the file was created.
timeLastUpdated: string;
A timestamp for the time that the file was last modified.
timesDownloaded: number;
The number of times the file has been downloaded.
optional title: string;
An optional title for the media file.
media/lib/types/mediaItem.ts:4
type MediaItemPageResponse: object & APILinks;
Represents the response data for a page of media items.
_embedded: object;
A collection of media items.
_embedded.media: MediaItemResponse[];
count: number;
The total number of records returned by your request.
page_index: number;
The page_index used in your request.
page_size: number;
The amount of records returned in this response.
Vonage API's will return information using snake_case
. This represents the
pure response before the client will transform the keys into camelCase
.
media/lib/types/Responses/mediaItemResponsePage.ts:11
type MediaItemResponse: object;
Represents the response data for a media item.
account_id: string;
The ID of your Nexmo account. This is the same as your API key.
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: string;
A UUID representing the object.
max_downloads_allowed: number;
The maximum number of times the file may be downloaded.
media_size: number;
The size of the file in bytes.
optional metadata_primary: string | null;
A user-set string containing metadata about the media file.
optional metadata_secondary: string | null;
A user-set string containing further metadata about the media file.
mime_type: string;
The IETF MIME type of the file.
original_file_name: string;
The filename of the object as it was originally uploaded.
public: boolean;
Whether the item is available for download without authentication.
store_id: string;
An internal identifier of how the file is stored.
time_created: string;
A timestamp for the time that the file was created.
time_last_updated: string;
A timestamp for the time that the file was last modified.
times_downloaded: number;
The number of times the file has been downloaded.
Vonage API's will return information using snake_case
. This represents the
pure response before the client will transform the keys into camelCase
.
media/lib/types/Responses/mediaItemResponse.ts:8
type MediaParameters: object;
Represents parameters for querying media items.
optional endTime: string;
Retrieve results created on or before this timestamp.
optional order: "ascending" | "descending";
The order of search results. Must be one of 'ascending' or 'descending'.
optional pageIndex: number;
Which page to retrieve in pagination.
optional pageSize: number;
How many items at most per page.
optional startTime: string;
Retrieve results created on or after this timestamp.