Skip to content

Vonage Server Client

github-actions edited this page Jul 5, 2024 · 31 revisions

Vonage Server ClientDocs


Documentation / Vonage Server Client

Vonage Server Client

Enumerations

AuthenticationType

Enum representing the different types of authentication methods supported by the Vonage APIs.

Enumeration Members

Enumeration Member Value Description Defined in
BASIC "basic" Description Basic authentication using a base64-encoded string. packages/server-client/lib/enums/AuthenticationType.ts:9
JWT "jwt" Description JSON Web Token (JWT) authentication. packages/server-client/lib/enums/AuthenticationType.ts:14
KEY_SECRET "key_secret" Description Authentication using both API key and secret in the request body. Deprecated This method is deprecated. packages/server-client/lib/enums/AuthenticationType.ts:20
QUERY_KEY_SECRET "query_key_secret" Description Authentication using API key and secret in the query parameters. packages/server-client/lib/enums/AuthenticationType.ts:25
SIGNATURE "signature" Description HMAC signature-based authentication. packages/server-client/lib/enums/AuthenticationType.ts:30

GenericErrors

Enum representing the different types of generic error codes that might be returned by the Vonage APIs.

Enumeration Members

Enumeration Member Value Description Defined in
ACCEPT_HEADER "accept-header" The provided Accept header in the request is invalid. Invalid Accept header provided. Most Vonage APIs only send back application/json. Check the API documentation for the specific API you're working with for a complete list of supported data types. packages/server-client/lib/enums/GenericErrorCodes.ts:113
ACCOUNT_SUSPENDED "account-suspended" The account has been suspended. This account has been suspended. Contact support@api.vonage.com for more information. packages/server-client/lib/enums/GenericErrorCodes.ts:45
APPLICATION_SUSPENDED "application-suspended" The application associated with the request has been suspended. This application has been suspended. Re-enable the application or create a new application to use. packages/server-client/lib/enums/GenericErrorCodes.ts:135
CONTENT_TYPE_HEADER "content-type-header" The provided Content-Type header in the request is invalid. Invalid Content-Type header provided. Most Vonage APIs only accept application/ json. Check the API documentation for the specific API you're working with for a complete list of supported data types. packages/server-client/lib/enums/GenericErrorCodes.ts:121
FORBIDDEN "forbidden" The authenticated user does not have access to the requested resource. Your account does not have permission to perform this action. Check that you're using the correct credentials and that your account has this feature enabled. packages/server-client/lib/enums/GenericErrorCodes.ts:25
INVALID_API_KEY "invalid-api-key" The provided API key is invalid. The API key provided does not exist in our system, or you do not have access. Modify your request to provide a valid API key. packages/server-client/lib/enums/GenericErrorCodes.ts:64
INVALID_ID "invalid-id" The provided ID in the request is invalid. The ID provided does not exist in our system. Modify your request to provide a valid ID. packages/server-client/lib/enums/GenericErrorCodes.ts:91
INVALID_IP "invalid-ip" The request originates from an unauthorized IP address. The source IP address of the request is not in our allow list. Make a request from an allowed IP address, or add your current IP to the list of authorized addresses. packages/server-client/lib/enums/GenericErrorCodes.ts:79
INVALID_JSON "invalid-json" The provided JSON in the request body is invalid. The request body did not contain valid JSON. Send a JSON request body, including a Content-Type header of application/json. packages/server-client/lib/enums/GenericErrorCodes.ts:98
INVALID_SIGNATURE "invalid-signature" The provided signature is invalid. The signature provided did not validate. Check your signature secret and ensure you're following the correct signing process. packages/server-client/lib/enums/GenericErrorCodes.ts:71
JWT_EXPIRED "jwt-expired" The provided JWT has expired. The JWT provided has expired. Generate a new JWT with an expiration date in the future. packages/server-client/lib/enums/GenericErrorCodes.ts:51
JWT_REVOKED "jwt-revoked" The provided JWT has been revoked. The JWT provided has been revoked. Generate a new JWT using your private key. packages/server-client/lib/enums/GenericErrorCodes.ts:57
LOW_BALANCE "low-balance" The account has insufficient funds. This request could not be performed due to your account balance being low. Top up your account in the Vonage Dashboard. packages/server-client/lib/enums/GenericErrorCodes.ts:11
MULTIPLE_AUTH_METHODS "multiple-auth-methods" Multiple authentication methods were provided in the request. Provide exactly one authentication method. packages/server-client/lib/enums/GenericErrorCodes.ts:85
NOT_FOUND "not-found" The requested resource could not be found. The requested resource does not exist, or you do not have access to it. Check both the URI that you're requesting and your authentication credentials. packages/server-client/lib/enums/GenericErrorCodes.ts:32
UNAUTHORIZED "unauthorized" The provided credentials are incorrect or missing. You did not provide correct credentials. Check your authentication credentials; they can be found in the Vonage Dashboard. packages/server-client/lib/enums/GenericErrorCodes.ts:18
UNAVAILABLE_LEGAL "unavailable-legal" The requested service is unavailable due to legal reasons. Vonage APIs are unavailable in the following areas due to international sanctions: Sudan, Syria, Crimea, North Korea, Iran, and Cuba. packages/server-client/lib/enums/GenericErrorCodes.ts:128
UNPROVISIONED "unprovisioned" The account is not provisioned for the requested service. The credentials provided do not have access to the requested product. Check that your API key is correct and has been whitelisted. packages/server-client/lib/enums/GenericErrorCodes.ts:39
WRONG_VERB "wrong-verb" The HTTP verb used in the request is not allowed. This endpoint does not support the HTTP verb that you requested. Read the API documentation to see which verbs your desired endpoint supports. packages/server-client/lib/enums/GenericErrorCodes.ts:105

Classes

Client

Extended by

Constructors

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

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

Client

Defined in

packages/server-client/lib/client.ts:46

Properties

auth
protected auth: AuthInterface;

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

Defined in

packages/server-client/lib/client.ts:33

authType?
protected optional authType: AuthenticationType = AuthenticationType.QUERY_KEY_SECRET;

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

Defined in

packages/server-client/lib/client.ts:28

config
protected config: ConfigParams;

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

Defined in

packages/server-client/lib/client.ts:38

transformers
static transformers: __module = transfomers;

Static property containing utility transformers.

Defined in

packages/server-client/lib/client.ts:23

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.
Defined in

packages/server-client/lib/client.ts:71

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.
Defined in

packages/server-client/lib/client.ts:359

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.
Defined in

packages/server-client/lib/client.ts:329

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.
Defined in

packages/server-client/lib/client.ts:290

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.
Defined in

packages/server-client/lib/client.ts:129

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.
Defined in

packages/server-client/lib/client.ts:145

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.
Defined in

packages/server-client/lib/client.ts:167

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.
Defined in

packages/server-client/lib/client.ts:187

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.
Defined in

packages/server-client/lib/client.ts:201

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.
Defined in

packages/server-client/lib/client.ts:215

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.
Defined in

packages/server-client/lib/client.ts:251

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.
Defined in

packages/server-client/lib/client.ts:230


FileClient

A client for downloading files from Vonage.

Extends

Constructors

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

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

FileClient

Inherited from

Client

Defined in

packages/server-client/lib/client.ts:46

Properties

auth
protected auth: AuthInterface;

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

Inherited from

Client

Defined in

packages/server-client/lib/client.ts:33

authType
protected authType: AuthenticationType = AuthenticationType.JWT;

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

Overrides

Client

Defined in

packages/server-client/lib/fileClient.ts:17

config
protected config: ConfigParams;

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

Inherited from

Client

Defined in

packages/server-client/lib/client.ts:38

saveFilePath
protected saveFilePath: string = '';
Defined in

packages/server-client/lib/fileClient.ts:19

transformers
static transformers: __module = transfomers;

Static property containing utility transformers.

Inherited from

Client

Defined in

packages/server-client/lib/client.ts:23

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

Defined in

packages/server-client/lib/client.ts:71

downloadFile()
downloadFile(file, path): Promise<void>

Downloads a file from Vonage and saves it to a specified path.

Parameters

file: string

The URL or ID of the file to be downloaded.

path: string

The path where the downloaded file should be saved.

Returns

Promise<void>

Resolves when the file is successfully downloaded and saved.

Throws

Throws an error if the file could not be downloaded or saved.

Defined in

packages/server-client/lib/fileClient.ts:31

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

Defined in

packages/server-client/lib/client.ts:359

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

Defined in

packages/server-client/lib/client.ts:329

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

Defined in

packages/server-client/lib/client.ts:290

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

Defined in

