Edits history of script submission #12080 for ' Create a Connector (cohere)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Cohere = {
      apiKey: string;
    };
    /**
     * Create a Connector
     * 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.
     */
    export async function main(
      auth: Cohere,
      body: {
        name: string;
        description?: string;
        url: string;
        excludes?: string[];
        oauth?: {
          client_id?: string;
          client_secret?: string;
          authorize_url?: string;
          token_url?: string;
          scope?: string;
        };
        active?: false | true;
        continue_on_failure?: false | true;
        service_auth?: { type: "bearer" | "basic" | "noscheme"; token: string };
      },
    ) {
      const url = new URL(`https://api.cohere.com/v1/connectors`);
    
      const response = await fetch(url, {
        method: "POST",
        headers: {
          "Content-Type": "application/json",
          Authorization: "Bearer " + auth.apiKey,
        },
        body: JSON.stringify(body),
      });
      if (!response.ok) {
        const text = await response.text();
        throw new Error(`${response.status} ${text}`);
      }
      return await response.json();
    }
    

    Submitted by hugo697 428 days ago