---
title: Events
description: Events - MailPirate Docs
---

# Events

`POST /events`

Record something a person did - viewed a product, started checkout, placed an order from a custom source, and similar. Events power segments, flows, and intelligence.

If you include `email`, MailPirate creates or updates that profile before storing the event.

## Request

```http
POST /api/v1/marketing/events
Authorization: Bearer mp_...
Content-Type: application/json
```

```json
{
  "store_slug": "main",
  "name": "Viewed Product",
  "email": "buyer@example.com",
  "properties": {
    "sku": "TEE-1",
    "product_id": "123",
    "name": "Harbor Tee"
  },
  "idempotency_key": "view:buyer@example.com:TEE-1:2026-11-18T12:00:00Z"
}
```

| Field | Required | Notes |
|-------|----------|-------|
| `store_slug` | Yes | |
| `name` | Yes | Event name string |
| `email` | No | Upserts profile when present |
| `properties` | No | Arbitrary JSON object |
| `idempotency_key` | No | Dedupes retries of the same event |

## Response `200`

```json
{
  "id": 12345
}
```

## Idempotency

If your client might retry (mobile offline queue, webhook replay), send a stable `idempotency_key` for that logical event. That prevents double-counting the same view/purchase in segments and journeys.

## Retention

MailPirate keeps events only as long as they stay useful for journeys and segments, then deletes them automatically:

| Event | Kept about |
|-------|------------|
| `Viewed Product` | 60 days |
| `Added to Cart` | 90 days |
| `Started Checkout` | 45 days |
| `Placed Order` / `Ordered Product` | 400 days |
| Other event names | 180 days |

Recent windows still power abandoned cart, browse segments, and RFM-style order history. Older browse noise is not stored forever.

## Naming tips

Pick clear, stable names your segments and flows can rely on, for example:

- `Viewed Product`
- `Started Checkout` (abandoned cart - include `items`, `checkout_url`, `total`, `currency`)
- `Placed Order`
- `Subscribed`

### Abandoned cart payload example

```json
{
  "store_slug": "main",
  "name": "Started Checkout",
  "email": "buyer@example.com",
  "idempotency_key": "woo-checkout:abc123",
  "properties": {
    "currency": "EUR",
    "total": 84.5,
    "checkout_url": "https://shop.example/checkout/",
    "cart_url": "https://shop.example/cart/",
    "first_name": "Ada",
    "items": [
      {
        "name": "Harbor Tee",
        "sku": "TEE-1",
        "quantity": 1,
        "price": 42.25,
        "url": "https://shop.example/product/harbor-tee/",
        "image_url": "https://shop.example/img/tee.jpg"
      }
    ]
  }
}
```

MailPirate turns `items` into `{{ cart_html }}` for the Abandoned cart journey. The WooCommerce plugin sends this shape for you; Shopify checkouts webhooks map into the same properties (including `abandoned_checkout_url` as `checkout_url`).

Shop connectors already ingest many commerce events. Use the API when you need custom on-site behavior beyond Woo plugin / Shopify checkout webhooks.

## Example

```bash
curl -sS -X POST "https://app.mailpirate.com/api/v1/marketing/events" \
  -H "Authorization: Bearer $TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "store_slug": "main",
    "name": "Viewed Product",
    "email": "buyer@example.com",
    "properties": { "sku": "TEE-1" },
    "idempotency_key": "view:buyer@example.com:TEE-1:batch-42"
  }'
```

```json
{"@context":"https://schema.org","@graph":[{"@type":"Organization","@id":"https://mailpirate.com/#organization","name":"MailPirate","legalName":"Jure Rožman s.p.","url":"https://mailpirate.com/","logo":{"@type":"ImageObject","@id":"https://mailpirate.com/#logo","url":"https://mailpirate.com/img/logo/mailpirate-logo.svg","contentUrl":"https://mailpirate.com/img/logo/mailpirate-logo.svg"},"image":{"@id":"https://mailpirate.com/#logo"},"description":"MailPirate is email marketing built for ecommerce stores: campaigns, automated journeys, living audiences, store sync, and deliverability control without managing mail servers yourself.","slogan":"Email that sells more for your store.","foundingDate":"2019-01-29","founder":{"@id":"https://mailpirate.com/#person-jure-rozman"},"address":{"@type":"PostalAddress","streetAddress":"Šinkov Turn 24A","addressLocality":"Vodice","postalCode":"1217","addressCountry":"SI"},"email":"info@mailpirate.com","telephone":"+38640504630","vatID":"SI72369213","identifier":[{"@type":"PropertyValue","propertyID":"AJPES registration number","value":"6881475000"}],"contactPoint":{"@type":"ContactPoint","contactType":"customer support","email":"info@mailpirate.com","telephone":"+38640504630","availableLanguage":["English"]},"knowsAbout":[{"@type":"Thing","name":"Email marketing"},{"@type":"Thing","name":"Ecommerce automation"},{"@type":"Thing","name":"Email deliverability"}],"areaServed":["SI","EU","GB","US"],"sameAs":["https://www.linkedin.com/company/mailpirate"]},{"@type":"Person","@id":"https://mailpirate.com/#person-jure-rozman","name":"Jure Rožman","jobTitle":"Founder","worksFor":{"@id":"https://mailpirate.com/#organization"},"description":"Founder of MailPirate. Builds ecommerce email tooling focused on fair billing, automation, and deliverability.","url":"https://mailpirate.com/about-us","sameAs":["https://www.linkedin.com/in/jurerozman/"]},{"@type":"WebSite","@id":"https://mailpirate.com/#website","url":"https://mailpirate.com/","name":"MailPirate","inLanguage":"en","publisher":{"@id":"https://mailpirate.com/#organization"},"about":{"@id":"https://mailpirate.com/#software"}},{"@type":"SoftwareApplication","@id":"https://mailpirate.com/#software","name":"MailPirate","applicationCategory":"BusinessApplication","applicationSubCategory":"Email marketing","operatingSystem":"Web","url":"https://mailpirate.com/","description":"Ecommerce email platform for Shopify and WooCommerce stores: campaigns, flows, segments, intelligence, and dedicated sending with deliverability controls.","publisher":{"@id":"https://mailpirate.com/#organization"},"featureList":["Campaigns and reporting","Automated flows (welcome, cart recovery, win-back)","Segments and lists","Store connectors (Shopify, WooCommerce)","Intelligence (RFM, affinity, send-time, replenishment)","Deliverability scorecard and dedicated sending","Marketing API and embed forms"]}]}
```
