# Subscription API

{% hint style="warning" %}
Do not forget to configure subscriptions settings in devtodev to successfully receive data! \
[Android setup](https://docs.devtodev.com/integration/server-api/pages/-MeASFB85TrtEFbUq3Pm#step-3.-settings-on-devtodev-side) \
[iOS setup](https://docs.devtodev.com/integration/server-api/pages/-MeeHqlQ6GNgcFpPS9uN#step-2.-settings-on-devtodev-side)
{% endhint %}

## General provisions

Endpoint:

```http
https://api.devtodev.com/subscriptions/api?apikey={project’s API key}
```

Query type: POST

The query body is a JSON object with fields described in the table below.

### Fields

| Name                                                                                                                                                | Description                                                                                                                                                                                                      |
| --------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| **`notificationType`**                                                                                                                              | Type of notification                                                                                                                                                                                             |
| **`originalTransactionId`**                                                                                                                         | ID of the original transaction                                                                                                                                                                                   |
| **`transactionId`**                                                                                                                                 | Transaction ID                                                                                                                                                                                                   |
| **`startDateMs`**                                                                                                                                   | Subscription start date in milliseconds in UTC                                                                                                                                                                   |
| **`expiresDateMs`**                                                                                                                                 | Subscription expiration date in milliseconds in UTC                                                                                                                                                              |
| **`product`**                                                                                                                                       | Subscription SKU                                                                                                                                                                                                 |
| **`productType`**                                                                                                                                   | Subscription type (line)                                                                                                                                                                                         |
| **`price`**                                                                                                                                         | Subscription price                                                                                                                                                                                               |
| **`currency`**                                                                                                                                      | Currency of the subscription payment                                                                                                                                                                             |
| **`isTrial`**                                                                                                                                       | The event is flagged if it is trial and is not flagged if it’s a subscription                                                                                                                                    |
| **`gracePeriod`**                                                                                                                                   | Extension of subscription renewal date in days. If this field is filled in and the user did not renew the subscription before the expiration date, then wait for `gracePeriod` days value to flag it as expired. |
| **Fields for user identification (Attention! Regardless of the type of notification, at least one of the user IDs must be specified in the query)** |                                                                                                                                                                                                                  |
| **`idfa`**                                                                                                                                          | Available platforms: iOS                                                                                                                                                                                         |
| **`idfv`**                                                                                                                                          | Available platforms: iOS                                                                                                                                                                                         |
| **`advertisingId`**                                                                                                                                 | Available platforms: Android, Windows                                                                                                                                                                            |
| **`androidId`**                                                                                                                                     | Available platforms: Android                                                                                                                                                                                     |
| **`userId`**                                                                                                                                        | The same as Main ID in user card                                                                                                                                                                                 |
| **`customId`**                                                                                                                                      | <p>String custom user ID</p><p>Available platforms: all platforms</p>                                                                                                                                            |
| **`devtodevId`**                                                                                                                                    | <p>d2d numeric user id. <br>Available platforms: all platforms</p>                                                                                                                                               |

### Notification types

| Notification type  | Description                                                    |
| ------------------ | -------------------------------------------------------------- |
| ***purchase***     | First-time subscription purchase                               |
| ***renewal***      | Active subscription renewal                                    |
| ***refund***       | Money refund                                                   |
| ***cancellation*** | Cancellation of an active subscription and proportional refund |

### Server response

If the notification is accepted, the response status is ***200***. If the query is incorrect, the response status is ***400***. In case of an internal error, the response status is ***500***.

In case the status is ***400*** or ***500***, the error description will be indicated in the query body as a JSON object:

```json
{
  "title": "Bad request",
  "error": "Not set parameter api-key"
}
```

## Notification types and corresponding fields

1. Available notification types for a trial (all postbacks should be flagged as ‘**`isTrial`** = ***true***’):

* ***purchase*** – trial subscription
* ***cancellation*** – subscription cancellation before the end of that trial

2\. Available notification types for subscription purchase:

* ***purchase*** – subscription purchase
* ***renewal*** – subscription renewal
* ***cancellation*** – premature termination of a subscription and proportional refund
* ***refund*** – money refund

### **Trial purchase**&#x20;

| Field name                  | Description                                  |
| --------------------------- | -------------------------------------------- |
| **`notificationType`**      | Notification type = ***purchase***           |
| **`originalTransactionId`** | ID of the original transaction               |
| **`transactionId`**         | Transaction ID                               |
| **`startDateMs`**           | Trial start date in milliseconds in UTC      |
| **`expiresDateMs`**         | Trial expiration date in milliseconds in UTC |
| **`product`**               | Subscription SKU                             |
| **`productType`**           | Subscription type (line)                     |
| **`isTrial`**               | ***true***                                   |

### **Trial cancellation**&#x20;

| Field name                  | Description                                  |
| --------------------------- | -------------------------------------------- |
| **`notificationType`**      | Notification type = ***cancellation***       |
| **`originalTransactionId`** | ID of the original transaction               |
| **`transactionId`**         | Transaction ID                               |
| **`expiresDateMs`**         | Trial expiration date in milliseconds in UTC |
| **`product`**               | Subscription SKU                             |
| **`productType`**           | Subscription type (line)                     |
| **`isTrial`**               | ***true***                                   |

### **Subscription purchase**

| Field name                  | Description                                         |
| --------------------------- | --------------------------------------------------- |
| **`notificationType`**      | Notification type = ***purchase***                  |
| **`originalTransactionId`** | ID of the original transaction                      |
| **`transactionId`**         | Transaction ID                                      |
| **`startDateMs`**           | Subscription start date in milliseconds in UTC      |
| **`expiresDateMs`**         | Subscription expiration date in milliseconds in UTC |
| **`product`**               | Subscription SKU                                    |
| **`productType`**           | Subscription type (line)                            |
| **`isTrial`**               | ***false***                                         |
| **`price`**                 | Subscription price                                  |
| **`currency`**              | Currency of the subscription payment                |
| **`gracePeriod`**           | Extension of subscription renewal date in days      |

### **Subscription renewal**

| Field name                  | Description                                         |
| --------------------------- | --------------------------------------------------- |
| **`notificationType`**      | Notification type = ***renewal***                   |
| **`originalTransactionId`** | ID of the original transaction                      |
| **`transactionId`**         | Transaction ID                                      |
| **`startDateMs`**           | Subscription start date in milliseconds in UTC      |
| **`expiresDateMs`**         | Subscription expiration date in milliseconds in UTC |
| **`product`**               | Subscription SKU                                    |
| **`productType`**           | Subscription type (line)                            |
| **`isTrial`**               | **`false`**                                         |
| **`price`**                 | Subscription price                                  |
| **`currency`**              | Currency of the subscription payment                |
| **`gracePeriod`**           | Extension of subscription renewal date in days      |

### **Subscription cancellation**

| Field name                  | Description                                         |
| --------------------------- | --------------------------------------------------- |
| **`notificationType`**      | Notification type = ***cancellation***              |
| **`originalTransactionId`** | ID of the original transaction                      |
| **`transactionId`**         | Transaction ID                                      |
| **`expiresDateMs`**         | Subscription expiration date in milliseconds in UTC |
| **`product`**               | Subscription SKU                                    |
| **`productType`**           | Subscription type (line)                            |
| **`isTrial`**               | ***false***                                         |

### **Subscription refund**

| Field name                  | Description                                         |
| --------------------------- | --------------------------------------------------- |
| **`notificationType`**      | Notification type = ***refund***                    |
| **`originalTransactionId`** | ID of the original transaction                      |
| **`transactionId`**         | Transaction ID                                      |
| **`expiresDateMs`**         | Subscription expiration date in milliseconds in UTC |
| **`product`**               | Subscription SKU                                    |
| **`productType`**           | Subscription type (line)                            |
| **`isTrial`**               | ***false***                                         |
| **`price`**                 | The amount of money refunded to the user            |
| **`currency`**              | Currency of the subscription payment                |

## **Query example**

```json
POST https://api.devtodev.com/subscriptions/api?apikey=ak-cDNRQl0Lypq4AOUrx8aGGMnmJT1FSebd
{
   "notificationType":"PURCHASE",
   "transactionId":"transactionId",
   "startDateMs":1640072573468,
   "expiresDateMs":1640245373468,
   "product":"com.demo.bundle.weekly",
   "price":90.9,
   "currency":"RUB",
   "isTrial":false,
   "devtodevId":4064192
}

```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.devtodev.com/integration/server-api/subscription-api.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
