aboutsummaryrefslogtreecommitdiff
path: root/apps/docs/memory-api/connectors/creating-connection.mdx
blob: a3d1e257204a2302002a5e6292f01cc02c3b76ee (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
---
title: 'Creating connections'
description: 'Create a connection to sync your content with supermemory'
---

To create a connection, just make a `POST` request to `/v3/connections/{provider}`

<CodeGroup>
```typescript Typescript
import Supermemory from 'supermemory';

const client = new Supermemory({
  apiKey: process.env['SUPERMEMORY_API_KEY'], // This is the default and can be omitted
});

// For OAuth providers (notion, google-drive, onedrive)
const connection = await client.connections.create('notion');
console.debug(connection.authLink);

// For web-crawler (no OAuth required)
const webCrawlerConnection = await client.connections.create('web-crawler', {
  metadata: { startUrl: 'https://docs.example.com' }
});
console.debug(webCrawlerConnection.id); // authLink will be null
```

```python Python
import requests

url = "https://api.supermemory.ai/v3/connections/{provider}"

payload = {
    "redirectUrl": "<string>",
    "containerTags": ["<string>"],
    "metadata": {},
    "documentLimit": 5000
}
headers = {
    "Authorization": "Bearer <token>",
    "Content-Type": "application/json"
}

response = requests.request("POST", url, json=payload, headers=headers)

print(response.text)
```

```bash cURL
curl --request POST \
  --url https://api.supermemory.ai/v3/connections/{provider} \
  --header 'Authorization: Bearer <token>' \
  --header 'Content-Type: application/json' \
  --data '{
  "redirectUrl": "<string>",
  "containerTags": [
    "<string>"
  ],
  "metadata": {},
  "documentLimit": 5000
}'
```
</CodeGroup>

### Parameters

- `provider`: The provider to connect to. Currently supported providers are `notion`, `google-drive`, `onedrive`, `web-crawler`
- `redirectUrl`: The URL to redirect to after the connection is created (your app URL)
    - Note: For `web-crawler`, this is optional as no OAuth flow is required
- `containerTags`: Optional. For partitioning users, organizations, etc. in your app.
    - Example: `["user_123", "project_alpha"]`
- `metadata`: Optional. Any metadata you want to associate with the connection.
    - This metadata is added to every document synced from this connection.
    - For `web-crawler`, must include `startUrl` in metadata: `{"startUrl": "https://example.com"}`
- `documentLimit`: Optional. The maximum number of documents to sync from this connection.
    - Default: 10,000
    - This can be used to limit costs and sync a set number of documents for a specific user.


## Response

supermemory sends a response with the following schema:
```json
{
  "id": "<string>",
  "authLink": "<string>",
  "expiresIn": "<string>",
  "redirectsTo": "<string>"
}
```

For most providers (notion, google-drive, onedrive), you can use the `authLink` to redirect the user to the provider's login page.

<Note>
**Web Crawler Exception:** For `web-crawler` provider, `authLink` and `expiresIn` will be `null` since no OAuth flow is required. The connection is established immediately upon creation.
</Note>

Next up, managing connections.