🔍

Quickstart Guide

Get up and running with Env in under 5 minutes. Learn how to install the SDK, configure your environment, and make your first API request.

💡 Prerequisites

Before you begin, ensure you have a valid Env API key and Node.js 18+ installed. If you don't have an API key, create a free account in the dashboard.

1. Installation

Install the Env SDK using your preferred package manager:

npm install @env/sdk
# or
yarn add @env/sdk
# or
pnpm add @env/sdk

2. Configuration

Initialize the SDK with your credentials. We recommend storing sensitive values in a .env file:

// .env
ENV_API_KEY=env_live_sk_xxxxxxxxxxxxxxxxxxxxxxxx
ENV_ORGANIZATION_ID=org_123456
ENV_ENVIRONMENT=production

Load and configure the client in your application:

import { EnvClient } from '@env/sdk';
import dotenv from 'dotenv';

dotenv.config();

const env = new EnvClient({
  apiKey: process.env.ENV_API_KEY,
  organizationId: process.env.ENV_ORGANIZATION_ID,
  timeout: 30000,
  retries: 3
});

Configuration Options

ParameterTypeRequiredDescription
apiKeystringYesYour secret API key from the dashboard
organizationIdstringYesIdentifies your workspace/scope
timeoutnumberNoRequest timeout in ms (default: 10000)
retriesnumberNoMax retry attempts for failed requests
baseUrlstringNoOverride default API endpoint

3. Making Your First Request

Once configured, you can start fetching environmental data. Here's how to retrieve your organization's current carbon footprint:

async function getFootprint() {
  try {
    const data = await env.emissions.getFootprint({
      scope: 'scope_3',
      period: '2024-Q3',
      units: 'metric_tons'
    });
    
    console.log(`Total Emissions: ${data.value} ${data.units}`);
    return data;
  } catch (error) {
    console.error('Failed to fetch footprint:', error.message);
    throw error;
  }
}
⚠️ Error Handling

The SDK throws typed errors. Always wrap API calls in try/catch blocks. Network errors will include a statusCode and retryAfter hint when applicable.

4. Webhooks & Real-time Updates

Env supports webhooks for real-time sustainability events. Configure your endpoint in the dashboard or via the API:

await env.webhooks.create({
  url: 'https://api.yourapp.com/env-events',
  events: ['emissions.calculated', 'compliance.expiring', 'audit.completed'],
  secret: process.env.WEBHOOK_SECRET
});

All webhook payloads are signed using HMAC-SHA256. Verify signatures before processing:

import { verifyWebhook } from '@env/sdk/security';

const isValid = verifyWebhook(
  request.body,
  request.headers['x-env-signature'],
  process.env.WEBHOOK_SECRET
);
← Installation Guide Environment Variables →