comecerodocs
Concepts

Localized formatting

Add formatted=true to a Comecero API call to get money amounts and dates as display text in the shopper's language, and choose the locale with user_locale.

Add formatted=true to a request and each object also carries a formatted child with its money amounts and dates written for people, in the shopper's language and format. You can show these values as they are, without formatting them yourself.

Ask for formatted values

Request
curl "https://api.comecero.com/api/v1/carts/0091307952465CafhFSTa1?formatted=true" \
  -H "Authorization: Bearer $COMECERO_TEST_TOKEN"
Response
{
  "object": "cart",
  "cart_id": "0091307952465CafhFSTa1",
  "date_created": "2026-11-07T23:16:38Z",
  "currency": "USD",
  "subtotal": 119.9,
  "shipping": 5,
  "tax": 9.38,
  "total": 134.28,
  "formatted": {
    "subtotal": "$119.90",
    "shipping": "$5.00",
    "tax": "$9.38",
    "total": "$134.28",
    "date_created": "11/7/2026 11:16 PM"
  }
}

The raw values stay where they are. Use them for sums and logic, and the formatted ones for display:

const cart = await response.json();
totalElement.textContent = cart.formatted.total; // "$134.28"

The default is false. A value other than true or false is a 400. Each object's page in the API reference lists what its formatted child holds.

What is formatted

  • Money amounts, with the currency's symbol and the locale's way of writing numbers. The same amount can read $134.28 in English and 134,28 $ in French.
  • Dates and times, as a short date and time in the locale, in the request's time zone (see Dates and times).
  • Some other fields with a display form, such as a country name. The object's page says which.

formatted follows show and hide: with show=total&formatted=true it holds only total.

Which locale is used

The API picks the locale in this order and uses the first it finds:

  1. The user_locale query parameter, if you send one.
  2. For limited and trusted tokens, the browser's Accept-Language header.
  3. The default locale of the shopper's country, found from their IP address.
  4. Your account's default locale.

A request from a shopper's browser needs nothing extra: the browser's language is used. Send user_locale to override it.

From your server

A server request with a secret token has no browser, so the Accept-Language header is not read. Pass the shopper's locale yourself as a language code, or a language and country:

user_locale=fr
user_locale=fr-CA
user_locale=de-AT
user_locale=en-US

You can also pass the browser's whole Accept-Language value in user_locale, for example fr-CA,fr;q=0.9,en;q=0.8. The API picks the best language it supports.

const locale = encodeURIComponent(request.headers['accept-language'] ?? 'en-US');
const response = await fetch(
  `https://api.comecero.com/api/v1/orders/6622-NXKHE-858?formatted=true&user_locale=${locale}`,
  { headers: { Authorization: `Bearer ${process.env.COMECERO_TEST_TOKEN}` } },
);

To format for the shopper's country too, a secret token can send the shopper's IP address in user_ip_address.

Next steps

On this page