---
type: api
title: Create a private location
description: **Spaces method and path for this operation:**
url: https://www.elastic.co/elastic/docs-builder/docs/4493/api/doc/kibana/operation/operation-post-private-location
resource: https://www.elastic.co/elastic/docs-builder/docs/4493/api/doc/kibana/operation/operation-post-private-location
products:
  - Kibana
---

# Create a private location

- Server: `https://{kibana_url}`

## Paths

- `POST` `/api/synthetics/private_locations`
- `POST` `/s/{space_id}/api/synthetics/private_locations`

## Description

Refer to [Spaces](https://www.elastic.co/docs/deploy-manage/manage-spaces) for more information.

Create a private location backed by a Fleet agent policy.

You must have `all` privileges for the Synthetics and Uptime feature in the Observability section of the Kibana feature privileges.

## Required authorization

- Privileges: `uptime-read` and `private-location-write` and `uptime-write`

## Authentication

- Api key: `Authorization: <value>`
  These APIs use key-based authentication. You must create an API key and use the encoded value in the request header. For example: `Authorization: ApiKey base64AccessApiKey`
- Basic: `Authorization: Basic <credentials>`

## Header parameters

- `kbn-xsrf` (string) — required
  A required header to protect against CSRF attacks

## Request body

`application/json`

- `agentPolicyId` (string · min length: 1 · max length: 1024) — required
  The ID of the agent policy associated with the private location. Each agent policy can back only one private location.
- `geo` (object) — optional
  Geographic coordinates (WGS84) for the location.
  - `lat` (number) — required
    The latitude of the location.
  - `lon` (number) — required
    The longitude of the location.
- `label` (string · min length: 1 · max length: 1024) — required
  A label for the private location. Must be unique.
- `spaces` (string[] · max items: 100) — optional
  An array of space IDs where the private location is available. If it is not provided, the private location is available in all spaces.
- `tags` (string[] · max items: 100) — optional
  An array of tags to categorize the private location.

## Responses

#### `200`

A successful response.

`application/json`

- `agentPolicyId` (string)
  The ID of the agent policy associated with the private location.
- `geo` (object)
  Geographic coordinates (WGS84) for the location.
  - `lat` (number)
    The latitude of the location.
  - `lon` (number)
    The longitude of the location.
- `id` (string)
  The unique identifier of the private location.
- `isInvalid` (boolean)
  Indicates whether the location is invalid. If `true`, the location is invalid, which means the agent policy associated with the location is deleted.
- `label` (string)
  A label for the private location.
- `namespace` (string)
  The namespace of the location, which is the same as the namespace of the agent policy associated with the location.
- `spaces` (string[])
  The space IDs where the private location is available.
- `tags` (string[])
  An array of tags to categorize the private location.
#### `400`

If the `agentPolicyId` is already used by an existing private location or if the `label` already exists, the API returns a 400 Bad Request response with a corresponding error message.

## Code examples

#### Console

```console
POST kbn://api/synthetics/private_locations
{"label":"Private Location 1","agentPolicyId":"abcd1234","tags":["private","testing"],"geo":{"lat":40.7128,"lon":-74.006},"spaces":["default"]}
```

#### curl

```curl
curl \
  -X POST "${KIBANA_URL}/api/synthetics/private_locations" \
  -H "Authorization: ApiKey ${API_KEY}" \
  -H "kbn-xsrf: true" \
  -H "Content-Type: application/json" \
  -d '{"label":"Private Location 1","agentPolicyId":"abcd1234","tags":["private","testing"],"geo":{"lat":40.7128,"lon":-74.006},"spaces":["default"]}'
```

## Response examples

#### Post private location response example1

```json
{
  "agentPolicyId": "abcd1234",
  "geo": {
    "lat": 40.7128,
    "lon": -74.006
  },
  "id": "abcd1234",
  "label": "Private Location 1",
  "spaces": [
    "default"
  ],
  "tags": [
    "private",
    "testing"
  ]
}
```

