Edits history of script submission #12104 for ' Update a Connector (cohere)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Cohere = {
      apiKey: string;
    };
    /**
     * Update a Connector
     * Update a connector by ID. Omitted fields will not be updated. See ['Managing your Connector'](https://docs.cohere.com/docs/managing-your-connector) for more information.
     */
    export async function main(
      auth: Cohere,
      id: string,
      body: {
        name?: 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/${id}`);
    
      const response = await fetch(url, {
        method: "PATCH",
        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