Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

@vonage/server-client

Vonage260kApache-2.01.17.0TypeScript support: included

The Vonage Server Client provides core functionalities for interacting with Vonage APIs, ensuring a standardized response regardless of the underlying HTTP adapter.

readme

Vonage Server Client SDK for Node.js

GitHub Workflow Status Codecov Latest Release Contributor Covenant License

Vonage

This is the Vonage Server Client SDK for Node.js used to wrap the authentication headers/signatures for use with Vonage APIs. To use it you will need a Vonage account. Sign up for free at vonage.com.

For full API documentation refer to developer.vonage.com.

Installation

With NPM

npm install @vonage/server-client

With Yarn

yarn add @vonage/server-client

Usage

To create a client, you will need to pass in a @vonage/auth object.

const { Auth } = require('@vonage/auth');
const { Client } = require('@vonage/server-client');

const vonageClient = new Client (new Auth({
        apiKey: API_KEY,
        apiSecret: API_SECRET,
        applicationId: APP_ID,
        privateKey: PRIVATE_KEY_PATH,
    }),
    options,
);

You will now be able to send requests using the client:

const response = await vonageClient.sendGetRequest('https://rest.nexmo.com/account/numbers')

Options

The constructor for the client takes in two parameters credentials and options. credentials is either an Auth or an object containing the settings from AuthInterface.

options allows adjusting api endpoints and the request timeout.

  • restHost: string (optional) - Allows overwriting the default https://rest.nexmo.com.
  • apiHost: string (optional) - Allows overwriting the default https://api.nexmo.com.
  • videoHost: string (optional) - Allows overwriting the default https://video.api.vonage.com.
  • timeout: int (optional) - Set a custom timeout for requests to Vonage in milliseconds. Defaults to the standard for Node http requests, which is 120,000 ms.
  • appendUserAgent: string (optional) - Set a custom string to be added to the user-agent header for the request

File Downloads

When downloading files, the request needs to be built with proper security headers set. Inside this package is the FileClient which will handle the request. You can download a file using the File Id or the FQURL.

const { Auth } = require('@vonage/auth');
const { FileClient } = require('@vonage/server-client');

const fileClient = new FileClient(new Auth({
    apiKey: API_KEY,
    apiSecret: API_SECRET,
    applicationId: APP_ID,
    privateKey: PRIVATE_KEY_PATH,
  }),
  options,
);

await fileClient.downloadFile('the-file-id-or-url', '/paht/to/save');

Testing

Run:

npm run test

changelog

(2025-01-10)

