{"library":"sentry-api","title":"Sentry API Client","description":"The `sentry-api` package provides a Node.js client for interacting with the Sentry API specifically for administrative tasks, such as managing projects, creating releases, and uploading source maps. This library is distinct from Sentry's official event reporting SDKs which focus on error ingestion. The current stable version is 0.2.0. It is explicitly in \"maintenance mode,\" meaning it will receive bug fixes and version updates but no new feature development. This makes it suitable for existing integrations but potentially not ideal for leveraging the latest Sentry API features. Its primary differentiation is enabling programmatic control over Sentry platform data rather than just error reporting.","language":"javascript","status":"maintenance","last_verified":"Sun Apr 19","install":{"commands":["npm install sentry-api"],"cli":null},"imports":["const { Client } = require('sentry-api');","const SentryAPI = require('sentry-api');\nconst client = new SentryAPI.Client(...);","/* No default export exists for this package. */"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"const fs = require('fs');\nconst Promise = require('promise'); // npm i promise, if not on a Node.js version with global Promise\nconst { Client: SentryClient } = require('sentry-api');\n\n// Your Sentry DSN or authentication token\n// Use process.env for sensitive credentials in a real application\nconst SENTRY_DSN = process.env.SENTRY_DSN ?? 'https://dummy@sentry.io/12345'; // Replace with a valid Sentry DSN\nconst SENTRY_TOKEN = process.env.SENTRY_TOKEN ?? 'your-sentry-auth-token'; // Replace with a valid Sentry API token\n\n// Initialize the Sentry API client\n// You can omit DSN if using token authentication with hosted Sentry\nconst sentry = new SentryClient(SENTRY_DSN, {\n  token: SENTRY_TOKEN\n});\n\nconst organization = 'my-organization-slug'; // Replace with your Sentry organization slug\nconst project = 'my-project-slug';          // Replace with your Sentry project slug\nconst version = `my-app-v1.0.0-${Date.now()}`; // Generate a unique version for demonstration\n\n// Create dummy files for upload demonstration\nconst dummyFilePath = 'app.min.js';\nfs.writeFileSync(dummyFilePath, 'console.log(\"hello world\");');\nconst dummyMapPath = 'app.min.js.map';\nfs.writeFileSync(dummyMapPath, '{}'); // Empty map file\n\nconsole.log(`Attempting to manage Sentry release for org: ${organization}, project: ${project}, version: ${version}`);\n\n// Check if a release already exists, otherwise create a new one, then upload files.\nsentry.releases.get(organization, project, version)\n  .then(function(release) {\n    console.log(`Release ${version} already exists!`);\n    return release; // Proceed with existing release\n  })\n  .catch(function(err) {\n    // If the release doesn't exist (e.g., 404 error), create it\n    if (err.statusCode === 404) {\n      console.log(`Release ${version} not found. Creating a new one...`);\n      return sentry.releases.create(organization, project, {\n        version: version,\n        ref: version,\n        dateStarted: new Date().toISOString(),\n      })\n      .then(function(release) {\n        console.log('Created release:', release.version);\n        return release;\n      });\n    }\n    throw err; // Re-throw other errors\n  })\n  .then(function(release) {\n    const filesToUpload = [dummyFilePath, dummyMapPath];\n\n    // Add files (e.g., source maps) to the release\n    const uploads = filesToUpload.map(function(file) {\n      return sentry.releases.createFile(organization, project, release.version, {\n        name: file,\n        file: fs.createReadStream(file)\n      }).then(function(newFile) {\n        console.log('Uploaded file:', newFile.name);\n      });\n    });\n\n    return Promise.all(uploads);\n  })\n  .then(function() {\n    console.log('Uploaded all files for the release.');\n    console.log('Cleaning up dummy files...');\n    fs.unlinkSync(dummyFilePath);\n    fs.unlinkSync(dummyMapPath);\n    console.log('Dummy files cleaned up.');\n    console.log('Quickstart example completed successfully.');\n  })\n  .catch(function(error) {\n    console.error('Error in Sentry release management:', error.message || error);\n    if (error.statusCode) {\n      console.error('Status Code:', error.statusCode);\n      console.error('Response Body:', error.responseBody);\n    }\n    // Ensure cleanup even on error\n    if (fs.existsSync(dummyFilePath)) fs.unlinkSync(dummyFilePath);\n    if (fs.existsSync(dummyMapPath)) fs.unlinkSync(dummyMapPath);\n  });","lang":"javascript","description":"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.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}