Skip to main content

Grant access levels manually

If you need to manually unlock premium features for specific users or user groups, you can do it using the Adapty API. This is useful for promotional campaigns, investor access, or special customer support cases.

In this guide, you'll learn how to identify users and grant them access levels programmatically.

Sample use cases

  • Promo codes: When users enter a valid promo code in your app, automatically grant them access to premium features.

  • Investor/beta tester access: Provide premium access to investors or beta testers by checking their custom attributes.

Step 1. Identify users

Adapty uses customer_user_id to identify users across platforms and devices. This is crucial for ensuring users keep their access after reinstalling the app or switching devices.

You need to create this ID once. When users first sign up from the app, you can pass their customer user ID during SDK activation, or use the identify method if the SDK was activated before signup.

important

If you identify new users after SDK activation, the SDK will first create an anonymous profile (it can't work without one). When you call identify with a customer user ID, a new profile will be created.

This behavior is normal and won't affect analytics accuracy. Read more here.

do {
try await Adapty.identify("YOUR_USER_ID") // Unique for each user
} catch {
// handle the error
}

Step 2. Grant access level via API

Once a user is identified with a customer_user_id, you can grant them access levels using the server-side API. This API call will grant the access level to the user, so they can access paid features without actually paying.

See the full method reference here.

tip

You can control user access by adding a custom attribute (e.g., Beta tester or Investor) in the Adapty dashboard. When your app launches, check this attribute in the user’s profile to grant access automatically. To update access, just change the attribute in the dashboard.

curl --request POST \
--url https://api.adapty.io/api/v2/server-side-api/purchase/profile/grant/access-level/ \
--header 'Accept: application/json' \
--header 'Authorization: Api-Key YOUR_SECRET_API_KEY' \
--header 'Content-Type: application/json' \
--header 'adapty-customer-user-id: CUSTOMER_USER_ID' \
--data '{
"access_level_id": "YOUR_ACCESS_LEVEL"
}'

Step 3. Verify access in the app

After granting access via API, the user's profile will be automatically updated. Fetch their profile to check their subscription status and unlock premium features.

do {
let profile = try await Adapty.getProfile()

if profile.accessLevels["YOUR_ACCESS_LEVEL_ID"]?.isActive ?? false {
// grant access to premium features
}
} catch {
// handle the error
}