TABLE OF CONTENTS
ADMIN PRIVILEGES REQUIRED
Overview
One of the key benefits of Stack Internal Community is its ability to break down "silos" and help your company's departments and locations share information. The Stack Internal Community application programming interface (API) can help you build reports quantifying how your various departments are sharing information.
By using Stack Internal Community for reporting purposes, you can:
- Use API v3 calls to get data on questions, answers, and their authors.
- Use your company HR data or API to decorate the users with segmentation data.
- Use your favorite data wrangling or data engineering methods to merge the data in beneficial ways.
- Prepare impactful data visualizations that will show your key stakeholders how Stack Internal Community is benefitting your business.
Use API calls to pull data on users, questions and answers
The graphic below shows the relationship of the data inside Stack Internal Community's Q&A model:
While the API makes all of these elements available, we recommend starting with a small subset of the data. From there, you can build the size and complexity of your reports based on business needs. For this article, we'll start with the basis of collaboration: users helping each other by asking and answering questions.
Set up API access
The Stack Internal Community API v3 article explains how to authorize the interactive API documentation and make your first request. Use a personal access token (PAT) scoped to the Team you want to report on. For an automated report, create your own read-only PAT as described in Personal Access Tokens (PATs) for API Authentication. Send it in an Authorization: Bearer [your_PAT] header, and include a descriptive User-Agent header with each request.
Build API calls
You can use the API v3 interactive documentation to create and test your API calls.
- Go to the interactive documentation and click Authorize. Keep access_team selected, then authorize access to the Team you want to report on. You do not need write access for this report.
- Find GET /teams/{team}/questions under Questions, click Try it out, and enter your Team slug. Set
pageto1andpageSizeto100, then click Execute. The response'sitemsarray contains questions, including each question'sid,owner.id(the asker), andanswerCount. - For a question with
answerCountgreater than zero, find GET /teams/{team}/questions/{questionId}/answers under Answers. Enter the same Team slug and the question'sidasquestionId, then click Execute. Each answer initemshas aquestionIdand anowner.id(the answerer).
To build a report for the whole Team, retrieve every page of questions, then every page of answers for each question with answers. Match each answer's questionId to the question's id to pair an asker with an answerer. API v3 returns questions and answers through separate endpoints. Use the Curl or Request URL shown by the interactive documentation as a starting point for your integration. Its authorization token is temporary, so use your own PAT for a recurring report.
The wrapper object
These API v3 list requests return results in a wrapper object. Its items array holds the questions or answers on the current page. The page, pageSize, totalPages, and totalCount fields describe the paginated result. Start with page=1 and increment page until you have requested totalPages, for both the question list and each answer list. Content can change while you paginate, so a report run is not a point-in-time snapshot.
You may want to write your own wrapper around the API results to speed up the API development and reporting process.
Download user information
Your collaboration report will benefit from additional user data, which you can download from your site in CSV format. Navigate to Admin settings, then Users and permissions on your Stack Internal Community site. If Download CSV is available, click it to get a list of users. The CSV includes Name, Email, and User Id columns. Join User Id to the question's owner.id for the asker and the answer's owner.id for the answerer. If CSV export is unavailable, a Team admin can paginate GET /teams/{team}/users and use each active user's id and email fields instead. The API shows other users' email addresses only to admins. Some content may have no available owner; leave those records unmatched rather than assigning them to another user.
Perform data analysis and segmentation
You can use additional data from your company's HR database or API to enhance your report with segmentation data. Join the user CSV to your HR data by email address, for example, then group the asker–answerer pairs by department or location. Decide whether to count every answer or each unique asker–answerer pair, and apply that choice consistently. You can use these data sources to prepare visualizations and/or build custom integrations.
Some ideas for data segregation and reporting:
- Report on asker and answerer departments or locations to show how Stack Internal Community is increasing collaboration across barriers.
- Join Stack Internal Community question and answer data with your HR data to show adoption by department or location.
- Connect the data to your favorite D3.js (Javascript data visualization library) code to show collaboration inside Stack Internal Community.
What you build is up to you. Consult the Stack Internal Community API v3 documentation for guidance and inspiration. Stack Overflow support can only help with questions and errors within the scope of general API usage and connectivity.
d3.js example
A chord diagram offers a unique, visually compelling way to display collaboration between question askers and answerers on your site. Set up correctly, a chord diagram will show bi-directional and proportional flow of interactions aggregated by department or location.
In the example below, the outer band is a colored pie chart showing the proportion of questions asked by department or location. The flow across the diagram shows which department answered the questions. This example shows that the yellow group answered the majority of the blue group's questions.