Rewards Webhook

Send the reward outputs like points, merchandise, cashbacks, coupons to your servers

A webhook url can be provided to CustomerGlu to receive the rewards won by users in real-time

A POST request will be made to the specified Webhook URL . Example request body is as follows

{
"userId":"xyz",
"type":"customReward",
"rewardId":"abc",
"rewardName":"Merchandise:T-shirt",
"details":{
"size":"L"
}
}

Optionally, to verify the authenticity of request, a secret token can be provided to CustomerGlu.

When you set a token, you'll receive the X-CG-SIGNATURE header in the webhook POST request. value of this header will be a hmac hexdigest of the request body with the provided token. See on how to validate the requests

Validating Reward Webhook

JavaScript
Python
JavaScript
const verifySignature = (reqBodyDigest, cgHeader) => {
return crypto.timingSafeEqual(Buffer.from(cgHeader), Buffer.from(`${reqBodyDigest}`));
}
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
app.post('/hook', (req, res) => {
const jsonString = JSON.stringify(req.body);
const reqBodyDigest = crypto.createHmac('sha1', token)
.update(jsonString)
.digest('hex');
const cgHeader = req.headers['x-cg-signature'];
const verify = verifySignature(reqBodyDigest, cgHeader)
}
Python
import hmac,hashlib,json
sampleObj = {"campaignId":"6bab1116-ae8e-4644-9cee-7a3d8ee9aff3","type":"direct","userId":"test-8-june-9","rewardId":"acdc71c6-08ad-4cd9-8c1e-3c812487b854","rewardName":"$15","rewardAmount":15,"details":{"currency":"USD","value":15,"reward_reason":"got_referred","userAName":"Test Solve 7","userAId":"test-8-june-7"}}
gluHeader="f2719895b483fbf3f98e1936bc88271cbe74f138"
def generateSignature(incomingBody):
key="PbTJp694bmgrfJpJPQmrjGfjgq".encode('utf-8')
incomingBodyString = json.dumps(incomingBody, separators=(',', ':')).encode('utf-8')
return hmac.new(key, incomingBodyString, hashlib.sha1).hexdigest()
def verifySignature(cgHeader,incomingBody):
return hmac.compare_digest(cgHeader,generateSignature(incomingBody))