5

I'm doing some data analysis on Stack Overflow questions, and I would like to figure out if a bounty was offered on a question or not. Is there a way to look at a question and figure this out? Is there an API on Stack Overflow that allows this?

Note: I'm not talking about currently active bounties.

For example, I had offered a bounty on my question in the past -> Streaming video from Camera to Samsung Smart TV, but now when I look at it, I see no traces of a past bounty.

1

3 Answers 3

4

While the answer from zcoop98 leverages the API, for data analysis of larger sets the Stack Exchange Data Explorer might be a viable alternative.

This query for example answers your specific question:

select votes.postid [Post Link]
     , userid [User Link]
     , votes.creationdate [Bounty started] 
     , votes.bountyamount
     , postnotices.creationdate [Notice added]
     , postnoticetypes.Name
     , postnotices.body
from votes
inner join postnotices on votes.postid = postnotices.postid
inner join postnoticetypes on postnoticetypes.id = postnotices.postnoticetypeid
where postnotices.postid = ##questionid##
and votetypeid = 8 -- bounty added

Which gives us:

enter image description here

From here you can adapt to include more questions.

SEDE is refreshed once a week on Sunday.

3

It's not the most intuitive, and could certainly be more streamlined, but you can use the API to determine if a given question has ever been bountied, all you need to do is to pull the revision history for that post (not, as one might assume, the post timeline).

The API endpoint for this is /posts/{ids}/revisions, where {ids} can be 1 to 100 semicolon delineated post IDs.

Using the post in question as an example, we'll send a GET request to:
https://api.stackexchange.com/2.3/posts/16729114/revisions?site=stackoverflow, which returns us a response containing an array of revision-type objects, sorted by creation date (most recent first), wrapped in the standard SE API response wrapper.

Unfortunately, there isn't a single "isBounty" field or similar to help us identify bounty revisions in the list, so we have to resort to parsing the comment field for this information (a string representation of the HTML used for the bounty notice in the post's revisions list).

Thankfully, the comment string of all bounties appears to take the same format:

<b>Bounty Started</b> worth <span class=\"s-badge s-badge__bounty s-badge__sm\">{bounty_amount}</span> reputation by <a href=\"{user_url}\">{user_display_name}</a>

Given this, we can simply check whether the comment exists and starts with <b>Bounty Started</b> to tell if the given revision notice belongs to a bounty.

If the response contains at least one such entry, then the post has had at least one bounty in its history.

Snippet example below:

new Vue({
  el: '#app',
  data() {
    return {
      ids: '16729114',
      pulled: false,
      loading: false,
      bounties: [],
    };
  },
  methods: {
    async pullRevs() {
      this.bounties = [];
      this.pulled = false;
      this.loading = true;

      await this.$nextTick();

      let response = await (await fetch(`https://api.stackexchange.com/2.3/posts/${this.ids}/revisions?key=U4DMV*8nvpm3EOpvf69Rxw((&site=stackoverflow`)).json();
      for (revision of response.items) {
        if (revision.comment && revision.comment.startsWith('<b>Bounty Started</b>'))
          this.bounties.push(revision.creation_date);
      }
      this.pulled = true;
      this.loading = false;
    },
    getDate(timestamp) {
      return new Date(timestamp * 1000).toString();
    },
  },
});
<script src="https://unpkg.com/vue@2/dist/vue.min.js"></script>

<div id="app">
  <h2>Has post been bountied?</h2>
  <p>(eg. 16729114, 26217076, 69770733, etc.)</p>
  <input placeholder="Post ID" v-model="ids" type="number">
  <button :disabled="ids.length == 0" @click="pullRevs">Go!</button>
  <div v-if="loading">
    <p>Loading...</p>
  </div>
  <template v-else>
  <div v-if="pulled && bounties.length">
    <h3>Yes!</h3>
    <h4>{{ bounties.length + ' time' + (bounties.length > 1 ? 's' : '') + ':'}}</h4>
    <ul>
      <li v-for="bountyTime in bounties" :key="bountyTime">{{ getDate(bountyTime) }}</li>
    </ul>
  </div>
  <div v-if="pulled && !bounties.length">
    <h3>No.</h3>
  </div>
  </template>
</div>

0

You can have a look at the timeline of the post.

enter image description here

You will see a table containing the history of the post, and the row that has the "bounty started" (and "notice added") is when the bounty was placed.

enter image description here

3
  • 1
    This question is about how to do so via the API.
    – Ryan M Mod
    Commented Oct 28, 2021 at 13:04
  • @RyanM Although the question includes "Is there an API on Stack Overflow that allows this?", it didn't say specifically that it must be done via API. Note the "For example, I had offered a bounty on my question in the past, but now when I look at it, I see no traces of a past bounty." in the OP's post.
    – Red
    Commented Oct 28, 2021 at 13:06
  • 1
    It's also tagged api, which is for "The Stack Exchange application programming interfaces (the “API Services”) are a set of programming interfaces which can query and connect to Stack Overflow and other sites in the Stack Exchange Network."
    – Ryan M Mod
    Commented Oct 28, 2021 at 13:06

You must log in to answer this question.

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