Skip to main content

Coupon Redeemed Webhook

Aghanim offers a coupon redeemed webhook to notify your game when a redeem code for a free item has been used by a player, providing detailed information about the event.

This webhook is activated through the Coupon redeemed event, selectable in Game → Webhooks.

warning

To credit in-game items to player accounts, use the item.add webhook. The coupon redeemed webhook is designed to provide detailed data when item.add is insufficient.

Redeem coupon webhook image
Redeem coupon webhook image

Requirements

To use the redeemed coupon webhook from Aghanim, you should have the webhook server configured as follows:

  • HTTPS endpoint, accepting POST webhook requests.
  • Listen for events, generated and signed by Aghanim.
  • Respond with 2xx status codes to signal successful processing, and 4xx or 5xx for denial or errors.

Configuration

  1. Develop a function for the coupon.redeemed webhook processing.
  2. Make your endpoint available.
  3. Register your endpoint within Aghanim account → GameWebhooksNew Webhook by choosing the corresponding event type.

Alternatively, you can register your endpoint within Aghanim using the Create Webhook API method.

Request schema

Below is an example of an coupon.redeemed webhook request:

POST /your/webhook/uri HTTP/1.1
Content-Type: application/json
Host: your-webhook-endpoint.com
User-Agent: Aghanim/0.1.0
X-Aghanim-Signature: 2e45ed4dede5e09506717490655d2f78e96d4261040ef48cc623a780bda38812
X-Aghanim-Signature-Timestamp: 1725548450

{
"event_type": "coupon.redeemed",
"event_data": {
"player_id": "2D2R-OP3C",
"coupon": {
"code": "WELCOME",
"sku": "crystals",
"redeemed_at": 1725548450
},
"item": {
"id": "itm_exTBZQmIlDz",
"name": "Crystals",
"description": "Reign supreme over your rivals with this massive crystal treasure.",
"sku": "crystals",
"quantity": 480000,
"price": 9499,
"price_decimal": 94.99,
"currency": "USD",
"type": "item",
"nested_items": null
}
},
"event_time": 1725548450,
"event_id": "whevt_eCacGbJVbvToOgzjXUgOCitkQE",
"idempotency_key": "idmpt_aXRlb...JkX2VFS",
"request_id": "d1593e9c-c291-4004-8846-6679c2e5810b",
"sandbox": false,
"trigger": "hub.redeem",
"transaction_id": "whtx_eCacGbJVbvT",
"context": null,
"game_id": "gm_exTAyxPsVwh"
}

The Event schema

KeyTypeDescription
event_idstringUnique Event ID generated by Aghanim.
game_idstringYour game ID in the Aghanim system.
event_typestringThe type of the event, coupon.redeemed in this case.
event_timenumberEvent date in Unix epoch time.
event_dataEventDataContains the event-specific data, with possible keys for inherited objects.
idempotency_keystringEnsures webhook actions are executed only once, even if retried.
request_idstring|nullIf the event was triggered by an API request, the request ID is included.
sandboxbooleanIndicates whether the event was sent from the sandbox game environment.
triggerstring|nullThe trigger that caused the event to be sent.
transaction_idstringThe transaction ID generated by Aghanim. This ID may be the same for multiple events emitted within the same transaction.
contextEventContext|nullContextual information about the event.

The EventContext schema

KeyTypeDescription
orderOrderContext|nullOrder information associated with the event if applicable.
playerPlayerContext|null(Optional) Player information. To add this, enable "Add player context" in the webhook settings.

The EventData schema

KeyTypeDescription
player_idstringThe unique Player ID chosen for player authentication.
couponCouponThe coupon object containing the redeem code data.
itemItemThe item object containing details about the free item provided upon redeeming the code.

The Coupon object

KeyTypeDescription
codestringRedeem code.
skustringFree item SKU provided upon the redeem code usage.
redeemed_atnumberCode usage date in Unix epoch time.

The Trigger values

ValueDescription
hub.redeemWhen a coupon for a free item is redeemed.
testWhen using the "Send test event" in the Dashboard.

The Item schema

KeyTypeDescription
idstringItem ID generated by Aghanim.
namestringItem name.
descriptionstring|nullItem description.
skustringItem SKU matching on both the game and Aghanim sides.
quantitynumberItem quantity.
typestringThe type of item. Possible values: item, bundle.
nested_itemsNestedItem[]|nullAn array of items included in the bundle.
fallback_itemItem|nullThe item that may be given as fallback if the main item can't be given to the player.

Item type bundle can contain several nested items inside.
You can handle the common sku of the bundle or handle each nested item individually.

The NestedItem schema

KeyTypeDescription
idstringItem ID generated by Aghanim.
namestringItem name.
descriptionstring|nullItem description.
skustringItem SKU matching on both the game and Aghanim sides.
quantitynumberItem quantity.
typestringThe type of item. Possible values: item, bundle.
nested_itemsNestedItem[]|nullAn array of items included in the bundle.

Need help?
Contact our integration team at integration@aghanim.com