POST /api/v1/profile/transaction-event/save/

保存交易事件

为用户画像记录一条商店交易事件。Adapty Mail 使用交易事件将用户画像纳入基于购买行为的流程——event_type 对应续订已取消、账单问题、已过期和已退款等流程——同时用于收入归因。

请在处理购买、续订和取消操作时发送这些事件。只有从未购买流程无需事件即可运行。

Request body

event_typestringrequired

交易事件的类型。基于购买的流程由这些值触发。

One of: "subscription_started", "subscription_renewed", "subscription_renewal_cancelled", "subscription_renewal_reactivated", "billing_issue_detected", "entered_grace_period", "subscription_refunded", "subscription_expired", "non_subscription_purchase", "non_subscription_purchase_refunded"

event_idstringrequired

此事件的唯一标识符,由您的系统管理。用于确保事件的幂等性。

event_datetimestringrequired

事件的记录时间,采用 ISO 8601 格式。

external_profile_idstringrequired

与保存用户画像时所使用的 external_profile_id 相同的稳定标识符。用于将交易与正确的用户画像关联。 您可以在用户画像存在之前发送交易。Adapty Mail 会将该事件以未关联状态存储,并在下一次携带相同标识符的保存操作时将其与用户画像关联。

customer_user_idstring

用户在您自己系统中的标识符。当 external_profile_id 无法匹配用户画像时,Adapty Mail 将使用此字段查找对应的用户画像。该字段不会存储在事件上。

emailstring

买家的电子邮件地址。当两个标识符均无法匹配用户画像时,Adapty Mail 将使用此字段查找对应的用户画像。该字段不会存储在事件上。

storestringrequired

交易来源的商店,例如 app_storeplay_storestripe

store_product_idstringrequired

所购产品在商店中的标识符。

store_transaction_idstringrequired

此交易在商店中的标识符。

store_original_transaction_idstringrequired

订阅链中第一笔交易的标识符。对于首次购买,此值与 store_transaction_id 相同。

purchased_atstringrequired

此交易发生的时间,采用 ISO 8601 格式。

originally_purchased_atstringrequired

订阅首次购买的时间,采用 ISO 8601 格式。

price_usdstring

交易金额(以美元计),以十进制字符串表示(例如 "9.99")。

expires_atstring

订阅的到期时间或已到期时间,采用 ISO 8601 格式。一次性购买无需填写此字段。

offerobject

应用于交易的促销活动或新用户优惠的详细信息。

categorystringrequired

One of: "introductory", "promotional", "offer_code", "win_back"

offer_typestringrequired

One of: "free_trial", "pay_as_you_go", "pay_up_front"

offer_idstring

商店中优惠的标识符(如有)。

Responses

交易事件已成功保存。响应体为空对象。

Schema
object
Example
{}

验证失败——必填字段缺失或无效。field_name 指示具体字段。

Schema

标准错误响应。每次失败都会返回一个包含此结构的 4XX 状态。

errorsarray of object
messagestring

人类可读的错误描述。

error_codestring

机器可读的错误标识符。

status_codeinteger

此错误的 HTTP 状态码。

field_namestring

导致错误的请求字段,如果错误与字段无关则为 null

Example
{
  "errors": [
    {
      "message": "Field required",
      "error_code": "base_error",
      "status_code": 400,
      "field_name": "event_type"
    }
  ]
}

密钥 API key 缺失或无效。

Schema

标准错误响应。每次失败都会返回一个包含此结构的 4XX 状态。

errorsarray of object
messagestring

人类可读的错误描述。

error_codestring

机器可读的错误标识符。

status_codeinteger

此错误的 HTTP 状态码。

field_namestring

导致错误的请求字段,如果错误与字段无关则为 null

Example
{
  "errors": [
    {
      "message": "Secret key doesn't exist",
      "error_code": "secret_key_does_not_exist_error",
      "status_code": 403,
      "field_name": null
    }
  ]
}