# Add Contact to Segment

> POST /contacts/:id/segments/:segment_id — add an existing contact to a segment.

`POST /contacts/:id/segments/:segment_id`

Add an existing contact to a segment. The contact is identified in the path by either its ID or its email address.

Either `id` or `email` must be provided.

**Path parameters**

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `id` | string | No | The Contact ID. |
| `email` | string | No | The Contact Email. |
| `segment_id` | string | Yes | The Segment ID. |

**Node.js**

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

const mb = new SendPing('mb_xxxxxxxxx');

const { data, error } = await mb.contacts.addToSegment('e169aa45-1ecf-4183-9955-b1499d5701d3', '78261eea-8f8b-4381-83c6-79fa7120f1cf');
console.log({ data, error });
```

**Ruby**

```ruby
require "sendping"

SendPing.api_key = "mb_xxxxxxxxx"

SendPing::Contacts.add_to_segment("e169aa45-1ecf-4183-9955-b1499d5701d3", "78261eea-8f8b-4381-83c6-79fa7120f1cf")
```

**PHP**

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

use SendPing\SendPing;

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

$sendping->contacts->addToSegment('e169aa45-1ecf-4183-9955-b1499d5701d3', '78261eea-8f8b-4381-83c6-79fa7120f1cf');
```

**Python**

```python
import sendping

sendping.api_key = "mb_xxxxxxxxx"

sendping.Contacts.add_to_segment("e169aa45-1ecf-4183-9955-b1499d5701d3", "78261eea-8f8b-4381-83c6-79fa7120f1cf")
```

**Go**

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

client := sendping.NewClient("mb_xxxxxxxxx")

added, err := client.Contacts.AddToSegment("e169aa45-1ecf-4183-9955-b1499d5701d3", "78261eea-8f8b-4381-83c6-79fa7120f1cf")
```

**Rust**

```rust
use sendping::SendPing;

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

let _added = mb.contacts.add_to_segment("e169aa45-1ecf-4183-9955-b1499d5701d3", "78261eea-8f8b-4381-83c6-79fa7120f1cf").await?;
```

**Java**

```java
import co.sendping.SendPing;
import co.sendping.SendPingResponse;

SendPing sendping = new SendPing("mb_xxxxxxxxx");

SendPingResponse response = sendping.contacts().addToSegment(
        "e169aa45-1ecf-4183-9955-b1499d5701d3",
        "78261eea-8f8b-4381-83c6-79fa7120f1cf");
```

**.NET**

```csharp
using SendPing;

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

var resp = await sendping.ContactAddToSegmentAsync(
    "e169aa45-1ecf-4183-9955-b1499d5701d3",
    "78261eea-8f8b-4381-83c6-79fa7120f1cf");
```

**cURL**

```bash
curl -X POST 'https://www.sendping.co/api/contacts/e169aa45-1ecf-4183-9955-b1499d5701d3/segments/78261eea-8f8b-4381-83c6-79fa7120f1cf' \
  -H 'Authorization: Bearer mb_xxxxxxxxx'
```

**CLI**

```bash
sendping contacts add-to-segment e169aa45-1ecf-4183-9955-b1499d5701d3 78261eea-8f8b-4381-83c6-79fa7120f1cf
```

### Response

```json
{
  "id": "78261eea-8f8b-4381-83c6-79fa7120f1cf"
}
```
