C# SDK

Install and start using the C# SDK.

Intro

The env zero API SDK provides access to the env zero API REST APIs.

This document describes the resources that make up the official env zero REST API.

Base URL

https://api.env0.com

Content types

All requests should be in JSON format and include the accept: application/json header.

Authentication

HTTP Basic authentication. Send the API Key ID as the username and the API Key Secret as the password. Keys are created under Organization Settings -> API Keys (Admin or User scope) or Personal Settings -> API Keys (Personal scope).

Scope of this document

This specification covers the environment drift-governance surface of the env zero API and the environment, deployment, template, configuration and project endpoints that support it. It was reconstructed from the OpenAPI fragments published on https://docs.envzero.com and is a subset of the full API.

Error responses

401 and 403 responses return { "message": string } and are documented on every operation. The upstream documentation does not define response bodies for other non-2xx status codes, so none are asserted here.

Installation

Add the SDK as a project reference into your solution:

Terminal
dotnet add reference <path-to-sdk>/src/EnvZeroApi/EnvZeroApi.csproj

The project takes its build settings from the files around it, so reference it in place.

Quick Start

Dependency Injection

Register the client with IServiceCollection and resolve it from the container. The HttpClient is managed by IHttpClientFactory. Configure the client's behavior through EnvZeroApiClientOptions.

C#
services.AddEnvZeroApiClient(options =>
{
    options.Env0ApiKey = new BasicAuthCredentials { Username = "YOUR_USERNAME", Password = "YOUR_PASSWORD" };
    options.Environment = ServerEnvironment.Production;
    // TODO: configure more client options here
});

Direct Instantiation

Create the client by passing an HttpClient you manage yourself. Configure the client's behavior through EnvZeroApiClientOptions.

C#
var httpClient = new HttpClient();
// TODO: configure more client options here
var options = new EnvZeroApiClientOptions
{
    Env0ApiKey = new BasicAuthCredentials { Username = "YOUR_USERNAME", Password = "YOUR_PASSWORD" },
    Environment = ServerEnvironment.Production,
};
var client = new EnvZeroApiClient(httpClient, options);

On this page