How to integrate Discourse Gamification with an external system (redeem and award points)

It may be my decade of experience working at banks, but the way I envision redeeming points is issuing negative value custom events.

For example, let’s say you have a user who wants to redeem points for a T-Shirt, and that T-Shirt costs 10k points. The flow on your redeeming system would be:

  1. Check if the user has enough points:

    curl https://meta.discourse.org/u/falco.json -s | jq . | grep score
        "gamification_score": 89386,
    
  2. Issue a “point withdraw” event

    jo -p user_id="13" date="2023-04-14" points="-10000" description="T-Shirt Redeem - order #123" | curl --json @- -XPOST http://example/admin/plugins/gamification/score_events -H "Api-Key: apikeyhere" -H "Api-Username: system"
    

You will want to wrap this in a semaphore of some sorts, as this is the text book example of using those, but that is the gist of the proposed workflow.

This is a very recent feature, so let me know if the proposed workflow doesn’t work correctly.

It’s working fine for me, both in the browser and via API. It’s an admin endpoint, so you need to be a logged in admin via browser, or pass API keys like explained in the OP.

3 Likes