Skip to content

Vonage Accounts

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

Vonage AccountsDocs


Documentation / Vonage Accounts

Vonage Accounts

Classes

Accounts

Client class to interact with the Account API which enables users to manage their Vonage API Account programmatically.

See

https://developer.nexmo.com/en/account/overview

Examples

Create a standalone Account client

import { Accounts } from '@vonage/account';

const accountClient = new Accounts({
 apiKey: VONAGE_API_KEY,
 apiSecret: VONAGE_API_SECRET
});

Create an Account client from the Vonage client

import { Vonage } from '@vonage/server-client';

const vonage = new Vonage({
  apiKey: VONAGE_API_KEY,
  apiSecret: VONAGE_API_SECRET
});

const accountClient = vonage.account;

Extends

Constructors

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

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

Accounts

Inherited from

Client.constructor

Defined in

server-client/dist/client.d.ts:30

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/client.d.ts:19

authType
protected authType: AuthenticationType = AuthenticationType.QUERY_KEY_SECRET;
See

Client.authType

Overrides

Client.authType

Defined in

accounts/lib/accounts.ts:44

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/client.d.ts:23

transformers
static transformers: __module;

Static property containing utility transformers.

Inherited from

Client.transformers

Defined in

server-client/dist/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/client.d.ts:37

getBalance()
getBalance(): Promise<GetBalanceResponse>

Retrieves the current balance of the Vonage API account.

Returns

Promise<GetBalanceResponse>

The current balance of the account in EUR.

See

https://rest.nexmo.com/account/get-balance

Example
const balance = await accontClient.getBalance();

console.log(`The current account balance is ${balance.value} ${balance.currency}`);
console.log(`Auto-reload is ${balance.autoReload ? 'enabled' : 'disabled'}`);
Defined in

accounts/lib/accounts.ts:58

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/client.d.ts:134

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/client.d.ts:124

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/client.d.ts:117

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/client.d.ts:44

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/client.d.ts:52

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/client.d.ts:60

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/client.d.ts:70

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/client.d.ts:80

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/client.d.ts:90

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/client.d.ts:110

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/client.d.ts:101

topUpBalance()
topUpBalance(trx): Promise<TopUpBalanceResponse>

Tops up the account balance when auto-reload is enabled. The top-up amount corresponds to the amount added when auto-reload was enabled.

Parameters

trx: string

The transaction reference for the balance addition and auto-reload activation.

Returns

Promise<TopUpBalanceResponse>

Response indicating the success of the operation.

See

https://rest.nexmo.com/account/top-up

Example
const response = await accountClient.topUpBalance('00X123456Y7890123Z');

if (response['error-code'] === '200') {
  console.log(`The account balance has been topped up`);
} else {
  console.log(`The account balance could not be topped up`);
}
Defined in

accounts/lib/accounts.ts:83

updateAccountCallbacks()
updateAccountCallbacks(callbacks): Promise<AccountUpdateResponse>

Updates the default webhook URLs associated with the account for:

  • Inbound SMS messages
  • Delivery receipts
Parameters

callbacks: AccountCallbacks

The new callback URLs for the account.

Returns

Promise<AccountUpdateResponse>

Details of the updated or current settings.

See

https://rest.nexmo.com/account/settings

Example
const callbacks = {
  moCallBackUrl: 'https://example.com/webhooks/inbound-sms',
  drCallBackUrl: 'https://example.com/webhooks/delivery-receipts',
};

const response = await accountClient.updateAccountCallbacks(callbacks);

for (const [key, value] of Object.entries(response)) {
  console.log(`New ${key}: ${value}`);
}
Defined in

accounts/lib/accounts.ts:112


Secrets

Client class to interact with the Account API to create secrets in their Vonage API Account 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 { Secrets } from '@vonage/account';

const secretClient = new Secrets({
 apiKey: VONAGE_API_KEY,
 apiSecret: VONAGE_API_SECRET
});

Extends

Constructors

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

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

Secrets

Inherited from

Client.constructor

Defined in

server-client/dist/client.d.ts:30

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/client.d.ts:19

authType
protected authType: AuthenticationType = AuthenticationType.BASIC;

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

Overrides

Client.authType

Defined in

accounts/lib/secrets.ts:26

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/client.d.ts:23

transformers
static transformers: __module;

Static property containing utility transformers.

Inherited from

Client.transformers

Defined in

server-client/dist/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/client.d.ts:37

createSecret()
createSecret(apiKey, secret): Promise<APISecretResponse>

Create a new API secret for a given API key.

Parameters

apiKey: string

The API key to manage secrets for.

secret: string

The new secret. It must follow the provided rules:

  • Minimum 8 characters.
  • Maximum 25 characters.
  • At least 1 lowercase character.
  • At least 1 uppercase character.
  • At least 1 digit.
Returns

Promise<APISecretResponse>

A promise that resolves to an object representing the created API secret.

Example
const { id } = await secretClient.createSecret(
 'new-api-key',
 'SuperSecret123!'
);

console.log(`Created secret with ID ${id}`);
Defined in

accounts/lib/secrets.ts:49

deleteSecret()
deleteSecret(apiKey, id): Promise<void>

Revoke (delete) an existing API secret for a given API key.

Parameters

apiKey: string

The API key to manage secrets for.

id: string

