@@ -5,7 +5,7 @@ description: Get up and running with the Stack Overflow SDK in under 5 minutes.
55import { Tabs , TabItem } from ' @astrojs/starlight/components' ;
66import { Card , CardGrid } from ' @astrojs/starlight/components' ;
77
8- Get your Stack Overflow integration running in minutes with our JavaScript SDK. This quickstart covers installation, initialization, and making your first API calls.
8+ Get your Stack Overflow integration running in minutes with our JavaScript SDK. This quickstart covers installation, authentication setup, initialization, and making your first API calls.
99
1010## Installation
1111
@@ -27,39 +27,54 @@ Get your Stack Overflow integration running in minutes with our JavaScript SDK.
2727 </TabItem >
2828</Tabs >
2929
30- ## 1. Initialize the SDK
31- <Tabs >
32- <TabItem label = ' Basic & Business' >
33- ``` typescript title="app.ts"
34- import { StackOverflowSDK } from ' so-teams-sdk' ;
30+ ## Authentication Setup
3531
36- const sdk = new StackOverflowSDK ({
37- baseUrl: ' https://api.stackoverflowteams.com/v3' ,
38- accessToken: ' your-access-token'
39- });
32+ Before making API calls, you'll need to set up authentication. The approach varies by your Stack Overflow for Teams tier:
4033
41- const teamContext = sdk .forTeam (' team-slug' );
42- ```
43- </TabItem >
44- <TabItem label = ' Enterprise' >
45- ``` typescript title="app.ts"
46- import { StackOverflowSDK } from ' so-teams-sdk' ;
47-
48- const sdk = new StackOverflowSDK ({
49- baseUrl: ' https://[your-site].stackenterprise.co/api/v3' ,
50- accessToken: ' your-access-token'
51- });
52- ```
53- </TabItem >
54- </Tabs >
34+ ### Enterprise - OAuth Available
35+ Enterprise instances can use built-in OAuth clients or manual tokens:
36+
37+ ``` typescript
38+ // Option 1: OAuth setup (recommended for Enterprise)
39+ import { StackOverflowSDK } from ' so-teams-sdk' ;
40+
41+ const sdk = StackOverflowSDK .enterpriseOAuth ({
42+ clientId: ' your-client-id' ,
43+ redirectUri: ' https://yourapp.com/callback' ,
44+ baseUrl: ' https://your-site.stackenterprise.co'
45+ });
46+
47+ // Option 2: Manual token (if you prefer)
48+ const sdk = StackOverflowSDK .fromToken (
49+ ' your-access-token' ,
50+ ' https://your-site.stackenterprise.co'
51+ );
52+ ```
53+
54+ ### Basic/Business - Token Required
55+ Basic and Business tiers require Personal Access Tokens (PATs):
56+
57+ ``` typescript
58+ import { StackOverflowSDK } from ' so-teams-sdk' ;
59+
60+ const sdk = StackOverflowSDK .fromToken (
61+ ' your-personal-access-token' ,
62+ ' https://api.stackoverflowteams.com/v3'
63+ );
64+
65+ // Team context required for Basic/Business
66+ const teamContext = sdk .forTeam (' your-team-id' );
67+ ```
68+
69+ > 📖 ** Need authentication help?** See our [ Authentication Guide] ( /guides/authentication ) for detailed OAuth setup and PAT generation.
5570
56- ## 2. Make Your First API Call
71+ ## Make Your First API Call
5772
5873Start exploring Stack Overflow data with these basic examples:
5974
60- ``` typescript title="api-calls.ts"
61- // Fetch recent questions
62- async function getAll () {
75+ ``` typescript
76+ // For Enterprise (direct SDK usage)
77+ async function getQuestions () {
6378 try {
6479 const questions = await sdk .questions .getAll ();
6580 console .log (' Recent questions:' , questions .items );
@@ -69,30 +84,51 @@ async function getAll() {
6984 }
7085}
7186
72- // Search for content
73- async function searchContent( query : string ) {
87+ // For Basic/Business (requires team context)
88+ async function getTeamQuestions( ) {
7489 try {
75- const results = await sdk .search .query (query );
76- console .log (' Search results:' , results .items );
77- return results ;
90+ const teamContext = sdk .forTeam (' your-team-id' );
91+ const questions = await teamContext .questions .getAll ();
92+ console .log (' Team questions:' , questions .items );
93+ return questions ;
7894 } catch (error ) {
79- console .error (' Search failed :' , error );
95+ console .error (' Failed to fetch questions :' , error );
8096 }
8197}
98+ ```
8299
83- // Get user information
84- async function getUser(userId : number ) {
85- try {
86- const user = await sdk .users .getUserById (userId );
87- console .log (' User details:' , user );
88- return user ;
89- } catch (error ) {
90- console .error (' Failed to fetch user:' , error );
91- }
92- }
100+ ## Complete Authentication Flow (Enterprise)
101+
102+ If using OAuth on Enterprise, here's a complete authentication flow:
103+
104+ ``` typescript
105+ import { StackOverflowSDK , BackendAuthClient } from ' so-teams-sdk' ;
106+
107+ // 1. Set up authentication client
108+ const authClient = new BackendAuthClient ({
109+ clientId: ' your-client-id' ,
110+ redirectUri: ' https://yourapp.com/callback' ,
111+ baseUrl: ' https://your-site.stackenterprise.co'
112+ });
113+
114+ // 2. Start OAuth flow
115+ const { url, codeVerifier, state } = await authClient .getAuthUrl ();
116+ // Redirect user to `url`
117+
118+ // 3. Handle callback and get tokens
119+ const tokens = await authClient .exchangeCodeForToken (code , codeVerifier );
120+
121+ // 4. Initialize SDK with token
122+ const sdk = StackOverflowSDK .fromToken (
123+ tokens .access_token ,
124+ ' https://your-site.stackenterprise.co'
125+ );
126+
127+ // 5. Make authenticated requests
128+ const questions = await sdk .questions .getAll ();
93129```
94130
95- ## 3. Working with Different Content Types
131+ ## Working with Different Content Types
96132
97133<Tabs >
98134 <TabItem label = " Questions & Answers" >
@@ -143,7 +179,7 @@ async function getUser(userId: number) {
143179 </TabItem >
144180</Tabs >
145181
146- ## 4. Team Context
182+ ## Team Context
147183
148184For Stack Overflow for Teams, use the team context:
149185
@@ -174,6 +210,7 @@ async function getTeamAnswers() {
174210}
175211```
176212
213+
177214## Error Handling
178215
179216Always wrap your API calls in try-catch blocks:
0 commit comments