Skip to main content

Processing and adding a subscription

Once the app received a push token, the app must transfer it to Altcraft MP in order to create a subscription. The API request is used for it.

With this request, you can:

  • Add new subscriptions.
  • Change the status of existing subscriptions.

The profile search mode can be set using the matching field in the request (see specification below). If the profile is not found, a new one will be created.

Moreover, if several databases are specified in the resource, then all of them will be processed separately. A request to such a resource will create and update profiles in several databases at once. An example of such a case can be seen below.
If there are no databases in the resource, then an error will be returned.

URL

Method: POST

https://<cookiesaver_host>/push_subscribe

Request parameters

ParameterTypeExampleRequiredDescription
idstring"abcdefghijklmnqrstuvwxyz"NoProfile ID
resource_tokenstring"abcdefghijklmnqrstuvwxyz"YesUnique resource ID.
db_ids[ ] int[ 2,3 ]NoResource database filter.
matchingstring"custom"NoProfile search mode.
If the parameter is not passed or is empty, profile search by ID will be used. If ID is also not passed, search by push subscriptions will be used.

For the push_subscribe method, this parameter can only accept the following values:
  • custom
  • profile_id
subscriptionsJSON array
SubscriptionObject
[{
"provider" : "android-firebase",
"subscription_id" : "%subscriptionid%"
}]
YesPush subscriptions that should be added to profile or should be updated.
"subscription_id" is unique for each device, Firebase provides it.

SubscriptionObject

ParameterTypeExampleRequiredDescription
providerstring"android-firebase"YesAltcraft MP Provider ID.
The available values:
  • android-firebase
  • ios-firebase
  • ios-apns
  • yandex-Appmetrica-device-id-ios
  • yandex-Appmetrica-device-id-android
  • yandex-Appmetrica-ios-ifa
  • yandex-Appmetrica-google-aid
  • yandex-Appmetrica-android-token
  • yandex-Appmetrica-ios-token
  • android-huawei
  • ios-huawei

>Each token type in AppMetrica has its own provider ID.
subscription_idstring"abcdef-ghijklmn-qrstuvwxyz"YesSubscription push token
unsubscribeboolfalseNoUnsubscribe flag. Dismiss subscription if its value — true.

Response parameters

ParameterTypeDescription
dataJSON array
DataObject
Information about the created subscriptions.

The array can contain several objects in the following cases:
  • Several SubscriptionObject were passed in the request.
  • ID field was not used in the request, and the Altcraft MP resource uses several databases. In this case, a new profile with subscriptions will be added for each database from the resource.
errorintError code
error_textstringError text

DataObject

ParameterTypeDescription
subscription_idstring"abcdef-ghijklmn-qrstuvwxyz"Subscription push token
unsubscribeboolfalseFlag whether the subscription was added or canceled
profile_idstring"5fb62e815ae47a4aa04dfadd"ID of the profile (transferred or newly created) for which the subscription was added.
providerstring"android-firebase"Altcraft MP Provider ID.
The available values:
  • android-firebase
  • ios-firebase
  • ios-apns
  • yandex-Appmetrica-device-id-ios
  • yandex-Appmetrica-device-id-android
  • yandex-Appmetrica-ios-ifa
  • yandex-Appmetrica-google-aid
  • yandex-Appmetrica-android-token
  • yandex-Appmetrica-ios-token
  • android-huawei
  • ios-huawei

Each token type in AppMetrica has its own provider ID.
db_idint2Altcraft MP Database ID. The profile is stored in this database.
resource_idint1Altcraft MP resource ID.
subscription_hash_idstring"92807e89"Subscription hash
statusstring"error"Operation status
  • ok
  • error
descriptionstring"Duplicate push subscription"Error description

Examples

Request with matching by system profile ID

{
"id": "59db33d269d426509e9c4bf9",
"resource_token": "3LXP2FRcRxJ-7b14db88ec937f14",
"subscriptions": [
{
"provider": "android-firebase",
"subscription_id": "%subscriptionid%"
}
]
}

Request with matching by a custom profile field

{
"resource_token": "3LXP2FRcRxJ-7b14db88ec937f14",
"matching": "custom",
"field_name": "CustomNumber1",
"field_value": 123,
"subscriptions": [
{
"provider": "android-firebase",
"subscription_id": "%subscriptionid%"
}
]
}

Request with matching by push subscriptions

{
"resource_token": "3LXP2FRcRxJ-7b14db88ec937f14",
"subscriptions": [
{
"provider": "android-firebase",
"subscription_id": "%subscriptionid%"
}
]
}

Request to a resource with several databases

{
"resource_token": "3LXP2FRcRxJ-7b14db88ec937f14",
"matching": "custom",
"field_name": "CustomNumber1",
"field_value": 12345,
"subscriptions": [
{
"provider": "android-firebase",
"subscription_id": "%subscriptionid%"
}
]
}

Request with matching by a custom profile field in a certain database

{
"resource_token": "3LXP2FRcRxJ-7b14db88ec937f14",
"db_ids": [1],
"matching": "custom",
"field_name": "CustomNumber1",
"field_value": 123,
"subscriptions": [
{
"provider": "android-firebase",
"subscription_id": "%subscriptionid%"
}
]
}

Request did not update or add any profile subscriptions

{
"resource_token": "3LXP2FRcRxJ-7b14db88ec937f14",
"matching": "custom",
"field_name": "CustomNumber1",
"field_value": 12345,
"subscriptions": [
{
"provider": "android-firebase",
"subscription_id": "%subscriptionid%"
}
]
}