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

# Upload customer tags

> Manage customer tags programmatically instead of uploading CSVs.

See [Customer tags](/configure/customer-tags) for what they do in the dashboard.

<CodeGroup>
  ```python Python theme={null}
  import weflayr

  client = weflayr.client(api_key="wf-...")
  ```

  ```js Node.js theme={null}
  const weflayr = require('weflayr');

  const client = weflayr.client({ apiKey: 'wf-...' });
  ```

  ```bash cURL theme={null}
  # Passed as a Bearer token on every request
  export WEFLAYR_API_KEY="wf-..."
  ```
</CodeGroup>

## Set customer tags

<CodeGroup>
  ```python Python theme={null}
  from weflayr.openapi.models import SetCustomerTagsInput

  client.set_customers_tags(body=SetCustomerTagsInput.from_dict({
      "upsert": True,
      "customers": [
          {"customer_name": "c_123", "tags": {"plan": "enterprise", "region": "EU"}},
          {"customer_name": "c_456", "tags": {"plan": "free", "trial": None}},
      ]
  }))
  ```

  ```js Node.js theme={null}
  await weflayr.api.setCustomersTags({
    client,
    throwOnError: true,
    body: {
      upsert: true,
      customers: [
        { customerName: 'c_123', tags: { plan: 'enterprise', region: 'EU' } },
        { customerName: 'c_456', tags: { plan: 'free', trial: null } },
      ],
    },
  });
  ```

  ```bash cURL theme={null}
  curl -X POST https://app.weflayr.com/api/customer-tags/ \
    -H "Authorization: Bearer $WEFLAYR_API_KEY" \
    -H "Content-Type: application/json" \
    -d '{
      "upsert": true,
      "customers": [
        {"customer_name": "c_123", "tags": {"plan": "enterprise", "region": "EU"}},
        {"customer_name": "c_456", "tags": {"plan": "free", "trial": null}}
      ]
    }'
  ```
</CodeGroup>

**Output:**

```json theme={null}
{"ok": true, "customers_updated": 2}
```

**Input params:**

<ParamField body="customers" type="array of customer objects" required>
  The per-customer tag updates, described below. Up to 1,000 per call.
</ParamField>

<ParamField body="upsert" type="boolean" default="false">
  If a (customer, key) pair already exists, overwrite it instead of throwing an error.
</ParamField>

Each object inside `customers` accepts:

<ParamField body="customer_name" type="string" required>
  The same identifier you stamp on your LLM calls when [propagating metadata](/quickstart#add-metadata-to-your-llm-calls-for-finer-analysis), so tags land on the same customer.
</ParamField>

<ParamField body="tags" type="object (string values, or null)" required>
  A string value sets the tag; `null` deletes it. Only the keys you post change, existing tags not included are left untouched.
</ParamField>

## Get customer tags

<CodeGroup>
  ```python Python theme={null}
  client.get_customers_tags(customer_names=["c_123", "c_456"])
  ```

  ```js Node.js theme={null}
  await weflayr.api.getCustomersTags({
    client,
    throwOnError: true,
    query: { customerNames: ['c_123', 'c_456'] },
  });
  ```

  ```bash cURL theme={null}
  curl "https://app.weflayr.com/api/customer-tags/?customer_names=c_123&customer_names=c_456" \
    -H "Authorization: Bearer $WEFLAYR_API_KEY"
  ```
</CodeGroup>

**Output:**

```json theme={null}
{
  "customers": [
    {"customer_name": "c_123", "tags": {"plan": "enterprise", "region": "EU"}},
    {"customer_name": "c_456", "tags": {"plan": "free"}}
  ],
  "next_cursor": null,
  "has_more": false
}
```

**Input params:**

<ParamField query="customer_names" type="list[string]">
  Specify the names of the customers whose tags should be fetched. Not setting it means "all customers".
</ParamField>

<ParamField query="limit" type="integer" default="100">
  Numbers of customers to fetch. Max `1000`.
</ParamField>

<ParamField query="cursor" type="string">
  The route is paginated: pass the previous page's `next_cursor` to fetch the next page. PS: `has_more` from the output says whether another page exists.
</ParamField>

## Delete customer tags

<CodeGroup>
  ```python Python theme={null}
  client.delete_customers_tags(customer_names=["c_123", "c_456"])
  ```

  ```js Node.js theme={null}
  await weflayr.api.deleteCustomersTags({
    client,
    throwOnError: true,
    query: { customerNames: ['c_123', 'c_456'] },
  });
  ```

  ```bash cURL theme={null}
  curl -X DELETE "https://app.weflayr.com/api/customer-tags/?customer_names=c_123&customer_names=c_456" \
    -H "Authorization: Bearer $WEFLAYR_API_KEY"
  ```
</CodeGroup>

**Output:**

```json theme={null}
{"ok": true, "tags_deleted": 2}
```

**Input params:** passed in the query string.

<ParamField query="customer_names" type="list[string]" required>
  Delete every tag of these customers. The customer records themselves are kept.
</ParamField>
