How to get unread notification / topic count via API?

I managed to do this by using two API endpoints and some backend magic. My first implementation fetches number of unread topics, number of unread notifications and number of unread private messages and then combines these numbers with some simple logic to yield a one meaningful number to show the user on the main site.

I use the following query for fetching the number of unread topics:
/unread.json?api_key=%s&api_username=%s

and this for unread notifications and private messages:
/session/current.json?api_key=%s&api_username=%s.

There might be a better way but this works for me now.

I then cache these values and refresh when needed. I also changed the forum link on the main site navigation to a simple redirect function that marks the notifications read and clears the cache every time user navigates to the forum from the main site. This is was the simplest brute force way that I came up with to easily clear the notifications. (If the user doesn’t actually reset the notifications on the forum, they will be updated again on next page load on the main site.)

Here’s my actual Django code for that view:

def backstage_redirect(request):
    if request.user.is_authenticated():
        try:
            profile = request.user.userprofile
            profile.refresh_backstage_notifications(mark_as_read=True)
        except Exception:
            pass

    return HttpResponseRedirect('https://backstage.slipmat.io')

There is lots of improvements to do here, but for now, this works for me as first implementation. Thanks everyone for really swift and helpful advice!