LocalesUrl

View as Markdown

LocalesUrl

LocalesUrl pairs a language code with the URL that a publishing environment serves that language from.

When to Use This Class: Use this class to give an environment one URL per language in EnvironmentModel.Urls.

Conceptual Role: Acts as the item type of EnvironmentModel.Urls. No method takes it directly.

Returns: LocalesUrl. One language code and its URL.

Class-Level Notes

Where it goes.

  • Add LocalesUrl objects to the Urls list of an EnvironmentModel, then pass the model to the Create or Update method of Environment.
  • The SDK does not check the language code or the URL.
  • A property you leave null stays out of the request body.

Properties

NameTypeRequiredDefaultDescription
Urlstring?NonullURL of the environment for this language. Serialized as url.
Localestring?NonullLanguage code, such as en-us. Serialized as locale.

Method Index

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

Class-Level Snippet

The snippet below sets an English and a French URL on an existing environment.

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 = "<ENVIRONMENT_NAME>",
    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" }
    }
};

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