# Get Campaign A/B Result

> GET /campaigns/:id/ab — retrieve the A/B winner evaluation for a campaign.

`GET /campaigns/:id/ab`

Returns the A/B winner evaluation for a campaign that has A/B testing enabled. SendPing runs a **two-proportion z-test** over the per-variant open, click, or reply outcomes recorded in the tracking tables, and returns which variant won, how confident the result is, and detailed per-variant metrics.

The `metric` field reflects the `ab_metric` set on the campaign (`open`, `click`, or `reply`). The `confidence` field is `low` when the sample is too small to trust, `medium` when the winner leads but it is not conclusive, and `high` when the result is statistically significant (p < 0.05 with at least 20 sends per arm).

If the variants are tied or one arm has no sends, the winner defaults to `A` and `fallback` is `true`.

**Path parameters**

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `id` | string | Yes | The campaign ID. |

**Node.js**

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

const mb = new SendPing('mb_xxxxxxxxx');

const { data, error } = await mb.campaigns.ab('8f5c2a1e-7b3d-4f9a-9c12-2e6d4a7b8c90');
console.log({ data, error });
```

**Ruby**

```ruby
require "sendping"

SendPing.api_key = "mb_xxxxxxxxx"

SendPing::Campaigns.ab("8f5c2a1e-7b3d-4f9a-9c12-2e6d4a7b8c90")
```

**PHP**

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

use SendPing\SendPing;

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

$sendping->campaigns->ab('8f5c2a1e-7b3d-4f9a-9c12-2e6d4a7b8c90');
```

**Python**

```python
import sendping

sendping.api_key = "mb_xxxxxxxxx"

sendping.Campaigns.ab("8f5c2a1e-7b3d-4f9a-9c12-2e6d4a7b8c90")
```

**Go**

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

client := sendping.NewClient("mb_xxxxxxxxx")

result, err := client.Campaigns.Ab("8f5c2a1e-7b3d-4f9a-9c12-2e6d4a7b8c90")
```

**Rust**

```rust
use sendping::SendPing;

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

let _result = mb.campaigns.ab("8f5c2a1e-7b3d-4f9a-9c12-2e6d4a7b8c90").await?;
```

**Java**

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

SendPing sendping = new SendPing("mb_xxxxxxxxx");

SendPingResponse response = sendping.campaigns().ab("8f5c2a1e-7b3d-4f9a-9c12-2e6d4a7b8c90");
```

**.NET**

```csharp
using SendPing;

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

var resp = await sendping.CampaignRetrieveAbResultAsync("8f5c2a1e-7b3d-4f9a-9c12-2e6d4a7b8c90");
```

**cURL**

```bash
curl -X GET 'https://www.sendping.co/api/campaigns/8f5c2a1e-7b3d-4f9a-9c12-2e6d4a7b8c90/ab' \
  -H 'Authorization: Bearer mb_xxxxxxxxx'
```

**CLI**

```bash
sendping campaigns ab 8f5c2a1e-7b3d-4f9a-9c12-2e6d4a7b8c90
```

### Response

```json
{
  "object": "campaign_ab",
  "campaign_id": "8f5c2a1e-7b3d-4f9a-9c12-2e6d4a7b8c90",
  "metric": "open",
  "a": {
    "variant": "A",
    "sent": 120,
    "conversions": 36,
    "rate": 0.3
  },
  "b": {
    "variant": "B",
    "sent": 118,
    "conversions": 47,
    "rate": 0.3983050847457627
  },
  "winner": "B",
  "fallback": false,
  "lift": 0.3276785714285714,
  "zScore": 2.14,
  "pValue": 0.0162,
  "confidence": "high",
  "reason": "variant B wins on open (p=0.016)"
}
```

> **Note:** Errors: `not_found` if the campaign does not exist or is not yours; `validation_error` if the campaign does not have A/B testing enabled.
