Extracting the DataCenterURI Claim

For reliability and performance purposes, BarTender Cloud tenants are hosted in regional data centers. When you authenticate in BarTender Cloud, the access token that is returned includes a DataCenterURI claim that must be added to your API requests to make sure that the requests that you send on behalf of a particular user are sent to the correct data center.

When an authenticated API call comes in to a BarTender Cloud web service, an HttpContext instance is created. You can extract the DataCenterURI claim from this instance by using the following code.

Copy

IEnumerable<Claim> claims = HttpContext.User.Claims;
string dataCenterURI = claims.FirstOrDefault(c => c.Type == "https://BarTenderCloud.com/DataCenterURI")?.Value;
                

The resulting data center URI will contain the correct protocol (HTTP or HTTPS) and domain to use for the current user and will resemble the following (including the trailing slash):

https://am1.bartendercloud.com/

This is the base address for the URI that you will create when you make the API request. For example, the base URI for a request to the Security API will resemble the following:

https://am1.bartendercloud.com/api/security...