# G2 产品对比 API (g2.compare)

- Canonical page: https://everyinfra.com/g2-api/compare
- Endpoint: POST https://api.everyinfra.com/api/v1/social with {"platform": "g2", "action": "compare", "params": {...}}
- Price: $0.001389 per call ($1.39 per 1,000 requests); failed calls and empty results are not charged
- Returns: single object
- Mode: sync; add "mode": "async" for slow tasks

G2 产品对比读取 G2 上的一张软件对比页，返回对比页地址 `url`、组合短名 `combined_slug`、按维度拆开的评分明细 `ratings`，以及页面上推荐的替代产品列表 `alternatives_shown`。它回答「这些软件在 G2 上各维度评分有什么差别」，适合软件采购方逐项比较候选产品，产品营销团队跟踪自家产品和指定竞品的对比结果。

用 `slugs` 列出要比较的产品，系统用 -vs- 把它们拼成对比页地址；手里已有对比页时，直接传 `combined_slug` 或完整 `url`。返回的 `combined_slug` 即对比页地址里 /compare/ 后的完整组合短名，可以和读取日期一起存档，日后对照同一张对比页的变化。

## Health

- Live health (24h percent, hourly and daily trends): https://api.everyinfra.com/api/v1/social/availability?platform=g2&action=compare

## Parameters

| name | type | required | default | description |
|---|---|---|---|---|
| slugs | not declared | yes | not declared | 要比较的产品 slug 字符串数组，也可在数组中放产品 URL；默认用 -vs- 拼成 G2 对比页路径。 |
| combined_slug | not declared | no | not declared | G2 /compare/ 后的完整组合短名；优先于 slugs 自动拼接，完整 url 的优先级更高。 |
| url | not declared | no | not declared | 完整 G2 /compare/ 对比页 URL；提供后优先于 slugs 或 combined_slug 构造的地址。 |

## Response fields (items in `results`)

| field | meaning |
|---|---|
| url | 该记录在原平台上的可访问链接。 |
| combined_slug | 对比页网址 /compare/ 后面的组合短名，如 产品A-vs-产品B。 |
| product_count | 产品数：vendor 里是厂商旗下产品数，compare 里是参与对比的产品数。 |
| products | 产品列表：vendor 里是厂商旗下产品，compare 里是参与对比的产品；每项含短名、名称、链接、评分和评价数。 |
| ratings | 分维度评分明细。 |
| alternatives_shown | 对比页上展示的替代产品列表，每项含短名、名称和链接。 |
| platform | 数据来源平台标识，与请求里的 platform 一致（如 xiaohongshu、tiktok）。 |

## Example

```bash
curl -X POST 'https://api.everyinfra.com/api/v1/social' \
  -H "Authorization: Bearer $EVERYINFRA_API_KEY" \
  -H 'Content-Type: application/json' \
  --data-raw '{
  "platform": "g2",
  "action": "compare",
  "params": {
    "slugs": [
      "slack",
      "microsoft-teams"
    ]
  }
}'
```

```python
import os
import requests

response = requests.post(
    "https://api.everyinfra.com/api/v1/social",
    headers={"Authorization": f"Bearer {os.environ['EVERYINFRA_API_KEY']}"},
    json={
        "platform": "g2",
        "action": "compare",
        "params": {
            "slugs": [
                "slack",
                "microsoft-teams",
            ],
        },
    },
    timeout=120,
)
print(response.status_code)
print(response.json())
```

## Response example

No real sample for these example parameters yet: structure only, every value is a placeholder (…).

```text
{
  "id": "req_…",
  "platform": "g2",
  "action": "compare",
  "results": {
    "url": …,
    "combined_slug": …,
    "product_count": …,
    "products": …,
    "ratings": …,
    "alternatives_shown": …,
    "platform": …
  },
  "billing": {
    "charged": …,
    "charged_usd": …,
    "balance_after_usd": …,
    …
  },
  "quota": { … }
}
```

## FAQ

### 要比较的产品怎么填？

在 `slugs` 里放一个字符串数组，每个元素是一款产品的 G2 slug，即产品链接里 /products/ 后面那一段，也可以直接放产品链接；系统用 -vs- 把它们拼成对比页地址。产品的 G2 链接可以从 G2 关键词搜索的结果里取。

### 同时传了几种输入，以哪个为准？

完整的对比页 `url` 优先，其次是 `combined_slug`，即地址里 /compare/ 后面那段完整组合短名，最后才是 `slugs`。建议只传其中一种；从浏览器复制了对比页地址时，整条放进 `url`，不用再填 slug。

### `ratings` 和 `alternatives_shown` 怎么读？

`ratings` 是对比页按维度拆开的评分明细，能看出参与对比的产品具体差在哪些方面，而不是只比一个总分。`alternatives_shown` 是页面上推荐的替代产品，每项带短名、名称和链接，短名可以接着交给 G2 评价。做竞品跟踪时，把每次的 `ratings` 按维度分别存下，比较同一维度的前后变化。

## Also

- Capability catalog (no key): https://api.everyinfra.com/api/v1/social/catalog?platform=g2
- OpenAPI: https://everyinfra.com/openapi.json · Agents guide: https://everyinfra.com/agents.md
