# Rank ads by performance

Returns the rank ads by performance, one page at a time.

```http
GET https://api.pozy.ai/v1/ads/performance
```

- Area: Ads / Ad Campaigns
- Auth: Authorization: Bearer pz_live_...

## Query parameters

- `accountId` (string, required)
- `adAccountId` (string)
- `fromDate` (string (date), required)
- `toDate` (string (date), required)
- `platform` (string): one of facebook, instagram, tiktok, linkedin, pinterest, google, twitter, openai, reddit, microsoft
- `sortBy` (string): one of spend, impressions, clicks, conversions, roas
- `limit` (integer)

## Example request

```bash
curl -X GET "https://api.pozy.ai/v1/ads/performance?accountId=696e0b682d0a31188e7a2ba9&fromDate=2026-10-01&toDate=2026-10-01&limit=50" \
  -H "Authorization: Bearer $POZY_API_KEY"
```

```ts
const res = await fetch("https://api.pozy.ai/v1/ads/performance?accountId=696e0b682d0a31188e7a2ba9&fromDate=2026-10-01&toDate=2026-10-01&limit=50", {
  headers: { Authorization: `Bearer ${process.env.POZY_API_KEY}` },
});
const data = await res.json();
if (!res.ok) throw new Error(data?.error ?? `Request failed with status ${res.status}`);
console.log(data);
```

```python
import os
import requests

resp = requests.get(
    "https://api.pozy.ai/v1/ads/performance",
    headers={"Authorization": f"Bearer {os.environ['POZY_API_KEY']}"},
    params={
        "accountId": "696e0b682d0a31188e7a2ba9",
        "fromDate": "2026-10-01",
        "toDate": "2026-10-01",
        "limit": 50,
    },
    timeout=30,
)
resp.raise_for_status()
print(resp.json())
```

## Response 200

- `ads`, array of object, required
  - `adId`, string
  - `platformAdId`, string: Can be null
  - `platform`, string
  - `name`, string
  - `status`, string: Can be null
  - `campaignName`, string: Can be null
  - `adSetName`, string: Can be null
  - `currency`, string: Can be null
  - `creative`, object
    - `type`, string: One of `image`, `video`, `carousel`, `document`. Can be null
    - `thumbnailUrl`, string: Can be null
    - `headline`, string: Can be null
    - `body`, string: Can be null
    - `linkUrl`, string: Can be null
  - `metrics`, object
    - `spend`, number
    - `impressions`, integer
    - `clicks`, integer
    - `ctr`, number
    - `conversions`, number
    - `costPerConversion`, number
    - `purchaseValue`, number
    - `roas`, number
    - `conversionsByType`, map of number

```json
{
  "ads": [
    {
      "adId": "6f40fa2fb0a7e728dd1a73b7",
      "platformAdId": "64149c3e561c1c5ac800f87a",
      "platform": "instagram",
      "name": "Acme",
      "status": "active",
      "campaignName": "Acme",
      "adSetName": "Acme",
      "currency": "USD",
      "creative": {
        "type": "image",
        "thumbnailUrl": "https://pozy.ai/media/example-1.jpg",
        "headline": "Launch day",
        "body": "string",
        "linkUrl": "https://pozy.ai/media/example-1.jpg"
      },
      "metrics": {
        "spend": 12.5,
        "impressions": 1,
        "clicks": 1,
        "ctr": 12.5,
        "conversions": 12.5,
        "costPerConversion": 12.5,
        "purchaseValue": 12.5,
        "roas": 12.5,
        "conversionsByType": {
          "key": 12.5
        }
      }
    }
  ]
}
```
