Skip to main content

Webhooks

Track GamePush events via Webhooks.

You will need to receive notifications on your server, for example, when processing payments. We will notify you when a player makes a payment so that you can process the purchase and award the player.

Add Webhook

First, you need to add a secret key to verify the authenticity of notification data.

  1. Go to Project > Public Zone
  2. In the Secret Key field, click "Create Key".

Now create a Webhook:

  1. Go to Project > Trusted Sites > Webhooks
  2. In the Webhooks section, create a Webhook.
    • Specify the link that will receive requests from our server.
    • If you need to track test requests, check the "Dev" box.
    • Through the "Notification Settings" button, select the notifications you need us to send.
    • Add the Webhook.

Concept

info

The webhook is sent via http protocol using the POST method in Base64 format, containing JSON.

For every player action marked by you, we send data to your server in Base64 format containing JSON, for example:

{
"event": "GivePlayerReward",
"player": {
"id": 1820283,
"name": "",
"avatar": "",
"projectId": 4,
"credentials": "",
"platformType": "NONE",
"active": true,
"removed": false,
"test": false,
"modifiedAt": "2024-04-26T11:34:23.415923998Z"
},
"result": {
"__typename": "PlayerReward",
"countAccepted": 0,
"countTotal": 1,
"rewardId": 685
},
"time": "2024-04-26T11:34:23.415923998Z"
}

Payload fields:

  • event - event type.
  • player - the player on whose behalf the request was made.
  • result - operation result. Unlike the API, we do not notify on error. A successful action result always comes.
  • time - time of the operation.

All result types are available in introspection. All hooks return the same operation result as the API response. To view the schema or work in a sandbox, use the Chrome extension - Altair GraphQL Client.

API is available at

https://api.gamepush.com/gs/api/graphql

Getting the Result

The result comes in Base64 with a signature separated by ., for example:

eyJ2YWx1ZSI6ICJzb21lIHJlYWwgZGF0YSJ9.cmVhbHNlY3JldGtleQ==

The first part is the request data, the second part is the signature.

Example of extracting data in JavaScript:

const body = 'eyJ2YWx1ZSI6ICJzb21lIHJlYWwgZGF0YSJ9.cmVhbHNlY3JldGtleQ==';
const [base64payload, signature] = body.split('.');
const payload = JSON.parse(atob(base64payload));
console.log(payload.event);

Signature Verification

Make sure the request was made specifically from our server. You will need the secret key you created earlier.

To verify the signature, compare your SHA256 hash with what came in the hook.

The SHA256 signature is formed from the string:

base64payload_secretKey
  • base64payload - the first part of the request before .;
  • secretKey - your secret token created specifically for the project.

Example of signature verification in JavaScript:

// Import library for creating signatures
import crypto from 'crypto';
// Your project's secret key
const secretKey = 'Be$T_Pr0jeCt';

// Data of the request sent by the GamePush server
const body = 'eyJ2YWx1ZSI6ICJzb21lIHJlYWwgZGF0YSJ9.cmVhbHNlY3JldGtleQ==';
// Get payload and signature from the body
const [base64payload, signature] = body.split('.');

// Prepare data for signing
const signData = `${base64payload}_${secretKey}`;
// Create signature
const hash = crypto.createHash('sha256').update(signData);
// Compare the signature
if (hash !== signature) {
// Someone is being tricky
res.status(400);
res.send('Bad request');
return;
}

// Get data and continue working
const payload = JSON.parse(atob(base64payload));
console.log(payload.event);

Events

Event TypeDescription
PurchasePlayerPurchasePlayer made a purchase / subscribed
ConsumePlayerPurchasePlayer consumed purchase
UnsubscribePlayerSubscriptionPlayer unsubscribed from subscription
ResumePlayerSubscriptionPlayer resumed subscription
ExpirePlayerSubscriptionPlayer's subscription expired
UnlockPlayerAchievementPlayer unlocked an achievement
PlayerSetAchievementProgressPlayer set achievement progress
PlayerPublishRecordPlayer published a record
SyncPlayerPlayer synchronized progress
GetPlayerPlayer loaded progress
GivePlayerRewardPlayer rewarded
PlayerSendInviteToChannelPlayer sent an invitation to a channel
PlayerCancelInviteToChannelPlayer canceled an invitation to a channel
PlayerAcceptInviteToChannelPlayer accepted an invitation to a channel
PlayerRejectInviteToChannelPlayer rejected an invitation to a channel
PlayerJoinChannelPlayer joined a channel
PlayerLeaveChannelPlayer left a channel
PlayerCancelJoinChannelPlayer canceled a join request to a channel
PlayerAcceptJoinRequestToChannelPlayer accepted a join request to a channel
PlayerRejectJoinRequestToChannelPlayer rejected a join request to a channel
PlayerKickFromChannelPlayer kicked another player from a channel
PlayerSendPersonalMessagePlayer sent a personal message
PlayerSendFeedMessagePlayer sent a message to a channel
PlayerSendMessagePlayer sent a message
PlayerEditMessagePlayer edited a message
PlayerDeleteMessagePlayer deleted a message
PlayerMutePlayerInChannelPlayer muted in a channel
PlayerUnmutePlayerInChannelPlayer unmuted in a channel
PlayerCreateChannelPlayer created a channel
PlayerUpdateChannelPlayer updated a channel
PlayerDeleteChannelPlayer deleted a channel
UploadPlayerFilePlayer uploaded a file
UploadPlayerImagePlayer uploaded an image

Stay in Touch

Other documents of this chapter available Here. To get started, welcome to the Tutorials chapter.

GamePush Community Telegram: @gs_community.

For your suggestions e-mail: [email protected]

We Wish you Success!