Since we launched Discourse Gamification a year ago, one of the most requested features from our roadmap has been the ability to make it possible to integrate Discourse Gamification with external gamification system . Examples are plenty:
-
Integrate with existing gamification programs in companies
-
ability to award points for events that happen outside of Discourse, like IRL events, or elsewhere online, like being a customer in a community, or buying a product.
-
the ability to allow users to redeem their points for swag, products or benefits
Today, just in time for the plugin’s first anniversary, we made all of the above possible with a full API to handle custom scoring events
.
This new system allows admins to:
-
Award users a custom score event
-
Award users with negative score events, to accommodate redeem or penalties events
-
Update and list custom events previously created
API
Points awarded via API will take up to 1 hour to reflect on a user’s overall score for events created with the current date, and up to 24 hours for events created in the last 10 days. For events created with a date older than 10 days, you can use the Recalculate Scores button in the admin gamification UI, or run the backfill rake task:
rake gamification_scores:backfill_scores_from[YYYY-MM-DD].
There are 3 different API endpoints currently.
List Events
Returns up to 100 events. You can filter by id, user_id, and/or date.
curl https://<example_url>/admin/plugins/gamification/score_events.json \
-H 'API-Key: <api_key_here>' \
-H 'API-Username: <api_username_here>'
You can also list specific user or date events:
curl https://<example_url>/admin/plugins/gamification/score_events.json?user_id=1&date=2023-05-01 \
-H 'API-Key: <api_key_here>' \
-H 'API-Username: <api_username_here>'
Create Event
curl -X POST https://<example_url>/admin/plugins/gamification/score_events.json \
-H 'API-Key: <api_key_here>' \
-H 'API-Username: <api_username_here>' \
-H "Content-Type: application/json" \
-d '{
"user_id": 13,
"date": "2023-04-14",
"points": 15,
"description": "May 2023 Karaoke attendee"
}'
Alternate syntax using jo:
jo -p user_id="13" date="2023-04-14" points="15" description="May 2023 Karaoke atendee" | curl --json @- -XPOST http://example/admin/plugins/gamification/score_events -H "Api-Key: apikeyhere" -H "Api-Username: system"
Update Event
The update endpoint requires id and points. You can optionally update description. Note that user_id and date cannot be changed after creation.
curl -L -X PUT https://<example_url>/admin/plugins/gamification/score_events.json \
-H 'API-Key: <api_key_here>' \
-H 'API-Username: <api_username_here>' \
-H "Content-Type: application/json" \
-d '{
"id": 6,
"points": 25,
"description": "May 2023 keynote attendee"
}'
Alternate syntax using jo:
jo -p id="11" points="25" description="May 2023 Karaoke attendee" | curl --json @- -XPUT http://example/admin/plugins/gamification/score_events -H "Api-Key: apikeyhere" -H "Api-Username: system"
Last edited by @MarkDoerr 2025-12-03T01:34:43Z
Last checked by @MarkDoerr 2025-12-19T22:30:29Z
Check document
Perform check on document:
