> ## Documentation Index
> Fetch the complete documentation index at: https://docs.backapp.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# RevenueCat

> Connect a RevenueCat webhook and verify a subscriber’s access in Backapp.

## Identify the subscriber

Register each device with `POST /v2/auth/device` and read the `user_id` from the response. Backapp matches this ID only among users of the app assigned to the webhook endpoint. [Register the device](https://docs.backapp.dev/quickstart.md#register-the-device)

### Use the Backapp user ID (recommended)

Call `Purchases.logIn(user_id)` before purchase or restore to use the Backapp user ID as the RevenueCat App User ID. Backapp looks for it in the event’s `app_user_id`, `original_app_user_id`, and `aliases`.

### Keep your existing RevenueCat App User ID

If your app needs to keep its own RevenueCat App User ID, such as an email address, set the `backapp_user_id` subscriber attribute on the signed-in RevenueCat customer before purchase. On each device, use the `user_id` returned for that device as `userId` below.

| SDK | Set the subscriber attribute |
| - | - |
| React Native | `await Purchases.setAttributes({ backapp_user_id: userId })` |
| Flutter | `await Purchases.setAttributes({'backapp_user_id': userId});` |
| iOS (Swift) | `Purchases.shared.attribution.setAttributes(["backapp_user_id": userId])` |
| Android (Kotlin) | `Purchases.sharedInstance.setAttributes(mapOf("backapp_user_id" to userId))` |

**Existing subscribers.** RevenueCat does not replay historical events. After the updated app sets the attribute, Backapp shows the subscription when it receives the next event that grants or renews access, such as `RENEWAL`.

### Multiple devices and account changes

Once Backapp has matched a customer’s devices through webhook events, they share subscription access. For example, if a purchase links a phone and a later renewal links a tablet, both devices have access. An expiration event ends access on both. If someone signs in to a different RevenueCat account on one device, that device stops following the previous account after Backapp receives the first event linking it to the new account.

## Connect the webhook

1. Ask the Backapp team for the RevenueCat endpoint URL and authorization secret for your app and environment. The URL ends in `/v2/webhooks/revenuecat/{public_id}`. This ID identifies the webhook endpoint. Use the assigned URL for all subscribers in the app.
2. In your RevenueCat project, open **Integrations → Webhooks** and add a configuration. Select the matching app and environment, enter the assigned URL, and paste the Backapp `whs_` secret into the **Authorization** field. Save the configuration.
   Starting with release `bf55ff2`, a new endpoint accepts deliveries with the correct Authorization value alone. Send a **TEST** event to verify the connection. The earlier release `f14ad43` requires HMAC signing for every RevenueCat endpoint.

### Enable HMAC signing (optional)

After saving the webhook, enable **HMAC webhook signing** in RevenueCat. Have the Backapp administrator save the key RevenueCat generates in the endpoint’s **Signing secret** field. From then on, every delivery must include both the authorization secret and a valid signature. Send another **TEST** event to verify the signed configuration. [RevenueCat webhook setup](https://www.revenuecat.com/docs/integrations/webhooks)

## Verify delivery and subscription state

For a **TEST** event, HTTP 200 with `{"ok":true}` confirms delivery. To verify the subscription itself, make a sandbox purchase with the identified user and read `GET /v2/me` for the same Backapp app and user. Check `subscription.is_active` and `subscription.product_id`. [Read subscription status](https://docs.backapp.dev/subscriptions.md)

If delivery returns HTTP 401, check the endpoint URL and authorization secret. If the endpoint has a signing secret configured, also check that RevenueCat signing is enabled, the keys match, and the signature timestamp is within five minutes of Backapp’s clock. If delivery succeeds but the subscription is missing, check the selected app and confirm the event contains the expected Backapp user ID in the RevenueCat identity fields or the `backapp_user_id` subscriber attribute. Backapp records an unmatched event without applying it to a subscription.

## How events affect access

| RevenueCat event | Effect on the Backapp subscription |
| - | - |
| `INITIAL_PURCHASE`, `RENEWAL`, `UNCANCELLATION`, `PRODUCT_CHANGE` | Set `is_active` and `will_renew` to true. |
| `NON_RENEWING_PURCHASE` | Grant access with `will_renew` set to false. |
| `SUBSCRIPTION_EXTENDED`, `REFUND_REVERSED`, `TEMPORARY_ENTITLEMENT_GRANT` | Grant access and preserve the current renewal setting. |
| `CANCELLATION` | Set `will_renew` to false. Access continues if already active. |
| `EXPIRATION` | Set `is_active`, `is_trial`, and `will_renew` to false. |
| `TEST`, `TRANSFER`, `BILLING_ISSUE`, `SUBSCRIPTION_PAUSED`, and other event types | Record the event only. |

For events that grant access, `period_type: TRIAL` sets `is_trial` to true. Backapp deduplicates deliveries by event ID within the app and source. An event with an older timestamp cannot overwrite a newer subscription update.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.