packages/server-client/lib/client.ts:129

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

Defined in

packages/server-client/lib/client.ts:145

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

Defined in

packages/server-client/lib/client.ts:167

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

Defined in

packages/server-client/lib/client.ts:187

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

Defined in

packages/server-client/lib/client.ts:201

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

Defined in

packages/server-client/lib/client.ts:215

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

Defined in

packages/server-client/lib/client.ts:251

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

Defined in

packages/server-client/lib/client.ts:230

Type Aliases

APILink

type APILink: object;

Represents a link object in the HAL format.

Type declaration

href
href: string;

The URL of the link.

See

https://tools.ietf.org/html/rfc5988 for more details on Web Linking.

Defined in

packages/server-client/lib/types/APILink.ts:7


APILinks

type APILinks: object;

Represents a set of links in the HAL format.

Type declaration

_links?
optional _links: object;

The set of links.

_links.first?
optional _links.first: APILink;

The link for the first page of resources.

_links.last?
optional _links.last: APILink;

The link for the last page of resources.

_links.next?
optional _links.next: APILink;

The link for the next page of resources.

_links.prev?
optional _links.prev: APILink;

The link for the previous page of resources.

_links.self
_links.self: APILink;

The link for the current resource.

See

https://tools.ietf.org/html/draft-kelly-json-hal-08 for more details on HAL format.

Defined in

packages/server-client/lib/types/APILinks.ts:9


ConfigParams

type ConfigParams: object;

Type defining configuration parameters for API requests.

Type declaration

apiHost?
optional apiHost: string;

The host for general API requests.

appendUserAgent?
optional appendUserAgent: string;

A string to append to the User-Agent header in API requests.

meetingsHost?
optional meetingsHost: string;

The host for meetings-related API requests.

proactiveHost?
optional proactiveHost: string;

The host for proactive API requests.

responseType?
optional responseType: ResponseTypes;

The desired response type for API requests.

Deprecated

The client will now use the content-type header to decode the response properly

restHost?
optional restHost: string;

The host for REST API requests.

timeout?
optional timeout: number;

The maximum time, in milliseconds, to wait for API responses.

videoHost?
optional videoHost: string;

The host for video-related API requests.

See

https://github.com/vonage/vetch for more information on ResponseTypes.

Defined in

packages/server-client/lib/types/ConfigParams.ts:8


TransformFunction()

type TransformFunction: (key) => string;

Parameters

key: string

Returns

string

Defined in

packages/server-client/lib/transformers.ts:7

Functions

camelCaseObjectKeys()

function camelCaseObjectKeys(...ts): Record<string | number, unknown>

Parameters

• ...ts: [Record<string | number, unknown>, boolean, boolean]

Returns

Record<string | number, unknown>

A new object with camelCased keys.

Defined in

packages/server-client/lib/transformers.ts:74


kebabCaseObjectKeys()

function kebabCaseObjectKeys(...ts): Record<string | number, unknown>

Parameters

• ...ts: [Record<string | number, unknown>, boolean, boolean]

Returns

Record<string | number, unknown>

A new object with kebab-cased keys.

Defined in

packages/server-client/lib/transformers.ts:94


omit()

function omit(keys, obj): Record<string | number, unknown>

Parameters

keys: string[]

The keys to omit.

obj: Record<string | number, unknown>

The object from which to omit keys.

Returns

Record<string | number, unknown>

A new object with omitted keys.

Defined in

packages/server-client/lib/transformers.ts:105


snakeCaseObjectKeys()

function snakeCaseObjectKeys(...ts): Record<string | number, unknown>

Parameters

• ...ts: [Record<string | number, unknown>, boolean, boolean]

Returns

Record<string | number, unknown>

A new object with snake_cased keys.

Defined in

packages/server-client/lib/transformers.ts:84


transformObjectKeys()

function transformObjectKeys(
   transformFn, 
   objectToTransform, 
   deep?, 
preserve?): Record<string | number, unknown>

Parameters

transformFn: TransformFunction

The function to transform the object's keys.

objectToTransform: Record<string | number, unknown>

The object whose keys are to be transformed.

deep?: boolean = false

Whether to deeply transform nested object keys.

preserve?: boolean = false

Whether to preserve the original object's keys.

Returns

Record<string | number, unknown>

A new object with transformed keys.

Defined in

packages/server-client/lib/transformers.ts:19

Clone this wiki locally