> ## Documentation Index
> Fetch the complete documentation index at: https://laudspeaker.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Upsert

> Adding or updating customers programmatically via the Laudspeaker API

The `upsert` endpoint is designed to allow Luadspeaker users the programmatic ability to add new customers or update existing customers.

The `upsert` endpoint looks up a customer document using the supplied `primary_key`, and then adds or changes customer attribute values specified in the `properties` `json` object in the request body.

> [!WARNING]
>
> In order to use this endpoint, a primary key must have first been selected via the [Laudspeaker UI](https://app.laudspeaker.com/).

### Authentication

**Authorization** `string` *required*

Header for authenticating with Laudspeaker. Starts with `Api-Key` followed by the API key, for example `Api-Key M4jxXt6diYz1Dds1YmhHe93KGPAUi24PlXgaiRXi`.

### Body

**primary\_key** `string` *required*

This field specifies the primary key value used to uniquely identify users.

**properties** `json`

This is where additional properties are added to the customer object. To delete a property, pass the key with value set to `null`.

### Response

```json 200 theme={null}
{
  "id":"65a70f3c373d50b91ea57438"
}
```

```json 400 theme={null}
{
  "error":"Primary Key not selected"
}
```

**id** `string` *required*

The id of the customer object that was created or modified.

### Examples

#### Creating an empty customer document

```cURL cURL theme={null}
curl --request POST \
  --url https://app.laudspeaker.com/api/customers/upsert \
  --header 'Authorization: Api-Key M4jxXt6diYz1Dds1YmhHe93KGPAUi24PlXgaiRXi' \
  --header 'Content-Type: application/json' \
  --data '{
  "primary_key": "johnsmith@example.com"
}'
```

#### Updating an existing customer document

```cURL cURL theme={null}
curl --request POST \
  --url https://app.laudspeaker.com/api/customers/upsert \
  --header 'Authorization: Api-Key M4jxXt6diYz1Dds1YmhHe93KGPAUi24PlXgaiRXi' \
  --header 'Content-Type: application/json' \
  --data '{
  "primary_key": "johnsmith@example.com",
  "properties": {
    "firstName": "John",
    "lastName": "Smith"
  }
}'
```

#### Deleting a field from an existing customer document

```cURL cURL theme={null}
curl --request POST \
  --url https://app.laudspeaker.com/api/customers/upsert \
  --header 'Authorization: Api-Key M4jxXt6diYz1Dds1YmhHe93KGPAUi24PlXgaiRXi' \
  --header 'Content-Type: application/json' \
  --data '{
  "primary_key": "johnsmith@example.com",
  "properties": {
    "firstName": "John",
    "lastName": null
  }
}'
```


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.