# 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. MailBlastr 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 { MailBlastr } from 'mailblastr';

const mb = new MailBlastr('mb_xxxxxxxxx');

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

**Ruby**

```ruby
require "mailblastr"

Mailblastr.api_key = "mb_xxxxxxxxx"

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

**PHP**

```php
$mailblastr = Mailblastr::client('mb_xxxxxxxxx');

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

**Python**

```python
import mailblastr

mailblastr.api_key = "mb_xxxxxxxxx"

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

**Go**

```go
package main

import (
    "fmt"
    "io"
    "net/http"
)

func main() {
    req, _ := http.NewRequest("GET", "https://api.mailblastr.com/campaigns/8f5c2a1e-7b3d-4f9a-9c12-2e6d4a7b8c90/ab", nil)
    req.Header.Set("Authorization", "Bearer mb_xxxxxxxxx")
    res, _ := http.DefaultClient.Do(req)
    defer res.Body.Close()
    out, _ := io.ReadAll(res.Body)
    fmt.Println(string(out))
}
```

**Rust**

```rust
use reqwest::Client;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let res = Client::new()
        .get("https://api.mailblastr.com/campaigns/8f5c2a1e-7b3d-4f9a-9c12-2e6d4a7b8c90/ab")
        .header("Authorization", "Bearer mb_xxxxxxxxx")
        .send()
        .await?;
    println!("{}", res.text().await?);
    Ok(())
}
```

**Java**

```java
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;

var client = HttpClient.newHttpClient();
var request = HttpRequest.newBuilder()
    .uri(URI.create("https://api.mailblastr.com/campaigns/8f5c2a1e-7b3d-4f9a-9c12-2e6d4a7b8c90/ab"))
    .header("Authorization", "Bearer mb_xxxxxxxxx")
    .method("GET", HttpRequest.BodyPublishers.noBody())
    .build();
var response = client.send(request, HttpResponse.BodyHandlers.ofString());
System.out.println(response.body());
```

**.NET**

```csharp
using System.Net.Http;
using System.Text;

var client = new HttpClient();
var request = new HttpRequestMessage(HttpMethod.Get, "https://api.mailblastr.com/campaigns/8f5c2a1e-7b3d-4f9a-9c12-2e6d4a7b8c90/ab");
request.Headers.Add("Authorization", "Bearer mb_xxxxxxxxx");
var response = await client.SendAsync(request);
Console.WriteLine(await response.Content.ReadAsStringAsync());
```

**cURL**

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

**CLI**

```bash
mailblastr 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.
