Edits history of script submission #12010 for ' List all clients (clerk)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Clerk = {
      apiKey: string;
    };
    /**
     * List all clients
     * Returns a list of all clients. The clients are returned sorted by creation date,
    with the newest clients appearing first.
    Warning: the endpoint is being deprecated and will be removed in future versions.
     */
    export async function main(
      auth: Clerk,
      limit: string | undefined,
      offset: string | undefined,
    ) {
      const url = new URL(`https://api.clerk.com/v1/clients`);
      for (const [k, v] of [
        ["limit", limit],
        ["offset", offset],
      ]) {
        if (v !== undefined && v !== "" && k !== undefined) {
          url.searchParams.append(k, v);
        }
      }
      const response = await fetch(url, {
        method: "GET",
        headers: {
          Authorization: "Bearer " + auth.apiKey,
        },
        body: undefined,
      });
      if (!response.ok) {
        const text = await response.text();
        throw new Error(`${response.status} ${text}`);
      }
      return await response.json();
    }
    

    Submitted by hugo697 428 days ago