> For the complete documentation index, see [llms.txt](https://api.senderwiz.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://api.senderwiz.com/customer/segments/update-a-list-segment.md).

# Update a List Segment

Update an existing list segment using new field or campaign conditions. Only the submitted conditions will be retained; any existing ones not included will be removed.

### ✏️ Update a List Segment

Modify an existing segment of a subscriber list by replacing its conditions, campaign filters, and other attributes.

#### 🔹 HTTP Request

```http
PUT API-URL/lists/LIST-UNIQUE-ID/segments/SEGMENT-UNIQUE-ID
```

#### 🔸 URL Segments

| Segment             | Type   | Required | Description                       |
| ------------------- | ------ | -------- | --------------------------------- |
| `LIST-UNIQUE-ID`    | string | Yes      | Unique identifier of the list.    |
| `SEGMENT-UNIQUE-ID` | string | Yes      | Unique identifier of the segment. |

#### 🔐 Authorization Header

```
X-API-KEY: your-api-key-here
```

#### 🕝 PUT Parameters

| Parameter | Type  | Required | Description                                                                                       |
| --------- | ----- | -------- | ------------------------------------------------------------------------------------------------- |
| `data`    | array | Yes      | List segment details including `name`, `operator_match`, `conditions`, and `campaign_conditions`. |

#### 📦 General Block *(Required)*

| Parameter        | Type   | Required | Description                     |
| ---------------- | ------ | -------- | ------------------------------- |
| `name`           | string | Yes      | Name of the list segment.       |
| `operator_match` | string | Yes      | Match operator: `any` or `all`. |

#### 📦 Conditions Block *(Optional)*

| Parameter     | Type   | Required | Description                                          |
| ------------- | ------ | -------- | ---------------------------------------------------- |
| `field_id`    | string | Yes      | ID of the custom field (use Get List Fields API).    |
| `operator_id` | string | Yes      | Condition operator ID (use condition operators API). |
| `value`       | string | Yes      | Value to compare against.                            |

#### 📦 Campaign Conditions Block *(Optional)*

| Parameter                  | Type    | Required | Description                                    |
| -------------------------- | ------- | -------- | ---------------------------------------------- |
| `action`                   | string  | Yes      | Action to filter by: `click` or `open`.        |
| `campaign_id`              | integer | Yes      | Campaign ID to check behavior against.         |
| `time_comparison_operator` | string  | Yes      | Time operator: `lte`, `lt`, `gte`, `gt`, `eq`. |
| `time_value`               | integer | Yes      | Time value for comparison.                     |
| `time_unit`                | string  | Yes      | Time unit: `day`, `month`, or `year`.          |

#### 💻 PHP Example

```php
// update list segment
// Only the conditions present here will be kept. All other existing conditions will be removed
$response = $endpoint->update('LIST-UNIQUE-ID', 'SEGMENT-UNIQUE-ID', [
    // required
    'name'           => 'My list segment created from the API updated', // required
    'operator_match' => 'any', // required (any/all)

    // optional
    'conditions' => [
        [
            'field_id'    => '96', // required
            'operator_id' => '3',  // required (see condition operators endpoint)
            'value'       => 'domain.com', // required
        ],
        [
            'field_id'    => '95',
            'operator_id' => '4',
            'value'       => 'keyword',
        ]
    ],

    'campaign_conditions' => [
        [
            'action'                   => 'click',
            'campaign_id'              => '100',
            'time_comparison_operator' => 'lte',
            'time_value'               => '3',
            'time_unit'                => 'day'
        ],
        [
            'action'                   => 'open',
            'campaign_id'              => '99',
            'time_comparison_operator' => 'gte',
            'time_value'               => '3',
            'time_unit'                => 'month'
        ]
    ],
]);

// and get the response
echo '<pre>';
print_r($response->body);
echo '</pre>';
```

#### 📦 Sample JSON Response

```json
{
  "status": "success",
  "data": {
    "record": {
      "segment_uid": "sx795qzttl9bb",
      "segment_id": "11",
      "name": "my segment with cond updated",
      "operator_match": "any",
      "date_added": "10/23/23, 2:36 PM",
      "subscribers_count": 0,
      "conditions": [
        {
          "field_id": "96",
          "operator_id": "3",
          "value": "keyword"
        }
      ],
      "campaign_conditions": []
    }
  }
}
```
