Skip to content

HTTP API 端点

所有端点共享同一 base URL、同一组鉴权 header(见 鉴权)以及同一套 ret_code 枚举(见 限流与错误)。

Base URL说明
https://openapi.abetterchoice.ai/abc/生产地址,本页所有示例都基于它。

端点一览

方法路径作用
POST/abc/get_experiments返回某 unit_id 的实验分组。
POST/abc/get_feature_flags返回某 unit_id 的命名 feature flag。

/abc/get_experiments 在返回真实分组(group_id != -1)时会由服务端自动记录一条曝光。 HTTP 调用方今天没有独立的"上报曝光"接口。

拉取实验

POST /abc/get_experiments 返回某 unit_id 在项目下一个或多个层的分组。

请求

字段类型必填说明
project_idstring项目 ID,控制台 URL /app/ 后那段。
unit_idstring稳定的用户 / 会话 / 设备 ID,详见 用户对象
profilesmap (attr → profile)用于受众目标的属性值。
profiles[attr].user_attrsstring 数组属性值,始终为字符串:数字与布尔在发送前先转字符串。
filter_options.layer_keysstring 数组限制响应只包含这些层名。
filter_options.experiment_keysstring 数组限制响应只包含这些实验名。

最简请求:

json
{ "project_id": "6666", "unit_id": "user_id_1" }

带过滤与属性的请求:

json
{
  "project_id": "6666",
  "unit_id": "user_id_1",
  "filter_options": {
    "layer_keys": ["layer_on_landing_page"]
  },
  "profiles": {
    "age":     { "user_attrs": ["18"] },
    "country": { "user_attrs": ["US"] }
  }
}

响应

json
{
  "ret_code": 100,
  "msg": "",
  "exp_data": {
    "layer_on_landing_page": {
      "experiment_key": "experiment_for_button",
      "group_id": 8942824,
      "group_key": "Treatment_A",
      "params": { "color": "blue", "size": "20" }
    },
    "layer_with_no_experiment": {
      "experiment_key": "default",
      "group_id": -1,
      "group_key": "default",
      "params": {}
    }
  }
}

阅读响应:

  • exp_data层名为 key,不是实验名。
  • group_id == -1group_key == "default" 表示该 unit_id 在这一层没有命中任何活跃实验, 请使用调用方的默认值。
  • params 在 HTTP 中始终返回字符串值,使用前在客户端转 bool / number / JSON。

curl 示例

bash
ak="your-secret-key-name"
token="your-API-token"
et=$(date +%s)
sig=$(echo -n "${token}${ak}${et}" | md5)

curl -X POST 'https://openapi.abetterchoice.ai/abc/get_experiments' \
  -H "Content-Type: application/json" \
  -H "X-Ak: $ak" -H "X-Et: $et" -H "X-Es: $sig" \
  -d '{
        "project_id": "6666",
        "unit_id":    "user_id_1",
        "filter_options": { "layer_keys": ["layer_on_landing_page"] },
        "profiles":   { "age": { "user_attrs": ["18"] } }
      }'

拉取 feature flag

POST /abc/get_feature_flags 返回命名 feature flag 的值,可选地带回驱动它的实验。

请求

字段类型必填说明
project_idstring项目 ID。
unit_idstring稳定的用户 / 会话 / 设备 ID。
feature_namesstring 数组要查询的 feature flag 名。
profilesmap (attr → profile)用于受众目标的属性值(与实验接口字段一致)。
json
{
  "project_id": "6666",
  "unit_id": "user_id_1",
  "feature_names": ["my_colour", "my_button_type"],
  "profiles": { "age": { "user_attrs": ["18"] } }
}

响应

feature flag 与实验绑定时:

json
{
  "ret_code": 100,
  "data": {
    "my_colour": {
      "name":  "my_colour",
      "value": "red",
      "relative_experiment": {
        "group_id":  76178323141,
        "group_key": "experiment_for_color",
        "exp_key":   "control_group_for_color_experiment",
        "params":    { "my_colour": "red" }
      }
    }
  }
}

独立 feature flag 时:

json
{
  "ret_code": 100,
  "data": {
    "my_colour": {
      "name":  "my_colour",
      "value": "red",
      "relative_experiment": null
    }
  }
}

curl 示例

bash
ak="your-secret-key-name"
token="your-API-token"
et=$(date +%s)
sig=$(echo -n "${token}${ak}${et}" | md5)

curl -X POST 'https://openapi.abetterchoice.ai/abc/get_feature_flags' \
  -H "Content-Type: application/json" \
  -H "X-Ak: $ak" -H "X-Et: $et" -H "X-Es: $sig" \
  -d '{
        "project_id":   "6666",
        "unit_id":      "user_id_1",
        "feature_names": ["my_colour", "my_button_type"],
        "profiles":      { "age": { "user_attrs": ["18"] } }
      }'

返回码

完整枚举在 限流与错误。本接口最常见的几项:

ret_code含义
100成功。
101无权限。
102限流。
103缺少 project ID。
104服务端错误。
105服务端错误。
0未知。