2

I want to create a slack integration that will list the user's Stack Overflow activity. EG: when the user asks a question, posts an answer, edits a post etc.

What can I use for this kind of notification?

1

2 Answers 2

3

This is what the /users/{ids}/timeline route is for.

It returns an ordered list of these kinds of timeline events:

  • accepted
  • answered
  • asked
  • badge
  • commented
  • reviewed
  • revision
  • suggested

Here is what your timeline currently looks like:

"items": [ {
    "badge_id": 2,
    "post_id": 7113,
    "user_id": 43099,
    "timeline_type": "badge",
    "post_type": "question",
    "creation_date": 1478279530,
    "detail": "Student",
    "title": "How to get notified when user ask a question or post an answer?"
  }, {
    "post_id": 7113,
    "user_id": 43099,
    "timeline_type": "asked",
    "post_type": "question",
    "creation_date": 1478266565,
    "title": "How to get notified when user ask a question or post an answer?"
  }, {
    "badge_id": 9,
    "user_id": 43099,
    "timeline_type": "badge",
    "creation_date": 1478264868,
    "detail": "Autobiographer"
  }
] ...

I recommend polling the route no more than once every 65 seconds, and judiciously using the fromdate parameter (which is really a unix epoch time parameter).

1
  • there's no such thing as github webhooks for this and other interesting events? I would like to receive an hook on new questions for a specific tag Dec 26, 2016 at 14:12
1

If you're more looking for events that happened, like posting/edit an answer or question, posting a comment or a new user that got created, use the /events endpoint.

It does require that you authenticate, so you can't run this as an anonymous user, you have to register an application and have one of the OAuth flows implemented.

When you call the /events endpoint you get the following JSON:

{
  "items": [
    {
      "creation_date": 1512992823,
      "event_id": 47752262,
      "event_type": "question_posted",
      "link": "https://stackoverflow.com/questions/47752262/nointerfacefoundtext-webcam-js"
    },
    {
      "creation_date": 1512992822,
      "event_id": 82464767,
      "event_type": "comment_posted",
      "link": "https://stackoverflow.com/questions/47750306/kafka-topic-creation-using-java-api-without-zookeeper/47751185#comment82464767_47751185"
    },
    {
      "creation_date": 1512992822,
      "event_id": 17416351,
      "event_type": "post_edited",
      "link": "https://stackoverflow.com/questions/17416351/difference-between-prelude-and-yesod-with-mongodb"
    },
    {
      "creation_date": 1512992821,
      "event_id": 47752261,
      "event_type": "answer_posted",
      "link": "https://stackoverflow.com/questions/47750098/count-user-within-15-min-and-15-to-30-min-sql-query/47752261#47752261"
    },
    {
      "creation_date": 1512992815,
      "event_id": 9083513,
      "event_type": "user_created",
      "link": "https://stackoverflow.com/users/9083513/yamini-lakshmi-menni"
    },
    ....
    ]
}

Notice the event_type that indicates what you're dealing with. The event_id is the unique id for the object of the event. So for a question_posted the event_id will be the id of the question, for comment_posted, the event_id will be the id of the comment. You can fed those id's in the other API endpoints to get more details. The event itself can deliver an excerpt but that is about it.

To convert this in a "webhook" you have to keep track of the last time you called events and then call it with the since parameter set. As you can make 10,000 calls per day this should allow for an events call just under every 10 seconds but it is advised to limit the number of calls. There is 15 minutes worth of events kept and you can access only 5 minutes of events. The call supports paging.

You must log in to answer this question.

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