Grant access level with server-side API
Provides access level to your end-user without providing info on the transaction. This comes in handy if you have bonuses for referrals or other events related to your products.
The access level provided by this method will not be reflected in your analytics. It will be sent to only webhook integration, and only in this case will appear in the Event Feed. If webhook integration is not enabled, granting access level will not be shown in the Event Feed.
To grant access and simultaneously provide the transaction details, please use the Set Transaction request which is recommended.
Method and endpoint
POST https://api.adapty.io/api/v2/server-side-api/purchase/profile/grant/access-level/
Example request
- cURL
- Python
- JavaScript
curl --location 'https://api.adapty.io/api/v2/server-side-api/purchase/profile/grant/access-level/' \
--header 'Authorization: Api-Key <YOUR_SECRET_API_KEY>' \
--header 'adapty-customer-user-id: <YOUR_CUSTOMER_USER_ID>' \
--header 'Content-Type: application/json' \
--data '{
"access_level_id": "premium",
"starts_at": "2022-10-12T09:42:50.000000+0000",
"expires_at": "2024-10-12T09:42:50.000000+0000"
}'
import requests
url = "https://api.adapty.io/api/v2/server-side-api/purchase/profile/grant/access-level/"
payload = {
"access_level_id": "premium",
"starts_at": "2022-10-12T09:42:50.000000+0000",
"expires_at": "2024-10-12T09:42:50.000000+0000"
}
headers = {
"Authorization": "Api-Key <YOUR_SECRET_API_KEY>",
"adapty-customer-user-id": "<YOUR_CUSTOMER_USER_ID>",
"Content-Type": "application/json"
}
response = requests.post(url, headers=headers, json=payload)
print(response.text)
const myHeaders = new Headers();
myHeaders.append("Authorization", "Api-Key <YOUR_SECRET_API_KEY>");
myHeaders.append("adapty-customer-user-id", "<YOUR_CUSTOMER_USER_ID>");
myHeaders.append("Content-Type", "application/json");
const raw = JSON.stringify({
"access_level_id": "premium",
"starts_at": "2022-10-12T09:42:50.000000+0000",
"expires_at": "2024-10-12T09:42:50.000000+0000"
});
const requestOptions = {
method: "POST",
headers: myHeaders,
body: raw,
redirect: "follow"
};
fetch("https://api.adapty.io/api/v2/server-side-api/purchase/profile/grant/access-level/", requestOptions)
.then((response) => response.text())
.then((result) => console.log(result))
.catch((error) => console.error(error));
Placeholders:
<YOUR_CUSTOMER_USER_ID>
: The unique ID of the customer in your system.<YOUR_SECRET_API_KEY>
: Your secret API key for authorization.
Parameters
Parameter | Type | Required in request | Nullable in request | Description |
---|---|---|---|---|
access_level_id | String | ➕ | ➖ | Paid access level ID configured by you in the Access Levels page of the Adapty Dashboard. |
starts_at | ISO 8601 date | ➖ | ➕ | The datetime when the access level will be active. Maybe in the future. The default value is null . |
expires_at | ISO 8601 date | ➖ | ➕ | The datetime when the access level will expire. It may be in the past and may be null for lifetime access. The default value is null . |
Successful response: 200: OK
The request is successful. The response body contains the data
field, which encapsulates the user's profile and associated information.
Parameter | Type | Nullable | Description |
---|---|---|---|
data | Object | ➖ | Contains the Profile object with user details and metadata. |
data object structure
The data
field is the primary container for the user profile. It includes several fields:
Parameter | Type | Nullable | Description |
---|---|---|---|
app_id | String | ➖ | The internal ID of your app. You can see in the the Adapty Dashboard: App Settings -> General tab. |
profile_id | UUID | ➖ | Adapty profile ID. You can see it in the Adapty ID field on the Adapty Dashboard -> Profiles -> specific profile page. |
customer_user_id | String | ➕ | The ID of your user in your system. You can see it in the Customer user ID field on the Adapty Dashboard -> Profiles -> specific profile page. It will work only if you identify the users in your mobile app code via Adapty SDK. |
total_revenue_usd | Float | ➖ | A float value representing the total revenue in USD earned in the profile. |
segment_hash | String | ➖ | Internal parameter. |
timestamp | Integer | ➖ | Response time in milliseconds, needs for resolve a race condition. |
custom_attributes | Dictionary | ➖ | A maximum of 30 custom attributes to the profile are allowed to be set. If you provide the Key: The key must be a string with no more than 30 characters. Only letters, numbers, dashes, points, and underscores allowed Value: The attribute value must be no more than 30 characters. Only strings and floats are allowed as values, booleans will be converted to floats. Send an empty value or null to delete the attribute. |
access_levels | Dictionary | ➕ | Profile Paid Access Level objects. Dictionary where the keys are paid access level identifiers configured by a developer in the Adapty Dashboard. Values are Access level objects. Can be null if the customer has no access levels. |
subscriptions | Dictionary | ➕ | Dictionary where the keys are vendor product IDs. Values are Subscription objects. Can be null if the customer has no subscriptions. |
non_subscriptions | Dictionary | ➕ | Dictionary where the keys are vendor product ids. Values are an array of Non-Subscription objects. Can be null if the customer has no purchases. |