The ID of the API secret to revoke.

Returns

Promise<void>

A promise that resolves when the secret has been revoked.

Example
await secretClient.deleteSecret('my-api-key', 'my-secret-id');
Defined in

accounts/lib/secrets.ts:70

getSecret()
getSecret(apiKey, id): Promise<APISecretResponse>

Retrieve the details of a specific API secret for a given API key.

Parameters

apiKey: string

The API key to manage secrets for.

id: string

The ID of the API secret to retrieve.

Returns

Promise<APISecretResponse>

A promise that resolves to an object representing the API secret.

Example
const { id } = await secretClient.getSecret('my-api-key', 'my-secret-id');
console.log(`Secret with ID ${id} has been retrieved`);
Defined in

accounts/lib/secrets.ts:88

listSecrets()
listSecrets(apiKey): Promise<ListAPISecretsResponse>

List all the secrets associated with a particular API key.

Parameters

apiKey: string

The API key for which to list secrets.

Returns

Promise<ListAPISecretsResponse>

A promise that resolves to an object containing a list of API secrets.

Example
const response = await secretClient.listSecrets('my-api-key');

for (const secret of response._embedded.secrets) {
  console.log(`Secret with ID ${secret.id} has been retrieved`);
}
Defined in

accounts/lib/secrets.ts:112

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/client.d.ts:134

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/client.d.ts:124

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/client.d.ts:117

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/client.d.ts:44

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/client.d.ts:52

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/client.d.ts:60

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/client.d.ts:70

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/client.d.ts:80

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/client.d.ts:90

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/client.d.ts:110

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/client.d.ts:101

Type Aliases

APISecretResponse

type APISecretResponse: APILinks & object;

Represents the response structure for an individual API secret.

Type declaration

created_at
created_at: string;

The timestamp indicating when the API secret was created.

id
id: string;

The unique identifier for the API secret.

Remarks

Many of the Vonage APIs are accessed using an API key and secret. It is recommended to manage and occasionally rotate these secrets for security purposes. This structure provides details for a single API secret.

See

APILinks

Defined in

accounts/lib/types/Response/APISecretResponse.ts:13


AccountCallbacks

type AccountCallbacks: object;

Represents the callbacks associated with an account.

Type declaration

drCallBackUrl?
optional drCallBackUrl: string;

The webhook URL that Vonage makes a request to when a delivery receipt is available for an SMS sent by one of your Vonage numbers.

Remarks

Send an empty string to unset this value.

moCallBackUrl?
optional moCallBackUrl: string;

The default webhook URL for inbound SMS. If an SMS is received at a Vonage number that does not have its own inboud SMS webhook configured, Vonage makes a request here.

Remarks

Send an empty string to unset this value.

Defined in

accounts/lib/types/AccountCallbacks.ts:4


AccountUpdateResponse

type AccountUpdateResponse: object;

Represents the response structure when updating account settings.

Type declaration

dr-callback-url
dr-callback-url: string;

The current or updated delivery receipt webhook URI.

max-calls-per-second
max-calls-per-second: number;

The maximum number of API calls per second.

max-inbound-request
max-inbound-request: number;

The maximum number of inbound messages per second.

max-outbound-request
max-outbound-request: number;

The maximum number of outbound messages per second.

mo-callback-url
mo-callback-url: string;

The current or updated inbound message webhook URI.

Remarks

Settings were updated if supplied; the details of the current settings are included in the response.

Defined in

accounts/lib/types/Response/AccountUpdateResponse.ts:7


GetBalanceResponse

type GetBalanceResponse: object;

Represents the response structure when querying for account balance.

Type declaration

autoReload
autoReload: boolean;

Indicates if the auto-reload feature is enabled.

value
value: number;

The current balance value.

Defined in

accounts/lib/types/Response/GetBalanceResponse.ts:4


ListAPISecretsResponse

type ListAPISecretsResponse: APILinks & object;

Represents the response structure when listing API secrets.

Type declaration

_embedded
_embedded: object;

Contains the embedded secrets information.

_embedded.secrets
_embedded.secrets: APISecretResponse[];

An array of API secrets.

See

APISecretResponse

Remarks

Many of the Vonage APIs are accessed using an API key and secret. It is recommended that you change or "rotate" your secrets from time to time for security purposes. This section provides the API interface for achieving this. Note: to work on secrets for your secondary accounts, you may authenticate with your primary credentials and supply the secondary API keys as URL parameters to these API endpoints.

Defined in

accounts/lib/types/Response/ListAPISecretsResponse.ts:16


TopUpBalanceResponse

type TopUpBalanceResponse: object;

Represents the response structure when performing a top-up operation for account balance.

Type declaration

error-code
error-code: string;

The code associated with any potential errors during the top-up process.

error-code-label
error-code-label: string;

A descriptive label for the error code.

Remarks

You can top up your account using this API when you have enabled auto-reload in the dashboard. The amount added by the top-up operation will be the same amount as was added in the payment when auto-reload was enabled. Your account balance is checked every 5-10 minutes and if it falls below the threshold and auto-reload is enabled, then it will be topped up automatically. Use this endpoint if you need to top up at times when your credit may be exhausted more quickly than the auto-reload may occur.

Defined in

accounts/lib/types/Response/TopUpBalanceResponse.ts:12

Clone this wiki locally