SDK Setup
Official TypeScript SDK for interacting with the Captain Data API.
This SDK provides a unified interface to interact with Captain Data’s API using a single entry point: the CaptainData
class. It simplifies authentication and gives access to the core API and multiple integrations such as LinkedIn and Sales Navigator.
Features
- Unified
CaptainData
interface - Individual API clients:
core
,linkedin
,salesnavigator
, etc. - Auto-generated TypeScript types for safety and autocompletion
- Built using OpenAPI Generator with the typescript-fetch generator and custom templates
- Supports modern async/await and Fetch API
- Supports ES6 Language level (es2019 and newer)
- Supports CommonJS and ES6 module systems
- Can be used in both TypeScript and JavaScript. In TypeScript, the definition will be automatically resolved via package.json.
Installation
Authentication
Each user has their own unique API Key tied to their account. API Keys are not shared across the workspace. To get your API Key:
- Log into the Captain Data Platform
- Go to Developer Settings
- Copy your API Key
Usage
Responses
All SDK operations return an enhanced Response wrapper that provides access to the full HTTP response as well as convenience methods to work with its content and metadata.
This design allows you to:
- Inspect HTTP status, headers, and success flags
- Parse and access the response body easily
- Handle paginated endpoints with built-in pagination helpers
The returned object includes:
Property | Description |
---|---|
raw | The native fetch Response object, with full access if needed |
status | HTTP status code (e.g., 200, 404) |
statusText | HTTP status text (e.g., “OK”, “Not Found”) |
ok | Boolean indicating if status is in the range 200–299 |
headers | The native Response.headers object – use .get() to retrieve |
previousPage | The value of the X-Pagination-Previous header, or null if absent |
nextPage | The value of the X-Pagination-Next header, or null if absent |
data | The parsed body of the response (lazily evaluated on first access) |
Tip: Use the
ok
flag to easily gate logic on successful requests:This gives you fine-grained control over both successful and unsuccessful responses, while keeping your codebase clean and predictable.
Error Handling
API calls can fail, and production-ready code should always handle errors properly. When an error occurs, the SDK throws a ResponseError
, which extends the native Error object and adds:
response
: the raw Fetch Response objectbody
: the decoded API error body (already parsed from JSON)
The API uses a consistent error response format across all endpoints. When an error occurs, you’ll receive a response with the following structure:
Each error response includes:
error_label
: A machine-readable identifier for the error typeerror_scope
: Indicates which part of the request caused the error (e.g., “input”, “auth”, “server”)error_ref
: A unique reference code for tracking and debuggingmessage
: A human-readable description of the errorstatus_code
: The HTTP status codeparams
: Additional error parameters (if any)
Common HTTP status codes:
200
: The request was successful (some API calls may return 201 instead)400
: Bad Request - Invalid input or parameters401
: Unauthorized - Invalid or missing API key403
: Forbidden - Insufficient permissions404
: Not Found - Resource doesn’t exist500
: Internal Server Error - Server-side issue
Always check the error_label
and error_scope
fields to programmatically
handle different types of errors in your application.
If you encounter an unusual error, such as a 500 or 503, feel free to reach out! These are internal errors on our end, and we’re happy to help resolve them.
SDK Structure
Captain Data API allows you to interact with several 3rd party services called integrations (linkedin, salesnavigator, …). The actions allowed for each integration are exposed under a scoped client for each integration.
Scopes are always lower case alpha identifiers.
The actions correspond to the action names you will find in the API Reference or in the Captain Data SaaS, stripped from the integration identifier prefixes.
FAQ
Q: Can I use this SDK in Node.js and browser environments?
A: Yes! It supports both environments as it is based on fetch. For Node.js, make sure to install a polyfill like node-fetch
.