EnvironmentModel

View as Markdown

EnvironmentModel

EnvironmentModel holds the details of a publishing environment that the Create and Update methods of Environment send.

When to Use This Class: Use this class to describe a new publishing environment, or the new details of an existing one.

Conceptual Role: Acts as the request body of Environment.Create and Environment.Update and their async forms. The SDK sends it inside an environment key.

Returns: EnvironmentModel. The details of one publishing environment.

Class-Level Notes

What the API needs.

  • The Content Management API reference asks for the environment name and its URLs when you add an environment. See Add an environment.
  • Each URL is a LocalesUrl that pairs a language code with the URL of the server for that language.
  • Each server is a Server with a name.

Serialization.

  • A property you leave null stays out of the request body.
  • DeployContent is a bool with the default true, so the SDK always sends deploy_content. Set it to false on every create or update that needs false.

Properties

NameTypeRequiredDefaultDescription
Namestring?NonullName of the environment. Serialized as name.
ServersList<Server>?NonullDeployment servers. Serialized as servers.
UrlsList<LocalesUrl>?NonullLanguage codes and their URLs. Serialized as urls.
DeployContentboolNotrueThe SDK sends it as deploy_content on every request.

Method Index

EnvironmentModel has no methods. Set its properties and pass it to the methods named above.

Class-Level Snippet

The snippet below adds a production environment with one server and a URL for each of two languages.

using System;
using System.Collections.Generic;
using Contentstack.Management.Core;
using Contentstack.Management.Core.Exceptions;
using Contentstack.Management.Core.Models;

ContentstackClient client = new ContentstackClient("<AUTHTOKEN>");

EnvironmentModel model = new EnvironmentModel()
{
    Name = "production",
    Servers = new List<Server>() { new Server() { Name = "web-server" } },
    Urls = new List<LocalesUrl>()
    {
        new LocalesUrl() { Locale = "en-us", Url = "https://www.example.com" },
        new LocalesUrl() { Locale = "fr-fr", Url = "https://www.example.com/fr" }
    },
    DeployContent = true
};

try
{
    ContentstackResponse response = client.Stack("<API_KEY>").Environment().Create(model);
    Console.WriteLine(response.OpenJsonObjectResponse().ToJsonString());
}
catch (ContentstackErrorException e)
{
    Console.WriteLine($"Request failed: {(int)e.StatusCode} {e.ErrorCode} {e.ErrorMessage}");
}