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

I have a crazy idea, it happens that in WooCommerce I am using a virtual wallet (based on points) which I would like to synchronize with the gamification points of Discourse… but I feel that only a API is very heavy (be consulting every x cron or when user hace action in WC)… you could create a webhook so that the virtual wallet in WooCommerce is updated with the points obtained in discourse?.. I attach a guide schema

I know it can be more complex than it seems, especially since the Discourse API is relatively new (and there’s no webhook either), but I only present a use case, validate the idea

Gamification recalculates every 5 minutes, so I think using a crontab style sync is quite appropriate.

1 Like

Oh, I hadn’t thought of that approach… ie I can use n8n (own hosting to reduce costs); I’ll create a cron trigger every 5 or maybe 10 minutes querying the Discourse API for new points (How would I go about querying all users? Or would you do it for events?)… Although, of course, there will be a constant little time window where you won’t see the score synced across both platforms…

I was thinking about it, and I think that if a webhook could be created for the gamification plugin sending the information by events (without having to consult via API) this would avoid having to consult, for example, if there are 200 active users, 200 times a API every 5 minutes (also by default Discourse allows webhooks)…it’s important because Discourse is the main source of points (and updates more constantly) and this would be an update that allows background sync. instantly according to the changes in Discourse…

@Falco
plan to add an API to delete events ? thanks.

1 Like

I want to add it, but it’s not planned yet. At the moment you can update it’s value to 0.

2 Likes

thanks @Falco
guess for an event, the ID could get a negative point, right ?
say, if lose in an competition event

1 Like

Yes, you can award negative scores too. It’s useful for doing events like exchanging points for gifts, applying penalties, etc.

1 Like

Late to the party here - Is there a way that certain point transactions could be earmarked so they don’t count as ‘spends’ toward leaderboard rank? Would want other true negative points to count toward leaderboard (votes/flags against, api events as suggested above for ‘losing’ a ladder event, etc).
eg.

  • accumulate 10k points through activities, be in the lead. Yay!
  • Spend 10k points on fancy swag, be at ‘spendable’ 0 points as a query would sum 10k - 10k.
    • but should still be on the top of the leaderboard.
  • Lose 2k points in a ladder game, display on leaderboard at 8k. Lose the lead…Spendable balance negative 2k.

hey @Falco
after editing the point of an event, will it re-calculate the overall point for an ID ?
seems not. is this expected ?

That’s what the warning in the OP covers. Since we cache the total score everywhere in the UI, after your edit it will only reflect after a cache update. For recent events the cache updates automatically, but for events that happened over 10 days ago, you will need to trigger a score update for the period.

2 Likes

7 posts were split to a new topic: Add bulk_create to Gamification external event API

Do we have the ability to constrain the API Key’s scope to just the Gamification plugin?

Not seeing an option in our API Key Admin view to constrain the key to ...admin/plugins/gamification/score_events

And our leadership is skeptical that we need a truly Global API Key for this.

I suspect you’re right. It seems that more scopes get added as they are asked for. You could with a custom plugin if you’re self hosted. You could submit a PR and or post as a Feature request. If you’re an enterprise customer you could have your leadership ask. :wink:

Hmm. Now I wonder about adding a custom api scope in a plugin is possible (especially having one plugin add an api scope for another plugin). I suspect that it is, but haven’t seen it done.

Maybe just create a user for just the api so at least you’d be able to track it that way.