Is there an API to retrieve additional leaderboard info?

Is there any way to retrieve info from created leaderboards (either on client or server)? Like expiring date, sort, operator…

Also… is it posible to list a list containing all created leaderboards? (creating a leaderboard that already exists doesnt’ reset it and there is no way to know if that leaderboard was already available or not)


This isn’t currently possible. At the moment leaderboards are treated more as a “configuration” element, and since they can only be created programatically by the developer it’s expected you’ll have a set of them pre-configured. The risk of accidentally changing the sort/reset/etc isn’t expected to be high.

That said it might be useful to get/list leaderboards by ID, so please open an issue so we can track the request.

Hy zyro
I actually managed to get a lot of info by querying the database on the server directly and returning all that info to the client in json format. Here is a quick snippet if someone else is interested

type LeaderBoardInfo struct {
	Id             string
	Authoritative  bool
	Sort_Order     int
	Operator       int
	Reset_schedule string
	Metadata       string
	Create_time    string

func ListLeaderboardsRPC(ctx context.Context, logger runtime.Logger, db *sql.DB, nk runtime.NakamaModule, payload string) (string, error) {
	if rows, err := db.QueryContext(ctx, "SELECT id, authoritative, sort_order, operator, reset_schedule, metadata, create_time FROM leaderboard"); err != nil {
		return "error accessing db", err
	} else {
		defer rows.Close()

		var infos []LeaderBoardInfo
		for rows.Next() {
			var info LeaderBoardInfo
			if err := rows.Scan(&info.Id, &info.Authoritative, &info.Sort_Order, &info.Operator, &info.Reset_schedule, &info.Metadata, &info.Create_time); err != nil {
			logger.Info("Leaderboard %v", info)
			infos = append(infos, info)
		var ret, _ = json.Marshal(infos)
		return string(ret), nil

That looks good, glad it works for your use case! Just keep in mind that it’s returning every leaderboard you have configured so the response could grow quite large.

1 Like

@Zal0 Nice code. We’ve made the low level database driver available to enable you to fill in gaps where our APIs don’t cover all the functionality developers need for projects yet. It would be great if you could open an issue anyway because I think it’d be useful to provide official runtime functions for this logic.

I noticed in your code that you call log.Fatal(err) which you might want to avoid because it will stop the server if the error occurs. I would log it and return an error but just fail the request.

Chiming in here. I made an account to request this feature.

I think nakama should have an api for returning a leaderboard by ID. The reset schedule is actually what I am looking for. Specifying the reset schedule in CRON format and then having to configure that logic across our Nakama deployment and our client is not simple. If Nakama would just return the leaderboard info, or even return the next expiry, that would be useful. Currently we are duplicating the leaderboard reset logic in both the nakama configuration and the client, with no enforced connection between the two. I worry about these becoming desynced and having the client not know when the leaderboards will reset.

@00jknight Sounds like a good suggestion. I see you’ve opened a feature request for it already :+1: