The getContentstackEndpoint method returns the correct Contentstack API base URL (host) for a given region (US, EU, AU, etc.) and, optionally, a specific API (such as Delivery, Management, GraphQL, or Auth).
Note: The function can return either a single endpoint URL or the full endpoints object for the region.
Use this helper when:
Skip it when:
This helper is optional, but recommended for multi-region flexibility.
Here’s a minimal example showing how to call the function.
import { getContentstackEndpoint } from '@contentstack/utils';
const contentDeliveryUrl = getContentstackEndpoint('na', 'contentDelivery');
console.log(contentDeliveryUrl);Expected output: https://cdn.contentstack.io
function getContentstackEndpoint(
region?: string,
service?: string,
omitHttps?: boolean
): string | ContentstackEndpointsAll parameters are optional. When a parameter is omitted, the value in the Default column is used.
| Parameter | Type | Default | Description |
| region | string | 'us' | Region ID or alias. 'us' is the default and maps to region ID na (North America). Other examples: 'eu', 'na', 'au', 'azure-na', 'gcp-eu'. |
| service | string | '' | A key from the region's endpoint configuration (e.g., contentDelivery, application, contentManagement, auth). |
| omitHttps | boolean | false | When true, returned URL(s) are without the https:// prefix. |
Returns
The following section lists the supported region IDs and their aliases.
Regions can be passed by ID or alias.
| Region ID | Description |
| na | North America (default; alias: us) |
| eu | Europe |
| au | Australia |
| azure-na | Azure North America |
| azure-eu | Azure Europe |
| gcp-na | GCP North America |
| gcp-eu | GCP Europe |
The function throws a descriptive Error instance on invalid input. It does not return null or undefined. It throws in these cases:
Region could not be empty. Provide a valid region and try again.Provided region <region> is invalid. Provide a valid region and try again.Service "{service}" is not available in region "{regionId}". Provide a valid service name and region ID and try again.The region's configuration file is not valid. Reinstall the SDK and try again.Catching Errors
Use try/catch when you need to handle failures (e.g. user-provided or config-driven region/service):
try {
const url = getContentstackEndpoint('', 'contentDelivery');
} catch (e) {
// Error: Region could not be empty. Provide a valid region and try again.
}
try {
const url = getContentstackEndpoint('invalid-region');
} catch (e) {
// Provided region "na" is invalid. Provide a valid region and try again.
}
try {
const url = getContentstackEndpoint('na', 'invalidService');
} catch (e) {
// Error: Service "{invalidService}" is not available in region "{na}". Provide a valid service name and region ID and try again
}Below are additional usage examples for common scenarios
Note on TypeScript Types: Because the function signature returns a union type (string | ContentstackEndpoints), TypeScript requires you to either narrow the type at runtime or use explicit casting to access specific properties.
import { getContentstackEndpoint, ContentstackEndpoints } from '@contentstack/utils';
const endpoints = getContentstackEndpoint() as ContentstackEndpoints;
// endpoints.application → 'https://app.contentstack.com'
// endpoints.contentDelivery → 'https://cdn.contentstack.io'
// endpoints.contentManagement → 'https://api.contentstack.io'
// endpoints.auth → 'https://auth-api.contentstack.com'
// ... etc.const euEndpoints = getContentstackEndpoint('eu') as ContentstackEndpoints;
// euEndpoints.application → 'https://eu-app.contentstack.com'
// euEndpoints.contentDelivery → 'https://eu-cdn.contentstack.com'const cdnUrl = getContentstackEndpoint('na', 'contentDelivery');
// → 'https://cdn.contentstack.io'
const euCdnUrl = getContentstackEndpoint('eu', 'contentDelivery');
// → 'https://eu-cdn.contentstack.com'
const appUrl = getContentstackEndpoint('au', 'application');
// → 'https://au-app.contentstack.com'Aliases are case-insensitive. Examples using commonly supported aliases:
getContentstackEndpoint('us'); // same as 'na' (North America)
getContentstackEndpoint('na'); // North America
getContentstackEndpoint('eu'); // Europe
getContentstackEndpoint('au'); // AustraliaUse the endpoint as the host when creating a Delivery SDK stack so the stack uses the correct region:
import contentstack from '@contentstack/delivery-sdk';
import { getContentstackEndpoint } from '@contentstack/utils';
const host = getContentstackEndpoint('eu', 'contentDelivery', true);
const stack = contentstack.stack({
apiKey: process.env.CONTENTSTACK_API_KEY!,
deliveryToken: process.env.CONTENTSTACK_DELIVERY_TOKEN!,
environment: process.env.CONTENTSTACK_ENVIRONMENT!,
host,
});const host = getContentstackEndpoint('na', 'application', true);
// → 'app.contentstack.com'
const allHosts = getContentstackEndpoint('na', '', true) as ContentstackEndpoints;
// allHosts.application → 'app.contentstack.com'
// allHosts.contentDelivery → 'cdn.contentstack.io'Since the return type is always a union, you must handle the result based on whether you provided a service argument.
Use typeof to check the result at runtime. This is the most robust method for handling dynamic inputs.
const result = getContentstackEndpoint('na');
if (typeof result === 'string') {
// TypeScript knows this is a URL string
console.log(result.toLowerCase());
} else {
// TypeScript knows this is a ContentstackEndpoints object
console.log(result.contentDelivery);
}If you know exactly which parameters you are passing, you can use the as keyword to tell TypeScript what to expect.
// When service is omitted, cast as the object
const all = getContentstackEndpoint('na') as ContentstackEndpoints;
// When service is provided, cast as a string
const url = getContentstackEndpoint('na', 'contentDelivery') as string;Use this section when you need:
The function returns a union type because it does not currently use function overloads to distinguish between call patterns.
Return Type: string | ContentstackEndpoints
The specific return value depends on the service argument:
| Scenario | Return Type | Logic |
| service is provided | string | Returns the specific base URL for that service. |
| service is omitted or '' | ContentstackEndpoints | Returns an object containing all available services for the region. |
Note: A whitespace-only string (e.g., ' ') for the service parameter is treated as a truthy value and will trigger an error rather than returning the full object.
When the function returns an object, it follows this structure:
interface ContentstackEndpoints {
[key: string]: string | ContentstackEndpoints;
}Exports from @contentstack/utils
The package exports: