0

Create a Connector

by
Published Apr 8, 2025

Creates a new connector. The connector is tested during registration and will cancel registration when the test is unsuccessful. See ['Creating and Deploying a Connector'](https://docs.cohere.com/v1/docs/creating-and-deploying-a-connector) for more information.

Script cohere Verified

The script

Submitted by hugo697 Bun
Verified 428 days ago
1
//native
2
type Cohere = {
3
  apiKey: string;
4
};
5
/**
6
 * Create a Connector
7
 * Creates a new connector. The connector is tested during registration and will cancel registration when the test is unsuccessful. See ['Creating and Deploying a Connector'](https://docs.cohere.com/v1/docs/creating-and-deploying-a-connector) for more information.
8
 */
9
export async function main(
10
  auth: Cohere,
11
  body: {
12
    name: string;
13
    description?: string;
14
    url: string;
15
    excludes?: string[];
16
    oauth?: {
17
      client_id?: string;
18
      client_secret?: string;
19
      authorize_url?: string;
20
      token_url?: string;
21
      scope?: string;
22
    };
23
    active?: false | true;
24
    continue_on_failure?: false | true;
25
    service_auth?: { type: "bearer" | "basic" | "noscheme"; token: string };
26
  },
27
) {
28
  const url = new URL(`https://api.cohere.com/v1/connectors`);
29

30
  const response = await fetch(url, {
31
    method: "POST",
32
    headers: {
33
      "Content-Type": "application/json",
34
      Authorization: "Bearer " + auth.apiKey,
35
    },
36
    body: JSON.stringify(body),
37
  });
38
  if (!response.ok) {
39
    const text = await response.text();
40
    throw new Error(`${response.status} ${text}`);
41
  }
42
  return await response.json();
43
}
44