@isnap/sdk is the TypeScript client of the iSnap API, published on npm under the MIT license. It runs in a server process, on Node.js or Bun. Read this page to install it, to check what it requires and to make a first call. These pages describe version 2.2.1.
Install
examples directory. The examples of these pages are other scripts: copy them from here.
The SDK follows Semantic Versioning. Its version is independent of the API version: see Versions.
Requirements
ESM and CommonJS
Import the SDK from an ECMAScript module:require('@isnap/sdk') fails with ERR_PACKAGE_PATH_NOT_EXPORTED. CommonJS code loads the SDK with a dynamic import():
Server side only
The SDK is a server-side library. Its entry point importsnode:crypto, so a browser bundle fails to build even when your code imports only the client. An API key is a secret: keep it on a server, and call the API from there.
TypeScript settings
The type declarations use the web platform typesHeadersInit, Headers, RequestInit, Response, Blob and AbortSignal. A project therefore needs "lib": ["DOM"], or "skipLibCheck": true.
Import the SDK from an ECMAScript module, with moduleResolution set to bundler, node16 or nodenext. A static import from a CommonJS file does not work:
- Under
node16, and undernodenextbefore TypeScript 5.8, it is a compile error (TS1479). - Under
nodenextwith TypeScript 5.8 or later, and undernode10with TypeScript 5, it compiles and then fails at run time withERR_PACKAGE_PATH_NOT_EXPORTED. TypeScript 6 reportsnode10as an error unlessignoreDeprecationsis set, and TypeScript 7 refuses it.
import(), as in ESM and CommonJS. In TypeScript, this needs module set to node16 or nodenext: under commonjs, TypeScript compiles import() to a require(), which fails the same way.
This tsconfig.json meets both requirements: it includes DOM, and it resolves modules with nodenext. It also loads the Node.js types, which TypeScript 6 and later do not load by default: install typescript and @types/node as development dependencies. With nodenext, a .ts file is an ECMAScript module when the nearest package.json has "type": "module":
Make a first call
Create an API key in the iSnap dashboard and put it in theISNAP_API_KEY environment variable. The SDK reads no environment variable: your code passes the key to the client.
client.version() calls GET /v1/version, which needs no credential. client.lines.listMine() calls GET /v1/lines/my: when the API refuses the key, the call throws AuthenticationError. Authentication describes the keys and the refusals.
Creating a client makes no network call. Every method returns a promise that resolves with the data of the response or throws: see Errors and retries. The four list iterators are the exception: they return an AsyncIterable, see Pagination.
What the SDK adds to plain HTTP
Help
Write to support@isnap.ai with thetrace_id and request_id of the response. The SDK exposes them as traceId and requestId on the error it throws.