Woodpecker.co API Client
The `woodpecker-api` package provides a Promise-based JavaScript client for interacting with the Woodpecker.co email outreach platform's API. It abstracts the underlying HTTP requests, offering a fluent interface for managing prospects, campaigns, and other Woodpecker resources directly from a Node.js application. The current stable version is 1.1.0, and releases appear to be feature-driven rather than on a fixed cadence, with recent updates introducing functionalities such as prospect editing, blacklisting, and webhook subscriptions. A key differentiator of this library is its role as a thin, unopinionated wrapper around the official Woodpecker API, designed to simplify asynchronous operations through the use of Promises. To utilize the library, developers must obtain and provide a valid API key from their Woodpecker.co account dashboard. It primarily targets CommonJS environments, requiring a specific factory function invocation pattern for client instantiation.
Common errors
-
Error: You must provide an API Key.
cause The Woodpecker API client factory function was called without a valid API key string.fixInitialize the client by passing your Woodpecker API key as a string: `const Woodpecker = require('woodpecker-api')('YOUR_API_KEY');` -
TypeError: Woodpecker.prospects is not a function
cause The `prospects` accessor was treated as a property directly exposing methods, instead of a method that returns a query builder object.fixInvoke `prospects()` as a method to get the query builder: `Woodpecker.prospects().find(...)` -
Request failed with status code 400 - limit cannot exceed 500
cause A `find` query was made with the `$limit` parameter set to a value greater than 500.fixReduce the `$limit` parameter to 500 or less. For retrieving larger datasets, implement client-side pagination by making multiple requests and incrementing the `$page` or `$skip` parameter.
Warnings
- gotcha The Woodpecker API documentation might contain discrepancies regarding field names. For example, the official docs might refer to `second_name`, but this client library correctly maps it to `lastName` for prospect searches.
- gotcha An API key is mandatory for all interactions. The client factory function must be invoked with a valid key immediately upon import, or API requests will fail.
- gotcha Pagination limits exist for `find` queries. The `$limit` parameter has a maximum value of `500`. Attempts to request more than 500 records per page will result in an API error.
- gotcha The library exclusively uses JavaScript Promises for all asynchronous operations. Developers must handle results using `.then()`/`.catch()` or `async`/`await` syntax.
Install
-
npm install woodpecker-api -
yarn add woodpecker-api -
pnpm add woodpecker-api
Imports
- WoodpeckerClientFactory
import WoodpeckerClientFactory from 'woodpecker-api';
const WoodpeckerClientFactory = require('woodpecker-api'); - WoodpeckerClientInstance
const Woodpecker = require('woodpecker-api');const Woodpecker = require('woodpecker-api')(process.env.WOODPECKER_API_KEY); - resource methods (e.g., prospects)
Woodpecker.prospects.find(...)
Woodpecker.prospects().find(...)
Quickstart
const Woodpecker = require('woodpecker-api')(process.env.WOODPECKER_API_KEY ?? '');
async function fetchAndManageProspects() {
if (!process.env.WOODPECKER_API_KEY) {
console.error('Error: WOODPECKER_API_KEY environment variable is not set.');
console.error('Please set it before running the script.');
return;
}
try {
// Find prospects named 'd' with a limit of 1
console.log('Searching for prospects with first name "d"...');
const results = await Woodpecker.prospects()
.find({
firstName: 'd',
$limit: 1
});
console.log('Found Prospect(s):', JSON.stringify(results, null, 2));
if (results && results.length > 0) {
const firstProspectId = results[0].id;
console.log(`\nAttempting to retrieve newest prospects...`);
const newest = await Woodpecker.prospects().newest();
console.log(`Retrieved ${newest.length} newest prospects.`);
// Example: Find 100 prospects who replied (if applicable)
// Note: This often requires specific campaign context for real-world use.
console.log('\nAttempting to retrieve replied prospects (if any)...');
const replied = await Woodpecker.prospects().replied();
console.log(`Retrieved ${replied.length} replied prospects.`);
} else {
console.log('No prospects found matching the initial search criteria.');
}
} catch (e) {
console.error('\nAn error occurred during API interaction:');
if (e.response && e.response.data) {
console.error('API Error Details:', JSON.stringify(e.response.data, null, 2));
} else {
console.error(e.message);
}
}
}
fetchAndManageProspects();