> This page is for Developer.

> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://docs.makeswift.com/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.makeswift.com/_mcp/server.

# Create Locale

POST https://api.makeswift.com/v2/locales
Content-Type: application/json

Creates a new locale for a site.

Reference: https://docs.makeswift.com/developer/api-reference/rest/locales/create-locale

## Authentication

- `x-api-key` header (required) — API key authentication. Accepts either: - App API key (e.g. sk_eczMHVBY9fV6GYFhvs53qcnxq7yptlXL3ABKOZtn6dQ) - Site API key (UUID format, e.g. 550e8400-e29b-41d4-a716-446655440000)

## Request

### Body (application/json)

This endpoint expects a CreateSiteLocaleV2RequestBodyDto.

- `siteId` (string, required) — The site ID to create the locale for.
- `locale` (string, required) — Locale of the site locale.
- `domain` (string, optional) — The domain URL for domain-based localization. This URL must include the protocol.

## Response

### 201

- `object` (enum, required)
  - Allowed values: `locale`
- `id` (string, required) — The ID of the created locale.
- `locale` (string, required) — We support the subset of locales specified with ISO 3166 that are composed of language and optionally a region.
- `domain` (string, required, nullable) — The domain URL for domain-based localization.
- `pathPrefix` (string, required, nullable) — Custom URL path prefix. Null means the locale code is used as the default prefix.
- `isDefault` (boolean, required) — The flag that indicates whether this locale is the default locale for the site.

## Errors

### 400 Bad Request Error

- `object` (enum, required)
  - Allowed values: `error`
- `code` (enum, required)
  - Allowed values: `bad_request`
- `message` (string, required)

### 403 Forbidden Error

- `object` (enum, required)
  - Allowed values: `error`
- `code` (enum, required)
  - Allowed values: `forbidden`
- `message` (string, required)

### 404 Not Found Error

- `object` (enum, required)
  - Allowed values: `error`
- `code` (enum, required)
  - Allowed values: `not_found`
- `message` (string, required)

### 409 Conflict Error

- `object` (enum, required)
  - Allowed values: `error`
- `code` (enum, required)
  - Allowed values: `conflict`
- `message` (string, required)

## Examples

**Request**

```json
{
  "siteId": "string",
  "locale": "es-ES"
}
```

**Response**

```json
{
  "object": "locale",
  "id": "string",
  "locale": "en",
  "domain": "https://hearthfurniture.com.mx",
  "pathPrefix": "french",
  "isDefault": true
}
```

**SDK Code**

```python
import requests

url = "https://api.makeswift.com/v2/locales"

payload = {
    "siteId": "string",
    "locale": "es-ES"
}
headers = {
    "x-api-key": "<apiKey>",
    "Content-Type": "application/json"
}

response = requests.post(url, json=payload, headers=headers)

print(response.json())
```

```javascript
const url = 'https://api.makeswift.com/v2/locales';
const options = {
  method: 'POST',
  headers: {'x-api-key': '<apiKey>', 'Content-Type': 'application/json'},
  body: '{"siteId":"string","locale":"es-ES"}'
};

try {
  const response = await fetch(url, options);
  const data = await response.json();
  console.log(data);
} catch (error) {
  console.error(error);
}
```

```go
package main

import (
	"fmt"
	"strings"
	"net/http"
	"io"
)

func main() {

	url := "https://api.makeswift.com/v2/locales"

	payload := strings.NewReader("{\n  \"siteId\": \"string\",\n  \"locale\": \"es-ES\"\n}")

	req, _ := http.NewRequest("POST", url, payload)

	req.Header.Add("x-api-key", "<apiKey>")
	req.Header.Add("Content-Type", "application/json")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(res)
	fmt.Println(string(body))

}
```

```ruby
require 'uri'
require 'net/http'

url = URI("https://api.makeswift.com/v2/locales")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Post.new(url)
request["x-api-key"] = '<apiKey>'
request["Content-Type"] = 'application/json'
request.body = "{\n  \"siteId\": \"string\",\n  \"locale\": \"es-ES\"\n}"

response = http.request(request)
puts response.read_body
```

```java
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.post("https://api.makeswift.com/v2/locales")
  .header("x-api-key", "<apiKey>")
  .header("Content-Type", "application/json")
  .body("{\n  \"siteId\": \"string\",\n  \"locale\": \"es-ES\"\n}")
  .asString();
```

```php
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://api.makeswift.com/v2/locales', [
  'body' => '{
  "siteId": "string",
  "locale": "es-ES"
}',
  'headers' => [
    'Content-Type' => 'application/json',
    'x-api-key' => '<apiKey>',
  ],
]);

echo $response->getBody();
```

```csharp
using RestSharp;

var client = new RestClient("https://api.makeswift.com/v2/locales");
var request = new RestRequest(Method.POST);
request.AddHeader("x-api-key", "<apiKey>");
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\n  \"siteId\": \"string\",\n  \"locale\": \"es-ES\"\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift
import Foundation

let headers = [
  "x-api-key": "<apiKey>",
  "Content-Type": "application/json"
]
let parameters = [
  "siteId": "string",
  "locale": "es-ES"
] as [String : Any]

let postData = JSONSerialization.data(withJSONObject: parameters, options: [])

let request = NSMutableURLRequest(url: NSURL(string: "https://api.makeswift.com/v2/locales")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "POST"
request.allHTTPHeaderFields = headers
request.httpBody = postData as Data

let session = URLSession.shared
let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in
  if (error != nil) {
    print(error as Any)
  } else {
    let httpResponse = response as? HTTPURLResponse
    print(httpResponse)
  }
})

dataTask.resume()
```