# Create a facility

> POST /api/public/v1/facilities, scope directory.write. Techvia TMS public API v1 reference.

Source: https://techvia.software/docs/tms/reference/facilities/create-a-facility/

`POST /api/public/v1/facilities`

**Scope:** `directory.write`. **MCP tool:** `create_facility`. Rules and edge cases: [Facilities guide](/docs/tms/guides/directory/).

## Request body

Content type `application/json`. Limits and rules for each field are in the [Facilities guide](/docs/tms/guides/directory/).

| Field | Type | Required | Notes |
|---|---|---|---|
| `name` | string | no |  |
| `street` | string | no |  |
| `city` | string | no |  |
| `state` | string | no |  |
| `zip` | string | no |  |
| `country` | string | no |  |
| `code` | string | no |  |
| `confirmNew` | boolean | no | Default `false` |

## Responses

| Status | Meaning | Body |
|---|---|---|
| `201` | Created | `PublicFacility` |
| `409` | Conflict | `ProblemDetails` |
| `422` | Unprocessable Entity | `ProblemDetails` |

### `201` body

| Field | Type | Notes |
|---|---|---|
| `id` | string (uuid) |  |
| `name` | string |  |
| `code` | string |  |
| `street` | string |  |
| `city` | string |  |
| `state` | string |  |
| `zip` | string |  |
| `timeZoneId` | string |  |
| `status` | enum FacilityStatus | One of `Active`, `Inactive` |
| `rowVersion` | integer |  |

Errors are RFC 7807 problem details; see [Errors](/docs/tms/concepts/errors/).

**Example request**

**curl**

```bash
curl -X POST "https://tms-api.techvia.software/api/public/v1/facilities" \
  -H "Authorization: Bearer $TMS_KEY" \
  -H "Content-Type: application/json" \
  -H "Idempotency-Key: $(uuidgen)" \
  -d '{
    "name": "FreshMart Phoenix",
    "street": "9 Market St",
    "city": "Phoenix",
    "state": "AZ",
    "zip": "85001",
    "code": "FM-PHX"
  }'
```

**JavaScript**

```js
const res = await fetch(`https://tms-api.techvia.software/api/public/v1/facilities`, {
  method: 'POST',
  headers: {
    Authorization: `Bearer ${process.env.TMS_KEY}`,
    'Content-Type': 'application/json',
    'Idempotency-Key': crypto.randomUUID(),
  },
  body: JSON.stringify({
    "name": "FreshMart Phoenix",
    "street": "9 Market St",
    "city": "Phoenix",
    "state": "AZ",
    "zip": "85001",
    "code": "FM-PHX"
  }),
});
if (!res.ok) throw new Error(await res.text());
console.log(await res.json());
```

**Python**

```python

res = requests.request(
    "POST",
    f"https://tms-api.techvia.software/api/public/v1/facilities",
    headers={"Authorization": f"Bearer {os.environ['TMS_KEY']}", "Idempotency-Key": str(uuid.uuid4())},
    json={
      "name": "FreshMart Phoenix",
      "street": "9 Market St",
      "city": "Phoenix",
      "state": "AZ",
      "zip": "85001",
      "code": "FM-PHX"
    },
)
res.raise_for_status()
print(res.json())
```

**Example response** `201`

```json
{
  "id": "01a20943-7a10-7c11-8a2e-000000000050",
  "name": "FreshMart Phoenix",
  "code": "FM-PHX",
  "street": "9 Market St",
  "city": "Phoenix",
  "state": "AZ",
  "zip": "85001",
  "timeZoneId": "America/Phoenix",
  "status": "Active",
  "rowVersion": 208
}
```

<p class="ep-caption">Illustrative values. The time zone comes from the address lookup.</p>
