stackexchange-apidataexplorer

How to get the id of the question or answer linked to a specific badge award?


I can get the badge id for a specific user, for example query:

Select *
From Badges
Where UserId = 10907521

Example badge id from result

30884218

But, how is it possible to get the associated question or answer id (if applicable) for every badge awarded to a user?
For those badges which are not related to a Q&A, we could expect an "NA".


Solution

  • Badge awards and posts are not linked in SEDE; that information is not available in the Data Explorer.

    You could get it from the API, though it ain't pretty.
    Reference the:

    For example, fetching:

        /users/10907521/timeline?pagesize=100&site=stackoverflow

    returns results like:

    {
      "badge_id": 10,
      "post_id": 54438094,
      "user_id": 10907521,
      "timeline_type": "badge",
      "post_type": "question",
      "creation_date": 1548848111,
      "detail": "Scholar",
      "title": "Execute a command and save the results into a df from a loop"
    }
    

    once you filter/search for badge_id in the results