5

I want to get information about all bounties that were active within last 3-4 days. This should include started, awarded and expired bounties. How do I do this?

Here are my thoughts.

  • If a bounty is still active, the corresponding question will be included in /questions/featured endpoint response. Then from the bounty_user, bounty_amount and bounty_closes_date fields of answer type I can figure who, when and how much offered as a bounty.
  • If a bounty has been awarded, the corresponding answer and question will have last_activity_date updated. Therefore, I can look through all recently active answers in the /answers endpoint.
    • bounty_user, bounty_amount will tell me who and how much is offered
    • by inspecting /users/{ids}/reputation-history for the bounty starter and answer owner, I can get timestamps for when bounty was started and ended.
  • If a bounty has expired, I would still expect the corresponding question appear in recently updated questions. However, there wouldn't be any record of an expired bounty.
    • For expired bounties started by the question author, I might check /users/{ids}/reputation-history and see when and how much they allocated for this question.
    • For expired bounties started not by question author, I don't know what to do.

For example, this timeline shows that two bounties started, and both expired without a winner. The first bounty was started by the question author, the second bounty was started by a passer-by 1.5 years later. However, the API question timeline type does not include the "bounty_started" or "bounty_ended" event types, and indeed those are omitted from the API timeline response.

3
  • Very related, but focused on something else so not sure it can be considered as duplicate. Commented Apr 2 at 7:05
  • @ShadowWizardLoveZelda Thanks, I saw it. The question you linked asks about getting this information from SEDE and data dump, which is possible and quite straightforward using the Votes table from SEDE/dump. I am asking about getting the bounty information from the API, which is very different, because there no /votes endpoint in API. So this is not a duplicate.
    – avm23
    Commented Apr 2 at 11:25
  • Well it's also tagged api and if the info exists in SEDE, it means it's public and should be available in the API as well. But yes, no dupe. Commented Apr 2 at 12:18

1 Answer 1

5

For expired bounties started not by question author, I don't know what to do.

You basically can't, or at least not without keeping track of formerly featured questions. This is caused by the fact that an expiring bounty and removing of the post notice does not update the questions last_activity_date. That makes searching for these questions impossible.

What you can do is:

  • fetch all featured questions
  • store their ids in a local datastore
  • each hour1 fetch all featured questions again
  • compare new ids with stored ids, mark those that are no longer featured
  • for each id that is no longer featured call Posts/{ids}/revisions
  • filter the items on revision_type = 'vote_based'
  • filter the items on comment starts-with '<b>Bounty Ended</b>'
  • parse the comment to obtain the reason the Bounty was ended
  • apply your other logic based on the reason.

Here is a code snippet that shows how you use the post/{ids}/revisions endpoint and handle its results.

const id = 4336045
const url = `https://api.stackexchange.com/2.3/posts/${id}/revisions?site=math&filter=!LIFDFz6ISS87ryfi9LAgrC`
fetch(url)
   .then( resp => resp.json())
   .then( data => data.items)
   .then( items => items.filter( i => i.revision_type === 'vote_based'))
   .then( items => items.filter( i => i.comment.indexOf('<b>Bounty Ended</b>') !== -1))
   .then( items => items[0])
   .then( item => { 
      const last = item.comment.indexOf('</b>')
      console.log(item.comment.substring(last+4))
    });


1. I don't think it makes sense to run this more often. Removing expired notices/bounties is on a scheduled batch program on the SE end of things. Maybe if it gets confirmed it runs every 5 minutes you can pull more often.
1
  • Thanks also for suggesting posts/{ids}/revisions, which I can use instead of /users/{ids}/reputation-history for getting timestamps, usernames and bounty amounts.
    – avm23
    Commented Apr 3 at 17:30

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .