# snyk-request-manager

> Rate controlled and retry enabled request manager to interact with Snyk APIs

Latest version **1.9.5** (published 2026-10-21) · Apache-2.0 license · 0 weekly downloads

## Install

```sh
npm install snyk-request-manager
pnpm add snyk-request-manager
yarn add snyk-request-manager
bun add snyk-request-manager
```

## Health

**Score 65/100 (B)** — status: active.

Positive: has types; no vulnerabilities; recently updated; high maintenance score; high quality score.

Warnings: low downloads; no esm support.

## Facts

| | |
|---|---|
| Version | 1.9.5 |
| Published | 2026-10-21 |
| First published | 2020-05-21 |
| Weekly downloads | 0 |
| License | Apache-2.0 |
| TypeScript types | bundled |
| Module format | CommonJS |
| Node | >=12 |
| Dependencies | 13 |
| Unpacked size | 62.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 6 |
| Author | Snyk Tech Services |
| Maintainers | snyk-tech-services |

## Links

- npm: https://www.npmjs.com/package/snyk-request-manager
- Repository: https://github.com/snyk-labs/snyk-request-manager
- Homepage: https://github.com/snyk-labs/snyk-request-manager#readme
- Issues: https://github.com/snyk-labs/snyk-request-manager/issues
- npm.io page: https://npm.io/package/snyk-request-manager

## Dependencies (13)

- [axios](https://npm.io/package/axios.md) 1.20.0
- [chalk](https://npm.io/package/chalk.md) ^4.0.0
- [debug](https://npm.io/package/debug.md) ^4.1.1
- [tslib](https://npm.io/package/tslib.md) ^1.10.0
- [lodash](https://npm.io/package/lodash.md) 4.18.1
- [snyk-config](https://npm.io/package/snyk-config.md) ^5.0.1
- [@types/debug](https://npm.io/package/@types/debug.md) ^4.1.7
- [global-agent](https://npm.io/package/global-agent.md) 3.0.0
- [proxy-from-env](https://npm.io/package/proxy-from-env.md) ^1.1.0
- [@snyk/configstore](https://npm.io/package/@snyk/configstore.md) ^3.2.0-rc1
- [leaky-bucket-queue](https://npm.io/package/leaky-bucket-queue.md) 0.0.2
- [source-map-support](https://npm.io/package/source-map-support.md) ^0.5.16
- [@types/babel__traverse](https://npm.io/package/@types/babel__traverse.md) 7.17.1

## Recent versions

- 1.9.5 (latest) — 2026-10-21
- 1.9.4 — 2026-08-20
- 1.9.3 — 2026-04-30
- 1.9.2 — 2026-04-28
- 1.9.1 — 2026-04-22
- 1.9.0 — 2024-12-20
- 1.8.6 — 2024-08-30
- 1.8.5 — 2024-07-05
- 1.8.4 — 2024-02-15
- 1.8.3 — 2023-10-05
- 1.8.2 — 2023-08-02
- 1.8.1 — 2022-11-02
- 1.8.0 — 2022-08-05
- 1.7.1 — 2022-07-01
- 1.7.0 — 2022-07-01
- … 18 more at https://npm.io/package/snyk-request-manager/versions

## README

![Snyk logo](https://snyk.io/style/asset/logo/snyk-print.svg)

***

[![Known Vulnerabilities](https://snyk.io/test/github/snyk-labs/snyk-request-manager/badge.svg)](https://snyk.io/test/github/snyk-labs/snyk-request-manager)
[![Actively Maintained](https://img.shields.io/badge/Maintenance%20Level-Actively%20Maintained-green.svg)](https://gist.github.com/cheerfulstoic/d107229326a01ff0f333a1d3476e068d)

Snyk helps you find, fix and monitor for known vulnerabilities in your dependencies, both on an ad hoc basis and as part of your CI (Build) system.

## Snyk snyk-request-manager

Rate controlled and retry enabled request manager to interact with Snyk APIs.\
No matter with request mode you decide to use, using the same client will ensure all requests are funneled through a leaky bucket style queue allowing specific burst and interval of requests.

Specific your queue settings in the constructor.

Failed requests will be put back into queue for retry till maximum number of attempts has been reached, in which case error will be thrown.

## Installation

`npm install snyk-request-manager`

## Usage

Check out available endpoints here: [https://snyk.docs.apiary.io/#reference](https://snyk.docs.apiary.io/#reference).\
Any url used below omits the API base ([https://snyk.io/api/v1](https://snyk.io/api/v1)).
Example for base documentation endpoint:
* `GET` request on `https://snyk.io/api/v1/`
* `await requestManager.request({verb: "GET", url: '/'})`

### 0 - Setup your Snyk details if not already done

Following the same setup as snyk CLI, it uses the token stored in your system after a `snyk auth` or defined via env var `SNYK_TOKEN`.
\
Same thing if you need to designate a different API base url to your onprem instance via `snyk config set endpoint` or `SNYK_API` to `https://yourhostname/api`

>Make sure to omit the base endpoint url when you define url to hit.

### 1 - Construct your manager

```js
const requestManager = new requestsManager()
```

Default values if using `new requestsManager()`:

```
snykToken = '', burstSize = 10, period = 500, maxRetryCount = 5
```

### 2 - Single shot request

Fire off your request and await it's result:

```js
import { requestsManager } from 'snyk-request-manager';

const run = async () => {
    const requestManager = new requestsManager();

    // Fire off single shot request
    try {
    let requestSync = await requestManager.request({verb: "GET", url: '/url'})
    console.log(requestSync.data)
    } catch (err) {
        console.log(err)
    }
}

run()
```

`request` and `requestBulk` are generic — if you know the shape of the endpoint you're calling, pass it as a type parameter to get a typed `.data` instead of `any`:

```ts
interface Project {
    id: string;
    name: string;
}

const requestSync = await requestManager.request<Project>({verb: "GET", url: '/org/:orgID/project/:projectId'})
console.log(requestSync.data.name) // typed as string
```

This is entirely optional — omitting the type parameter keeps `.data` as `any`, exactly as before.

### 3 - Bulk requests burst

Fire off you array of requests, await for all of them to complete to receive results in an Array in the same order.
If some requests fails, retrieve the results in the catch, requests completed successfully will have the results.

```js
import { requestsManager } from 'snyk-request-manager';

const run = async () => {
    const requestManager = new requestsManager();

    // Fire off single shot request
    try {
    let requestSync = await requestManager.request({verb: "GET", url: '/url'})
    console.log(requestSync.data)
    } catch (err) {
        console.log(err)
    }

    // Fire off multiple requests async/await
    const filters = `{
        "filters": {
            "severities": [
                "critical",
                "high",
                "medium",
                "low"
            ],
            "exploitMaturity": [
                "mature",
                "proof-of-concept",
                "no-known-exploit",
                "no-data"
            ],
            "types": [
                "vuln",
                "license"
            ],
            "ignored": false
        }
    }
    `
    try {
    const results = await requestManager.requestBulk([
        {verb: "GET", url: '/'},
        {verb: "POST", url: '/org/:orgID/project/:projectId/issues', body: filters },
        {verb: "GET", url: '/user/:id'}])
    console.log(results)
    } catch(resultsWithError) {
        console.log(resultsWithError)
    }
}

run()
```

### 4 - Stream mode requests

Define you listeners `data` and `error` to listen on your channel only.
Define as many listeners as needed to use multiple parallel streams.
If not defining custom channel name, default channel name is used in the backend `stream`

```js
requestManager.on('data', {
    callback:(requestId, data) => {
        console.log("response for request on test-channel ", requestId)
        console.log(data.data)
    },
    channel: 'test-channel'
})

try {
requestManager.requestStream({verb: "GET", url: '/user/:id'}))
requestManager.requestStream({verb: "GET", url: '/'}, 'test-channel')
} catch (err) {
    console.log(err)
}
```

Above will only show result of call to `/` as listener is only for 'test-channel'


### Customize queue/retry values and or snyk token

While instantiating your manager:

#### Customize queue size and intervals

```
const requestManager = new requestsManager({burstSize: 20, period: 100, maxRetryCount: 10})
```

#### Customize snyk token

```
const requestManager = new requestsManager({snykToken:'21346-1234-1234-1234')
```


#### Customize to use REST api endpoint

Each request can be opted in to use the new REST Snyk API, which defaults to 'https://api.snyk.io/rest/' and is automatically calculated from the `SNYK_API` or `endpoint` configuration by reusing the same host.
```
const res = await requestManager.request({verb: "GET", url: '/url', useRESTApi: true})
```


#### Customize snyk token and queue|intervals|retries

```
const requestManager = new requestsManager({snykToken:'21346-1234-1234-1234', burstSize: 20, period: 100, maxRetryCount: 10})
```

## Development

### Running tests

`npm test` runs lint and the full jest suite.

Test runs force `SNYK_API=https://api.snyk.io/v1` via `test/jest.setup.js` so they're isolated from any real local Snyk CLI config. Without this, if you've ever run `snyk auth` or `snyk config set endpoint` on your machine, `getConfig()` picks up the `endpoint` stored in `~/.config/configstore/snyk.json` instead of the library's default — which can differ just enough (e.g. missing the `/v1` suffix) to make requests miss the tests' nock mocks and silently fall through to the wrong interceptor, producing confusing failures that don't reproduce in CI or on a clean machine.

---
_Source: https://npm.io/package/snyk-request-manager · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
