BACKEND / API

Server API.

Your backend's way into RevFox. Check what a customer is entitled to, keep their attributes in sync, hand out promotional access and erase customers on request.

01

Authentication

Create a key under API keys → Secret API keys in the panel. It is shown once; RevFox stores only its hash. Send it as a bearer token to your API server, the api_url the SDKs use:

curl https://api.example.com/v1/customers/user_123 \
  -H "Authorization: Bearer sk_..."
Keep it on your server

A secret key reads and changes every customer in its project. Never put it in an app or a web page; apps use their public SDK key. Delete a key from the panel to revoke it.

The key decides the project, so URLs carry no project ID. Customer IDs in paths must be URL-encoded, for example %24RCAnonymousID%3Aabc. Any of a customer's aliases finds them.

02

The customer object

Every endpoint except delete answers with the customer as it is after the change:

{
  "customer": {
    "customer_id": "user_123",
    "original_customer_id": "user_123",
    "aliases": ["user_123", "$RCAnonymousID:abc"],
    "first_seen_at_ms": 1700000000000,
    "last_seen_at_ms": 1760000000000,
    "attributes": {
      "$email": { "value": "[email protected]", "updated_at_ms": 1760000000000 }
    },
    "benefits": ["premium"],
    "purchases": [
      {
        "id": "2000000123",
        "store": "APP_STORE",
        "environment": "PRODUCTION",
        "product_id": "pro.monthly",
        "benefits": ["premium"],
        "is_active": true,
        "will_renew": true,
        "expires_at_ms": 1762000000000
      }
    ]
  }
}
FieldDescription
customer_idThe ID in the request.
original_customer_id, aliasesThe customer's original ID, and every ID that resolves to them.
first_seen_at_ms, last_seen_at_msFirst and latest contact, in Unix milliseconds.
attributesEvery attribute with its value and when it last changed.
benefitsWhat the customer can use now, from purchases and promotional grants.
purchasesThe same purchase statuses the SDK gets. Grants appear with store: "PROMOTIONAL".
03

Get a customer

GET/v1/customers/{id}

Returns the customer, or 404 when RevFox does not know the ID. Add ?environment=PRODUCTION or ?environment=SANDBOX to read one environment's purchases; both are read by default.

curl "https://api.example.com/v1/customers/user_123?environment=PRODUCTION" \
  -H "Authorization: Bearer sk_..."
04

Set attributes

POST/v1/customers/{id}/attributes

Sets attributes; null removes one. Creates the customer when RevFox does not know them yet. Body up to 64 KiB.

curl -X POST https://api.example.com/v1/customers/user_123/attributes \
  -H "Authorization: Bearer sk_..." \
  -H "Content-Type: application/json" \
  -d '{"attributes": {"$email": "[email protected]", "plan": "team", "referrer": null}}'

Answers 200 with the customer, or 400 when attributes is empty or has an empty key.

05

Grant a benefit

POST/v1/customers/{id}/grants

Gives the customer a benefit without a store purchase, for a duration or until a time.

curl -X POST https://api.example.com/v1/customers/user_123/grants \
  -H "Authorization: Bearer sk_..." \
  -H "Content-Type: application/json" \
  -d '{"benefit": "premium", "duration": "monthly"}'

# or until a set time
  -d '{"benefit": "premium", "expires_at_ms": 1762000000000}'
FieldDescription
benefitRequired. A benefit identifier from the project.
durationdaily, three_day, weekly, monthly, two_month, three_month, six_month, yearly or lifetime.
expires_at_msInstead of duration: when the grant ends, in Unix milliseconds.

Answers 201 with the customer, or 400 for an unknown benefit or a bad duration. Grants add no revenue, count in every environment and are sent to webhooks. See promotional grants.

06

Revoke a benefit

DELETE/v1/customers/{id}/grants/{benefit}

Ends the customer's active promotional grants of the benefit. Store purchases are not affected. Answers 200 with the customer, or 404 when there was no active grant.

curl -X DELETE https://api.example.com/v1/customers/user_123/grants/premium \
  -H "Authorization: Bearer sk_..."
07

Delete a customer

DELETE/v1/customers/{id}

Permanently deletes the customer, their aliases, the purchases they own, their history and grants, for example for a GDPR erasure request. It does not cancel store subscriptions. See deleting a customer.

curl -X DELETE https://api.example.com/v1/customers/user_123 \
  -H "Authorization: Bearer sk_..."
{ "deleted": true, "customer_id": "user_123" }
08

Errors

Errors are JSON, such as {"error": "customer not found"}. An unexpected server error is answered as plain text.

StatusMeaning
400The body is missing or invalid.
401No bearer key, or an unknown one.
404Unknown customer, or no grant to revoke.
500An unexpected server error. Retry later.

Get told about changes

Receive webhooks.

Webhooks