Skip to content
API Now! is currently in closed beta. We are constantly updating these guides as we release updates!

Country (Semantic Module)

← Back to Modules Reference

The Country semantic module validates, standardizes, and restricts country values using official ISO 3166-1 international standards.

Country data is essential for international shipping, tax calculation, and compliance. Tagging a property with Country ensures users enter recognized country identifiers, standardizes codes into consistent uppercase formatting, and allows you to configure allowed or disallowed country lists.


AttributeSpecification
ScopeProperty (Applied to a text property)
Data TypeString
Validation StandardISO 3166-1 (iso-3166-1 standard library)
Default FormatISO_3166_Alpha_2 (Two-letter codes, e.g., US, CA, DE)
Casing StandardizationAutomatically converted to uppercase for Alpha codes
Sibling CoordinationProvides country context for the PostalCode semantic

You can choose how country values are validated and stored in your data model:

  • ISO_3166_Alpha_2 (Default): Requires standard two-letter ISO country codes (e.g., US, GB, FR, DE, JP).
  • ISO_3166_Alpha_3: Requires three-letter ISO country codes (e.g., USA, GBR, FRA, DEU, JPN).
  • Name: Requires official English country names (e.g., United States, United Kingdom, Germany).

Restrict shipping or signups to a specific list of served countries (e.g., ['US', 'CA', 'MX']). Any transaction or profile submitted with an unlisted country is rejected with a clear validation error.

3. Country Deny Lists (disallowedCountries)

Section titled “3. Country Deny Lists (disallowedCountries)”

Block specific countries due to trade sanctions, export regulations, or regional service limitations.

Valid input values are automatically trimmed and saved in the canonical format (e.g. lowercase "us" is saved as standardized "US").


When configuring the Country semantic in the Domain Modeler, you can customize the following parameters:

OptionTypeDefaultDescription
format'ISO_3166_Alpha_2' | 'ISO_3166_Alpha_3' | 'Name''ISO_3166_Alpha_2'Required country format standard.
allowedCountriesstring[][] (all allowed)Allow list of permitted country codes or names.
disallowedCountriesstring[][] (none disallowed)Deny list of prohibited country codes or names.

1. Creating a Record with Standard Country Code

Section titled “1. Creating a Record with Standard Country Code”

With the default ISO_3166_Alpha_2 format:

POST /addresses
Content-Type: application/json
{
"street": "10 Downing Street",
"city": "London",
"country": "gb"
}

Server Response (201 Created): The country code is standardized to uppercase:

{
"data": {
"id": "addr_401",
"street": "10 Downing Street",
"city": "London",
"country": "GB"
}
}

A client submits an unrecognized country code:

{
"country": "XX"
}

Server Response (400 Bad Request):

{
"type": "https://docs.apinow.app/errors/validation",
"title": "Validation Error",
"status": 400,
"code": "E_VALIDATION_ERROR",
"detail": "Property 'country' must be a valid ISO 3166-1 Alpha-2 country code (e.g. 'US')."
}

3. Validation Failure (Disallowed Country)

Section titled “3. Validation Failure (Disallowed Country)”

If a country is present in disallowedCountries (e.g. disallowedCountries: ['CU', 'IR', 'KP', 'SY']):

{
"country": "KP"
}

Server Response (400 Bad Request):

{
"type": "https://docs.apinow.app/errors/validation",
"title": "Validation Error",
"status": 400,
"code": "E_VALIDATION_ERROR",
"detail": "Country 'KP' is disallowed for 'country'."
}

  • Applicable Property Types: Apply to a String property in the Domain Modeler.
  • Coordination with Postal Codes: When paired with a sibling PostalCode property within the same entity, the engine dynamically checks that the postal code matches the format required by this country.