Bug Fixes

  • Add missing advanced machine detection mode (#947) (f2cc9c1)
  • create conversation was sending the request incorrectly (#967) (4b81d74)
  • incorrect http method for updating users (#953) (9f52bc5)
  • incorrect http method for updating users (#954) (bacbe72)
  • messages now using basic auth when requested (ac1f603)
  • send form request sending undefined form body (#966) (78b6199)
  • server-client no longer sends undefined query parameters (7d7fc08)
  • subaccounts: correct incorrect type on BalanceTransferParameters (#937) (70f9c25)
  • subaccounts: correct type on SubAccountCreateParameters (#940) (f7e7531)
  • user-to-user header was not being transformed to lisp case (#976) (f83aaf0)
  • video: Corrected video transition guide install instructions (68d3c3b)
  • video: Updated list of supported video APIs in transition guide (f98252f)

Features

4.0.0 (2024-05-24)

Bug Fixes

  • added missing type declration for node fetch (f927b8e)
  • adding rs256 as allowed algrothim (#914) (4e3bd8a)
  • auth: fixed passing in private key path (#920) (0dbb5d2)
  • decoding when charset is in the content type response header (#904) (aec47d6)
  • number-insights-v2: incorrect auth method (#909) (8fd3dcc)
  • outdated/wrong algorithm argument passed to jsonwebtoken (#907) (d5adb68)
  • sms: correct wrong status code for "partner account barred" (#895) (20ed3f2)
  • verify2: sms and silent auth updates (#908) (935a20c)
  • video: Make sure create session returned JSON, and fixed return type (#913) (28ac0df)
  • video: updated endpoints for adding/removing streams from Archive (#922) (9652cac)
  • voice: ncco encoding (#906) (9f2cfc8)

Features

  • add tss languages generate file from voice.json (#926) (a34e4dc)
  • conversations: added conversations package (#905) (e28f6b6)
  • messages: added new webhook, viber, and sms parameters (#921) (691a796)

3.10.1 (2023-11-12)

Bug Fixes

  • explicit_approval typeo in join type (#870) (66ea103)
  • Added dist folder to depcheck ignores (0b3e533)
  • Allow features to be searched in available numbers (#731) (5b4b201)
  • allow no filter when getting owned numbers, require filter when searching available numbers (#747) (ac80247)
  • applications: updating types for application package (#827) (2ff4e5a)
  • build: GHA install typescript and update NPM before running build commands (#737) (504be6a)
  • Correct our return types when sending SMS (#743) (7d9fc80)
  • Exported additional NCCO classes and interfaces that weren't before (#732) (a36ef9c)
  • Fixed issue with WA Template interface from older, incorrect spec (#730) (52de295)
  • jwt: Fix ttl in claims (#846) (54fccdc)
  • kebabecase api parameters (#802) (c71d424)
  • messages: Fixed README example (82570dd)
  • missing depedency for proactive connect (2ac48d3)
  • number paramters casing (#848) (73b4a68)
  • Numbers API was making JSON requests instead of form encoded requests (#734) (9c8e13d)
  • removed importHelpers compiler options (#786) (f07eff9)
  • restored append to user agent (#852) (dcab7ab)
  • Reverts back to ES6 and CommonJS for better Node compatibility (#777) (15503f9)
  • server-client not setting timeout parameter (b9efd8f)
  • server-client: Removing module declaration (d3930fc)
  • server-sdk: Fix links and SMS example (2dec8f9)
  • Set the proper content type when we send put/patch/post (#738) (02c303f)
  • timeout parameter being respected (#850) (52fae4a)
  • type for websocket header (#851) (8dd49dd)
  • types using node:http for import (#741) (e8e5dd6)
  • types: verify response types (#794) (888111d)
  • update packages after audit (#844) (8760b0f)
  • Verify - Added brand to seperate out from Sender ID (#744) (01bfdec)
  • verify2: check code not returning status (#823) (3e04e19)
  • verify2: missing "t" in the silent auth channel enum (#834) (565bcdd)
  • verify2: package json had incorrect main entry (#830) (9b48fb7)
  • verify: Added missing remapping for params (#782) (7fb20f2)
  • verify: import using lib folder (#803) (5530793)
  • video: Added SIP and DTMF playing (#776) (727027e)
  • video: Fix blank values on Dial API (#828) (14ec31f)
  • voice: Fixed response types on file downloads (#864) (0446638)
  • voice: Force NCCO actions to set value for NCCO type to avoid JS problems (#853) (6bce17b)

Features

3.0.0-beta.4 (2022-03-10)

Bug Fixes

  • add top level package-lock (a845782)
  • auth: add signed requests and req updates (887a776)

Features

  • numbers: Add Numbers module code (a78e9f0)
  • numbers: add numbers module) (82805e4)
  • sms: add sms module (4479d03)

3.0.0-beta.3 (2021-08-13)

3.0.0-beta.2 (2021-08-13)

3.0.0-beta.1 (2021-08-11)

3.0.0-beta.0 (2021-08-10)

3.0.1-beta.0 (2021-08-10)

2.10.2 (2020-10-05)

2.10.1 (2020-09-10)

2.9.1 (2020-08-17)

2.8.0 (2020-06-26)

2.4.2 (2019-09-07)

2.4.0 (2018-09-27)

2.2.1 (2018-04-29)

2.2.0 (2018-01-24)

2.1.2 (2018-01-11)

2.1.1 (2017-12-14)

2.0.2 (2017-03-22)

2.0.1 (2017-03-21)

2.0.0 (2017-03-20)