@versium/reach-api-sdk-node
v1.0.4
Published
Versium REACH API Client
Downloads
5
Readme
Versium REACH API Software Development Kit (SDK) for Node.js
A simplified TypeScript-based interface for accessing Versium Reach APIs via Node.js
Installation
npm install @versium/reach-api-sdk-node
Supports Node.js v16+.
NOTE: This package is an ESM-only module - you are not able to import it with require()
. See the Node.js documentation for more information on using ES modules.
Usage
Import the ReachClient class:
import ReachClient from '@versium/reach-api-sdk-node';
Create a new client instance:
const client = new ReachClient('your-api-key');
For adding data to a set of inputs, use the
append
method. Check the API documentation for which data tools and output types are available.IMPORTANT NOTE: This method returns an
AsyncGenerator
that yields arrays containing API responses, you must iterate over the generator to get the response arrays, then iterate over the response arrays to get the results.const inputs = [ { first: 'john', last: 'doe', address: '123 Trinity St', city: 'Redmond', state: 'WA', zip: '98052' } ]; // iterate over the AsyncGenerator to get the response arrays, note the 'for await' syntax here for await (const results of client.append('contact', inputs, ['email', 'phone'])) { // filter out failed queries for processing later const failedResults = results.filter(result => !result.success); // iterate over the response array to get the results results.forEach((result, idx) => { if (result.success && result.matchFound) { // merge successful matches with inputs inputs[idx].appendResults = result.body.versium.results; } }) }
For retrieving a list of records, use the
listgen
method. This function returns a promise that resolves to a response object with agetRecords
function on it which returns anAsyncGenerator
for iterating over records from the response stream. Thelistgen
method will return as soon as data begins streaming in, andgetRecords
can be used to drain the stream until you have extracted all records from the response. Check the API documentation for which data tools and output types are available.const response = await client.listgen('abm', {domain: ['versium.com']}, ['abm_email', 'abm_online_audience']); if (response.success) { // getRecords returns an AsyncGenerator, so here we use the 'for await' syntax to iterate over the results for await (const record of response.getRecords()) { console.log({record}); } }
Things to keep in mind
- The default rate limit is 20 queries per second
- You must have a provisioned API key for this function to work. If you are unsure where to find your API key, look at our API key documentation
Contributing
For information on building and testing the library, see CONTRIBUTING.md