22
33Create connectors using Vectorize's managed OAuth credentials for quick setup.
44
5+ ## Supported Connectors
6+
7+ Vectorize provides managed OAuth credentials for the following platforms:
8+ - ** Google Drive** (` GOOGLE_DRIVE_OAUTH_MULTI ` )
9+ - ** Dropbox** (` DROPBOX_OAUTH_MULTI ` )
10+ - ** Notion** (` NOTION_OAUTH_MULTI ` )
11+
512## API Route Implementation
613
714Create a file at ` app/api/createConnector/route.ts ` :
@@ -38,7 +45,8 @@ export async function POST(request: Request) {
3845 // Create the connector (Vectorize managed)
3946 const connectorId = await createVectorizeConnector (
4047 config ,
41- connectorName
48+ connectorName ,
49+ platformType
4250 );
4351
4452 return NextResponse .json ({ connectorId }, { status: 200 });
@@ -48,36 +56,208 @@ export async function POST(request: Request) {
4856}
4957```
5058
59+ ## Connector Examples
60+
61+ ### Google Drive Multi-User Connector
62+
63+ ``` typescript
64+ import { createVectorizeConnector } from " @vectorize-io/vectorize-connect" ;
65+
66+ const config = {
67+ organizationId: process .env .VECTORIZE_ORGANIZATION_ID ! ,
68+ authorization: process .env .VECTORIZE_API_KEY ! ,
69+ };
70+
71+ // Create Google Drive connector
72+ const gdriveConnectorId = await createVectorizeConnector (
73+ config ,
74+ " Team Google Drive" ,
75+ " GOOGLE_DRIVE_OAUTH_MULTI"
76+ );
77+
78+ console .log (' Google Drive connector created:' , gdriveConnectorId );
79+ ```
80+
81+ ### Dropbox Multi-User Connector
82+
83+ ``` typescript
84+ import { createVectorizeConnector } from " @vectorize-io/vectorize-connect" ;
85+
86+ const config = {
87+ organizationId: process .env .VECTORIZE_ORGANIZATION_ID ! ,
88+ authorization: process .env .VECTORIZE_API_KEY ! ,
89+ };
90+
91+ // Create Dropbox connector
92+ const dropboxConnectorId = await createVectorizeConnector (
93+ config ,
94+ " Team Dropbox Storage" ,
95+ " DROPBOX_OAUTH_MULTI"
96+ );
97+
98+ console .log (' Dropbox connector created:' , dropboxConnectorId );
99+ ```
100+
101+ ### Notion Multi-User Connector
102+
103+ ``` typescript
104+ import { createVectorizeConnector } from " @vectorize-io/vectorize-connect" ;
105+
106+ const config = {
107+ organizationId: process .env .VECTORIZE_ORGANIZATION_ID ! ,
108+ authorization: process .env .VECTORIZE_API_KEY ! ,
109+ };
110+
111+ // Create Notion connector
112+ const notionConnectorId = await createVectorizeConnector (
113+ config ,
114+ " Team Notion Workspace" ,
115+ " NOTION_OAUTH_MULTI"
116+ );
117+
118+ console .log (' Notion connector created:' , notionConnectorId );
119+ ```
120+
51121## Alternative: Using createSourceConnector
52122
53123For more control over connector configuration:
54124
55125``` typescript
56126import { createSourceConnector } from ' @vectorize-io/vectorize-connect' ;
57127
58- const connectorId = await createSourceConnector (
128+ // Google Drive with createSourceConnector
129+ const gdriveConnectorId = await createSourceConnector (
130+ config ,
131+ {
132+ name: " Team Google Drive" ,
133+ type: " GOOGLE_DRIVE_OAUTH_MULTI" ,
134+ config: {}
135+ }
136+ );
137+
138+ // Dropbox with createSourceConnector
139+ const dropboxConnectorId = await createSourceConnector (
59140 config ,
60141 {
61- name: " My Platform Connector " ,
62- type: " PLATFORM_OAUTH_MULTI " ,
142+ name: " Team Dropbox Storage " ,
143+ type: " DROPBOX_OAUTH_MULTI " ,
63144 config: {}
64145 }
65146);
147+
148+ // Notion with createSourceConnector
149+ const notionConnectorId = await createSourceConnector (
150+ config ,
151+ {
152+ name: " Team Notion Workspace" ,
153+ type: " NOTION_OAUTH_MULTI" ,
154+ config: {}
155+ }
156+ );
157+ ```
158+
159+ ## Frontend Usage Examples
160+
161+ ### Google Drive Connector Creation
162+
163+ ``` typescript
164+ const handleCreateGoogleDriveConnector = async () => {
165+ try {
166+ const response = await fetch (" /api/createConnector" , {
167+ method: " POST" ,
168+ headers: {
169+ " Content-Type" : " application/json" ,
170+ },
171+ body: JSON .stringify ({
172+ connectorName: " Team Google Drive" ,
173+ platformType: " GOOGLE_DRIVE_OAUTH_MULTI"
174+ }),
175+ });
176+
177+ if (! response .ok ) {
178+ const data = await response .json ();
179+ throw new Error (data .error || ' Failed to create Google Drive connector' );
180+ }
181+
182+ const { connectorId } = await response .json ();
183+ console .log (' Google Drive connector created:' , connectorId );
184+ } catch (error : any ) {
185+ console .error (' Error creating Google Drive connector:' , error .message );
186+ }
187+ };
188+ ```
189+
190+ ### Dropbox Connector Creation
191+
192+ ``` typescript
193+ const handleCreateDropboxConnector = async () => {
194+ try {
195+ const response = await fetch (" /api/createConnector" , {
196+ method: " POST" ,
197+ headers: {
198+ " Content-Type" : " application/json" ,
199+ },
200+ body: JSON .stringify ({
201+ connectorName: " Team Dropbox Storage" ,
202+ platformType: " DROPBOX_OAUTH_MULTI"
203+ }),
204+ });
205+
206+ if (! response .ok ) {
207+ const data = await response .json ();
208+ throw new Error (data .error || ' Failed to create Dropbox connector' );
209+ }
210+
211+ const { connectorId } = await response .json ();
212+ console .log (' Dropbox connector created:' , connectorId );
213+ } catch (error : any ) {
214+ console .error (' Error creating Dropbox connector:' , error .message );
215+ }
216+ };
217+ ```
218+
219+ ### Notion Connector Creation
220+
221+ ``` typescript
222+ const handleCreateNotionConnector = async () => {
223+ try {
224+ const response = await fetch (" /api/createConnector" , {
225+ method: " POST" ,
226+ headers: {
227+ " Content-Type" : " application/json" ,
228+ },
229+ body: JSON .stringify ({
230+ connectorName: " Team Notion Workspace" ,
231+ platformType: " NOTION_OAUTH_MULTI"
232+ }),
233+ });
234+
235+ if (! response .ok ) {
236+ const data = await response .json ();
237+ throw new Error (data .error || ' Failed to create Notion connector' );
238+ }
239+
240+ const { connectorId } = await response .json ();
241+ console .log (' Notion connector created:' , connectorId );
242+ } catch (error : any ) {
243+ console .error (' Error creating Notion connector:' , error .message );
244+ }
245+ };
66246```
67247
68- ## Frontend Usage
248+ ### Dynamic Connector Creation
69249
70250``` typescript
71- const handleCreateConnector = async () => {
251+ const handleCreateConnector = async (platformType : string , connectorName : string ) => {
72252 try {
73253 const response = await fetch (" /api/createConnector" , {
74254 method: " POST" ,
75255 headers: {
76256 " Content-Type" : " application/json" ,
77257 },
78258 body: JSON .stringify ({
79- connectorName: " My Team Storage Connector " ,
80- platformType: " PLATFORM_OAUTH_MULTI "
259+ connectorName ,
260+ platformType
81261 }),
82262 });
83263
@@ -87,20 +267,30 @@ const handleCreateConnector = async () => {
87267 }
88268
89269 const { connectorId } = await response .json ();
90- console .log (' Connector created:' , connectorId );
270+ console .log (` ${platformType } connector created: ` , connectorId );
271+ return connectorId ;
91272 } catch (error : any ) {
92- console .error (' Error creating connector:' , error .message );
273+ console .error (` Error creating ${platformType } connector: ` , error .message );
274+ throw error ;
93275 }
94276};
277+
278+ // Usage examples
279+ await handleCreateConnector (" GOOGLE_DRIVE_OAUTH_MULTI" , " Team Google Drive" );
280+ await handleCreateConnector (" DROPBOX_OAUTH_MULTI" , " Team Dropbox Storage" );
281+ await handleCreateConnector (" NOTION_OAUTH_MULTI" , " Team Notion Workspace" );
95282```
96283
97284## Error Handling
98285
286+ ### Basic Error Handling
287+
99288``` typescript
100289try {
101290 const connectorId = await createVectorizeConnector (
102291 vectorizeConfig ,
103- " My Connector"
292+ " Team Google Drive" ,
293+ " GOOGLE_DRIVE_OAUTH_MULTI"
104294 );
105295} catch (error ) {
106296 if (error .response ?.status === 401 ) {
@@ -113,6 +303,46 @@ try {
113303}
114304```
115305
306+ ### Platform-Specific Error Handling
307+
308+ ``` typescript
309+ const createConnectorWithErrorHandling = async (
310+ platformType : string ,
311+ connectorName : string
312+ ) => {
313+ try {
314+ const connectorId = await createVectorizeConnector (
315+ vectorizeConfig ,
316+ connectorName ,
317+ platformType
318+ );
319+
320+ console .log (` ${platformType } connector created successfully: ` , connectorId );
321+ return connectorId ;
322+ } catch (error ) {
323+ // Handle specific platform errors
324+ if (error .response ?.status === 401 ) {
325+ throw new Error (` Invalid Vectorize API credentials for ${platformType } ` );
326+ } else if (error .response ?.status === 403 ) {
327+ throw new Error (` Insufficient permissions for ${platformType } connector creation ` );
328+ } else if (error .response ?.status === 400 ) {
329+ throw new Error (` Invalid configuration for ${platformType } connector ` );
330+ } else {
331+ throw new Error (` Failed to create ${platformType } connector: ${error .message } ` );
332+ }
333+ }
334+ };
335+
336+ // Usage with error handling
337+ try {
338+ await createConnectorWithErrorHandling (" GOOGLE_DRIVE_OAUTH_MULTI" , " Team Google Drive" );
339+ await createConnectorWithErrorHandling (" DROPBOX_OAUTH_MULTI" , " Team Dropbox" );
340+ await createConnectorWithErrorHandling (" NOTION_OAUTH_MULTI" , " Team Notion" );
341+ } catch (error ) {
342+ console .error (' Connector creation failed:' , error .message );
343+ }
344+ ```
345+
116346## Next Steps
117347
118348- [ Authentication] ( ../../authentication/vectorize/ )
0 commit comments