@versium/reach-api-sdk-node
TypeScript icon, indicating that this package has built-in type declarations

1.0.4 • Public • Published

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

  1. Import the ReachClient class:

    import ReachClient from '@versium/reach-api-sdk-node';
  2. Create a new client instance:

    const client = new ReachClient('your-api-key');
  3. 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;
        }
      })
    }
  4. For retrieving a list of records, use the listgen method. This function returns a promise that resolves to a response object with a getRecords function on it which returns an AsyncGenerator for iterating over records from the response stream. The listgen method will return as soon as data begins streaming in, and getRecords 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

Readme

Keywords

none

Package Sidebar

Install

npm i @versium/reach-api-sdk-node

Weekly Downloads

0

Version

1.0.4

License

BSD-3-Clause

Unpacked Size

37.6 kB

Total Files

18

Last publish

Collaborators

  • zbuttram-versium