Importing Google Play purchase payloads

This tutorial describes how to import Google Play purchases into ChartMogul.

Google Play does not directly notify ChartMogul of new purchases, nor does it list all past purchases. For this reason, we rely on you, the mobile app developer, to import in-app purchases into ChartMogul. This tutorial describes how you can do that.


Connect your Google Play account to ChartMogul first

Before starting this tutorial, you must have connected your Google Play account with your ChartMogul account. Follow our help centre article to get that setup.

1. The Payloads URL

The Payloads URL is an endpoint uniquely generated for each Google Play data source. This endpoint accepts in-app purchase data and customer data from you, the mobile app developer.

Payload URLs contain the data source UUID in them and are of the following format,{{DATA_SOURCE_UUID}}/purchases

2. Authentication

Create a new API key.

3. Submitting payloads

The Payloads URL accepts payloads with purchase data and customer data. This allows you as the mobile developer to include customer specific identifiers and metadata. This information will significantly improve the value you get out of ChartMogul's segmentation features.

curl -X POST "" \
     -H 'Content-Type: application/json' \
     -u YOUR_API_KEY: \
     -d '{
     "purchase_data": {
        "product_id": "monthly_basic",
        "purchase_token": "oagjjjfmhmagjafhjkhlnijd.AO-J1Oy4f45RuaZIodr1s4nKPvkD1gxXNJfmmLoADyuAHZcqJHUZMm5AZiNIO6sPfaxI6LT9tFoCvE0OLpTMe2iHzoMirYW_UG4d9A4lz2-vzCOWOqFZzQWtP3FfCVpp6cNNIcK9_j0x"
      "customer": {
        "external_id": "customer_001",
        "name": "Adam Smith",
        "email": "[email protected]",
        "company": "Acme Inc.",
        "country": "US",
        "state": "CA",
        "city": "San Jose",
        "zip": "95037",
        "lead_created_at": "2019-01-01 16:59:00",
        "trial_started_at": "2019-01-11 10:00:00",
        "attributes": {
            "tags": ["OnePlus", "multi_device"],
            "custom": [
                "type": "String",
                "key": "marketing_campaign",
                "value": "Facebook ads",
                "source": "Internal DB"
HTTP status `202 - Accepted`

    "message": "payload accepted for processing"

The payload JSON object parameters are as follows,

  1. purchase_data - Mandatory - JSON Object - A JSON object containing the following,
  • product_id - Mandatory - The productId for the product that was purchased. This is also called the subscriptionId or the sku in Google Play's In-App Billing and Developer APIs.
  • purchase_token - Mandatory - The purchaseToken returned by Google Play as soon as a purchase is completed. This is usually returned within the INAPP_PURCHASE_DATA object in the getBuyIntent() method.
  1. customer - Optional but recommended - JSON object containing customer information. The body parameters are the same as those for the Create a Customer endpoint, minus the data_source_uuid.


What you need to know:

  • If you haven't historically saved purchase tokens in your server, these tokens are visible for each order in the Order Management section of the Google Play console.
  • We highly recommend that you send us purchase tokens in chronological order of purchase time. This will ensure that any upgrades, downgrades or re-activations are correctly linked up and reported in ChartMogul.
  • We also recommend that you send us purchase tokens as soon as you receive them on your servers, to ensure that ChartMogul's reports are as real-time as possible.
  • We also highly recommend including at least the unique external_id of the subscriber in the payloads, even if you do not include other subscriber attributes. This will help ChartMogul report all in-app subscriptions purchased by the same subscriber under a single customer.
  • If you cannot specify external_id, ChartMogul will generate an anonymous subscriber for each purchase_token that is not linked to another purchase token, and will set the customer external ID to the purchase token.
  • If you import a purchase token for an upgrade/downgrade/reactivation, ChartMogul will be able to link it to a previously imported purchase_token by using the linkedPurchaseToken property in Google Developer APIs.
  • ChartMogul generates its own subscription external IDs in order to track upgrades/downgrades/reactivations as accurately as possible.
  • Customer custom attributes with Type: String have a limit of 255 characters. Anything above the 255 character limit will be truncated.