Appfiliate Docs
appfiliate.io

Track Purchase

Records an in-app purchase and links it to a prior attribution. The affiliate (creator) is automatically resolved from the attribution record.

POST/v1/purchases

Track an in-app purchase and associate it with the affiliate who drove the install.


Request Body

ParameterTypeRequiredDescription
app_idstringOptionalYour app ID. Used for scoping and duplicate detection.
attribution_idstringRequiredThe attribution ID returned by the /v1/attribution endpoint. Links this purchase to the install and its affiliate.
product_idstringRequiredThe product identifier (e.g. "premium_monthly", "coins_500").
revenuenumberRequiredThe purchase amount (e.g. 9.99). Stored as a number.
currencystringOptionalISO 4217 currency code (e.g. "USD", "EUR"). Defaults to "USD".
transaction_idstringOptionalThe platform transaction ID from the App Store or Google Play. Used for duplicate detection.

Example Request

curl
curl -X POST https://us-central1-appfiliate-5a18b.cloudfunctions.net/api/v1/purchases \
  -H "Content-Type: application/json" \
  -d '{
    "app_id": "app_myapp",
    "attribution_id": "m1abc123_x9f2k4p1",
    "product_id": "premium_monthly",
    "revenue": 9.99,
    "currency": "USD",
    "transaction_id": "GPA.1234-5678-9012-34567"
  }'

Responses

Successful purchase

200 OK
{
  "status": "ok",
  "purchase_id": "m1def456_y8g3h5j2"
}

Duplicate transaction

If a purchase with the same transaction_id and app_id already exists, the API returns the existing purchase instead of creating a duplicate.

200 OK
{
  "status": "duplicate",
  "purchase_id": "m1def456_y8g3h5j2"
}

Missing required fields

400 Bad Request
{
  "error": "Missing required fields"
}

Duplicate detection

Always pass transaction_id when available. The API uses it together with app_id to detect and prevent duplicate purchase records. This makes it safe to retry failed requests without risking double-counted revenue.

Automatic creator resolution

You do not need to pass a creator_id. The API automatically looks up the attribution record to find the affiliate (creator) who drove the original install. The purchase is stored with the resolved creator_id so revenue can be attributed correctly.