Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
muslnode 18–226 runs
build_error
glibcnode 18–226 runs
build_error
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
Client
✓ const { Client } = require('sentry-api');
✗ import { Client } from 'sentry-api';
This library is exclusively CommonJS and does not provide ESM exports. The `Client` class is a named export from the main module. Attempting to use ESM `import` will result in module loading errors.
SentryAPI module object
✓ const SentryAPI = require('sentry-api');
const client = new SentryAPI.Client(...);
✗ const client = new require('sentry-api').Client(...);
You can import the entire module object and then access the `Client` property. Avoid nesting `require` directly within the `new` call for readability and common practice.
Default Export (None)
✓ /* No default export exists for this package. */
✗ const Sentry = require('sentry-api').default;
The `sentry-api` package does not expose a default export. The primary class `Client` must be accessed as a named property from the CommonJS module object.
Demonstrates how to initialize the Sentry API client, create a new release (or use an existing one), and upload source map files for a specific project and version using DSN and authentication tokens. Includes error handling and cleanup of temporary files.
const fs = require('fs');
const Promise = require('promise'); // npm i promise, if not on a Node.js version with global Promise
const { Client: SentryClient } = require('sentry-api');
// Your Sentry DSN or authentication token
// Use process.env for sensitive credentials in a real application
const SENTRY_DSN = process.env.SENTRY_DSN ?? 'https://dummy@sentry.io/12345'; // Replace with a valid Sentry DSN
const SENTRY_TOKEN = process.env.SENTRY_TOKEN ?? 'your-sentry-auth-token'; // Replace with a valid Sentry API token
// Initialize the Sentry API client
// You can omit DSN if using token authentication with hosted Sentry
const sentry = new SentryClient(SENTRY_DSN, {
token: SENTRY_TOKEN
});
const organization = 'my-organization-slug'; // Replace with your Sentry organization slug
const project = 'my-project-slug'; // Replace with your Sentry project slug
const version = `my-app-v1.0.0-${Date.now()}`; // Generate a unique version for demonstration
// Create dummy files for upload demonstration
const dummyFilePath = 'app.min.js';
fs.writeFileSync(dummyFilePath, 'console.log("hello world");');
const dummyMapPath = 'app.min.js.map';
fs.writeFileSync(dummyMapPath, '{}'); // Empty map file
console.log(`Attempting to manage Sentry release for org: ${organization}, project: ${project}, version: ${version}`);
// Check if a release already exists, otherwise create a new one, then upload files.
sentry.releases.get(organization, project, version)
.then(function(release) {
console.log(`Release ${version} already exists!`);
return release; // Proceed with existing release
})
.catch(function(err) {
// If the release doesn't exist (e.g., 404 error), create it
if (err.statusCode === 404) {
console.log(`Release ${version} not found. Creating a new one...`);
return sentry.releases.create(organization, project, {
version: version,
ref: version,
dateStarted: new Date().toISOString(),
})
.then(function(release) {
console.log('Created release:', release.version);
return release;
});
}
throw err; // Re-throw other errors
})
.then(function(release) {
const filesToUpload = [dummyFilePath, dummyMapPath];
// Add files (e.g., source maps) to the release
const uploads = filesToUpload.map(function(file) {
return sentry.releases.createFile(organization, project, release.version, {
name: file,
file: fs.createReadStream(file)
}).then(function(newFile) {
console.log('Uploaded file:', newFile.name);
});
});
return Promise.all(uploads);
})
.then(function() {
console.log('Uploaded all files for the release.');
console.log('Cleaning up dummy files...');
fs.unlinkSync(dummyFilePath);
fs.unlinkSync(dummyMapPath);
console.log('Dummy files cleaned up.');
console.log('Quickstart example completed successfully.');
})
.catch(function(error) {
console.error('Error in Sentry release management:', error.message || error);
if (error.statusCode) {
console.error('Status Code:', error.statusCode);
console.error('Response Body:', error.responseBody);
}
// Ensure cleanup even on error
if (fs.existsSync(dummyFilePath)) fs.unlinkSync(dummyFilePath);
if (fs.existsSync(dummyMapPath)) fs.unlinkSync(dummyMapPath);
});
Errors
Common errors & fixes
TypeError: Sentry.releases is undefined
The `Client` instance was not correctly initialized, or the DSN/token provided was invalid, preventing the API endpoint objects (like `releases`, `projects`) from being attached.
fixEnsure `new Client(...)` is called with a valid DSN or authentication token, and that the returned Sentry client instance is used correctly. Check console for any initialization errors.
(node:xyz) UnhandledPromiseRejectionWarning: StatusCodeError: 401 Unauthorized
The Sentry API token provided is missing or invalid, or does not have the necessary permissions for the requested operation.
fixVerify your Sentry API token's validity and ensure it has the required scopes (e.g., `project:releases`, `org:read`, `org:write`) for the operations you are performing. Pass the token via the `token` option in the client constructor.
(node:xyz) UnhandledPromiseRejectionWarning: StatusCodeError: 404 Not Found (when accessing Sentry resources)
The specified organization slug, project slug, or release version does not exist, or the authenticated API token lacks permissions to access it.
fixDouble-check the accuracy of the organization slug, project slug, and release version. Confirm that the API token has the necessary permissions to `read` or `write` to the specified Sentry resources.
Audit
Dependencies
promiserequiredUsed for promise-based API calls, explicitly required in the examples for older Node.js environments. While modern Node.js has a global Promise, the library's examples demonstrate a reliance on this module.