OCAPI localization 21.10

The Open Commerce API supports localized content.

Shop API

The Shop API supports a single locale at a time. You can specify the locale by setting the locale parameter, which takes values in the format <language code>-<country code>. Otherwise, the Shop API uses the default locale of the site. Please Note: In Shop API the following locale fallback is performed: Locale (en-US) > Language Locale (en) > Default locale (default). The following example shows how you can explicitly specify a locale:

REQUEST:
GET /dw/shop/v21_10/content/about_us?locale=en-US HTTP/1.1
Host: example.com
Accept: application/json

RESPONSE:
HTTP/1.1 200 OK
Content-Length: 351
Content-Type: application/json; charset=UTF-8

{
  "_v" : "21.10",
  "_resource_state" : "ba4e84383e1790597e49eeee34b201633d80ed3f499992f5af11d639dd903a36"
  "description" : "It all started with a series of observations...",
  "id" : "about-us",
  "name" : "About Us",
  "c_body" : "<h1 class=\"content-header\">About Us</h1><h2>It all started with a series of observations:</h2> ...",
  "c_greeting" : "How are you?"
}

Data API

The Data API supports multiple locales at the same time. By default, localizable properties are returned as a map of all available localized values keyed by the locale identifier. However, you can explicitly specify a single locale by setting the locale parameter, which takes values in the format <language code>-<country code>. If you explicitly specify a locale, localizable properties are returned as a single map entry. Please Note: In Data API no locale fallback is performed.

The first example shows the default behavior, which returns a map of multiple localized values:

REQUEST:
GET /dw/data/v21_10/library/SiteGenesis/content/about-us HTTP/1.1
Host: example.com
Accept: application/json

RESPONSE:
HTTP/1.1 200 OK
Content-Length: 569
Cache-Control: max-age=0,no-cache,no-store,must-revalidate
Content-Type: application/json;charset=UTF-8

{
  "_v" : "21.10",
  "_resource_state" : "ba4e84383e1790597e49eeee34b201633d80ed3f499992f5af11d639dd903a36"
  "description" : {
    "default" : "It all started with a series of observations..."
  },
  "id" : "about-us",
  "link" : "https://example.com/s/-/dw/data/v21_10/libraries/SiteGenesis/content/about-us",
  "name" : {
    "default" : "About Us"
  },
  "c_body" : {
    "default" : "<h1 class=\"content-header\">About Us</h1><h2>It all started with a series of observations:</h2> ...",
    "de-DE" : "<h1 class=\"content-header\">Über uns</h1><h2>Alles begann mit einer Reihe von Untersuchungen:</h2> ..."
  },
  "c_greeting" :
  {
    "default" : "hello",
    "en" : "Good day",
    "en-US" : "How are you?",
    "en-GB" : "How do you do?",
    "de" : "Hallo",
    "de-DE" : "Guten Tag",
    "fr" : "Bonjour"
  }
}

The second example shows a response for an explicitly specified locale:

REQUEST:
GET /dw/data/v21_10/library/SiteGenesis/content/about-us?locale=en-US HTTP/1.1
Host: example.com
Accept: application/json

RESPONSE:
HTTP/1.1 200 OK
Content-Length: 569
Cache-Control: max-age=0,no-cache,no-store,must-revalidate
Content-Type: application/json;charset=UTF-8

{
  "_v" : "21.10",
  "_resource_state" : "ba4e84383e1790597e49eeee34b201633d80ed3f499992f5af11d639dd903a36"
  "id" : "about-us",
  "link" : "https://example.com/s/-/dw/data/v21_10/libraries/SiteGenesis/content/about-us",
  "c_greeting" :
  {
    "en-US" : "How are you?"
  }
}
X OCAPI versions 15.x and 16.x will be retired on March 31, 2021. For dates and more information, see the OCAPI versioning and deprecation policy and this Knowledge Article.
X Privacy Update: We use cookies to make interactions with our websites and services easy and meaningful, to better understand how they are used. By continuing to use this site you are giving us your consent to do this. Privacy Policy.