# Update segment

> PATCH /segments/:id — edit a segment’s name or filter.

`PATCH /segments/:id`

**Body parameters**

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `name` | string | No | New name. |
| `filter.status` | string | No | New status filter: `all`, `subscribed`, `unsubscribed`, or `members_only` (matches nobody by filter — the segment resolves to its explicitly added contacts only). |
| `filter.email_contains` | string | null | No | New email substring (pass `null` to clear). |
| `filter.property_filters` | array | null | No | Replace the property-filter list (pass `null` or `[]` to clear). Each entry: `{ key, operator, value? }`. Keys must be registered via `POST /contact-properties`. |
| `filter.engagement` | object | null | No | Object or `null`. An engagement predicate: `{ event, campaign_id }`, where `event` is one of `clicked`, `not_clicked`, `opened`, `not_opened` and `campaign_id` is required whenever `engagement` is set. Pass `null` to clear it. |

> **Note:** A segment’s domain cannot be changed — passing `domain` (or `audience_id`) here returns `422 validation_error`.

**Node.js**

```js
import { SendPing } from 'sendping';

const mb = new SendPing('mb_xxxxxxxxx');

const { data, error } = await mb.segments.update('4c1f8b2e-9a2f-4d71-8f0c-2b5d7e6a1c93', { "filter": { "status": "all" } });
console.log({ data, error });
```

**Ruby**

```ruby
require "sendping"

SendPing.api_key = "mb_xxxxxxxxx"

SendPing::Segments.update("4c1f8b2e-9a2f-4d71-8f0c-2b5d7e6a1c93", {
  "filter": {
    "status": "all"
  }
})
```

**PHP**

```php
<?php
require 'vendor/autoload.php';

use SendPing\SendPing;

$sendping = SendPing::client('mb_xxxxxxxxx');

$sendping->segments->update('4c1f8b2e-9a2f-4d71-8f0c-2b5d7e6a1c93', [
  'filter' => [
    'status' => "all"
  ]
]);
```

**Python**

```python
import sendping

sendping.api_key = "mb_xxxxxxxxx"

sendping.Segments.update("4c1f8b2e-9a2f-4d71-8f0c-2b5d7e6a1c93", {
  "filter": {
    "status": "all"
  }
})
```

**Go**

```go
import "github.com/shekhu10/sendping-sdks/sendping-go"

client := sendping.NewClient("mb_xxxxxxxxx")

segment, err := client.Segments.Update("4c1f8b2e-9a2f-4d71-8f0c-2b5d7e6a1c93", &sendping.UpdateSegmentRequest{
    Filter: &sendping.SegmentFilterInput{Status: "all"},
})
```

**Rust**

```rust
use sendping::{SegmentFilterOptions, SegmentStatus, SendPing, UpdateSegmentOptions};

let mb = SendPing::new("mb_xxxxxxxxx");

let params = UpdateSegmentOptions::new()
    .with_filter(SegmentFilterOptions::new().with_status(SegmentStatus::All));
let _segment = mb.segments.update("4c1f8b2e-9a2f-4d71-8f0c-2b5d7e6a1c93", params).await?;
```

**Java**

```java
import co.sendping.SendPing;
import co.sendping.SendPingResponse;
import co.sendping.requests.SegmentFilter;
import co.sendping.requests.UpdateSegmentRequest;

SendPing sendping = new SendPing("mb_xxxxxxxxx");

UpdateSegmentRequest request = UpdateSegmentRequest.builder()
        .filter(SegmentFilter.builder().status("all").build())
        .build();

SendPingResponse response = sendping.segments().update(
        "4c1f8b2e-9a2f-4d71-8f0c-2b5d7e6a1c93",
        request);
```

**.NET**

```csharp
using SendPing;

ISendPing sendping = SendPingClient.Create("mb_xxxxxxxxx");

var resp = await sendping.SegmentUpdateAsync("4c1f8b2e-9a2f-4d71-8f0c-2b5d7e6a1c93", new SegmentUpdateOptions
{
    Filter = new SegmentFilterOptions { Status = "all" },
});
```

**cURL**

```bash
curl -X PATCH 'https://www.sendping.co/api/segments/4c1f8b2e-9a2f-4d71-8f0c-2b5d7e6a1c93' \
  -H 'Authorization: Bearer mb_xxxxxxxxx' \
  -H 'Content-Type: application/json' \
  -d '{ "filter": { "status": "all" } }'
```

**CLI**

```bash
sendping segments update 4c1f8b2e-9a2f-4d71-8f0c-2b5d7e6a1c93 \
  --filter '{"status":"all"}'
```

### Response

Returns the full updated segment object — the same shape as [Create segment](https://www.sendping.co/docs/api/segments-create).

```json
{
  "object": "segment",
  "id": "4c1f8b2e-9a2f-4d71-8f0c-2b5d7e6a1c93",
  "audience_id": "78261eea-8f8b-4381-83c6-79fa7120f1cf",
  "name": "Gmail subscribers",
  "filter": { "status": "all", "email_contains": "@gmail.com", "property_filters": [], "engagement": null },
  "created_at": "2026-06-23T10:00:00.000Z",
  "updated_at": "2026-06-24T08:15:02.000Z"
}
```

An unknown segment id (or one you do not own) returns `404 not_found`. A `filter.status` outside `all`, `subscribed`, `unsubscribed`, `members_only`, an unknown `property_filters` key, or a malformed `filter.engagement` returns `422 validation_error`. See [Errors](https://www.sendping.co/docs/api/errors).
