data-src=../../../includes/saas-only.md
Custom regions
The /V1/directory/countries/:countryId/regions REST endpoints allow you to create and manage custom regions, such as states or provinces, for countries in which this data is not predefined in Adobe Commerce.
Each custom region receives a region_id, so you can use it in customer addresses, checkout, shipping, and tax rules.
These endpoints are designed for:
- Administrators who sell in countries that are missing state or province data
- Third-party integrations that load region lists from external systems, such as ERP and address-validation services
- Automated workflows that create every region for a country in a single request
data-variant=info
data-slots=text
Authentication
All endpoints require an admin or integration bearer token. The token must belong to a role that includes the Manage Country Regions (Magento_DirectoryRegionRestApi::country_region) permission.
System and custom regions
The system field in each response indicates if this is a system region or a custom region.
system valuetruefalseThe following rules apply to all regions:
- Region codes must be unique (case-insensitive) within each country.
- Regions are global. They are not scoped to a website or store view.
- When the store locale matches an entry in
locale_names, Commerce displays that name. Otherwise, it displaysdefault_name.
REST API reference
The API exposes the following operations, which are all secured by the Magento_DirectoryRegionRestApi::country_region permission resource:
/V1/directory/countries/:countryId/regions/V1/directory/countries/:countryId/regions/V1/directory/countries/:countryId/regions/:regionId/V1/directory/countries/:countryId/regions/:regionIdPath parameters
countryIdDO for the Dominican Republic.regionIdcountryId.Field reference
The create and update endpoints accept the following fields for each region.
codedefault_namelocale_nameslocale, such as en_US, and a name.data-variant=info
data-slots=text
region_id, country_id, or system in a request body. The API sets these values and rejects any request that includes them with a 400 error.Each response returns region objects with the following fields.
region_idcountry_idcodedefault_namelocale_namessystemtrue for a system region, false for a custom region.List regions for a country
Returns the system and custom regions for the country in the path. The results are always limited to that country, in addition to any search criteria you pass.
GET/V1/directory/countries/:countryId/regionsThere is no endpoint that retrieves a single region by ID. Filter on region_id instead. The following example returns the region with the code 25 for the Dominican Republic:
GET /V1/directory/countries/DO/regions
?searchCriteria[filter_groups][0][filters][0][field]=code
&searchCriteria[filter_groups][0][filters][0][value]=25
&searchCriteria[filter_groups][0][filters][0][condition_type]=eq
Response (200):
{
"items": [
{
"region_id": 1187,
"country_id": "DO",
"code": "25",
"default_name": "Santiago",
"locale_names": [],
"system": false
}
],
"search_criteria": {
"filter_groups": [
{
"filters": [
{
"field": "code",
"value": "25",
"condition_type": "eq"
}
]
}
]
},
"total_count": 1
}
Create custom regions
Creates one or more custom regions for the country in the path. A request can contain 1 to 500 regions.
POST/V1/directory/countries/:countryId/regionsIf any region fails validation, no regions are created.
Request body:
{
"regions": [
{
"code": "01",
"default_name": "Distrito Nacional",
"locale_names": [
{
"locale": "en_US",
"name": "National District"
}
]
},
{
"code": "25",
"default_name": "Santiago"
},
{
"code": "32",
"default_name": "Santo Domingo"
}
]
}
Response (200):
Returns the created regions in the same order as the request.
[
{
"region_id": 1186,
"country_id": "DO",
"code": "01",
"default_name": "Distrito Nacional",
"locale_names": [
{
"locale": "en_US",
"name": "National District"
}
],
"system": false
},
{
"region_id": 1187,
"country_id": "DO",
"code": "25",
"default_name": "Santiago",
"locale_names": [],
"system": false
},
{
"region_id": 1188,
"country_id": "DO",
"code": "32",
"default_name": "Santo Domingo",
"locale_names": [],
"system": false
}
]
Update a custom region
Updates the code, default name, and locale-specific names of a custom region.
PUT/V1/directory/countries/:countryId/regions/:regionIdThe request requires both code and default_name.
data-variant=warning
data-slots=text
locale_names from an update request, the API removes all existing locale-specific names for the region. To keep them, include them in the request.Request body:
{
"region": {
"code": "25",
"default_name": "Santiago de los Caballeros",
"locale_names": [
{
"locale": "en_US",
"name": "Santiago"
}
]
}
}
Response (200):
{
"region_id": 1187,
"country_id": "DO",
"code": "25",
"default_name": "Santiago de los Caballeros",
"locale_names": [
{
"locale": "en_US",
"name": "Santiago"
}
],
"system": false
}
Delete a custom region
Deletes a custom region and its locale-specific names.
DELETE/V1/directory/countries/:countryId/regions/:regionIdResponse (200):
true
Error handling
The API returns standard HTTP status codes:
400401Magento_DirectoryRegionRestApi::country_region permission.404