Edits history of script submission #20102 for ' List Syncs from Warehouse And Source (segment)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Segment = {
      token: string;
      baseUrl: string;
    };
    /**
     * List Syncs from Warehouse And Source
     * Returns the overview of syncs for a Source connected to a Warehouse.
    
    
    The rate limit for this endpoint is 2 requests per minute, which is lower than the default due to access pattern restrictions. Once reached, this endpoint will respond with the 429 HTTP status code with headers indicating the limit parameters. See Rate Limiting for more information.
     */
    export async function main(
      auth: Segment,
      warehouseId: string,
      sourceId: string,
      pagination: string | undefined,
    ) {
      const url = new URL(
        `${auth.baseUrl}/warehouses/${warehouseId}/connected-sources/${sourceId}/syncs`,
      );
      for (const [k, v] of [["pagination", pagination]]) {
        if (v !== undefined && v !== "" && k !== undefined) {
          url.searchParams.append(k, v);
        }
      }
      const response = await fetch(url, {
        method: "GET",
        headers: {
          Authorization: "Bearer " + auth.token,
        },
        body: undefined,
      });
      if (!response.ok) {
        const text = await response.text();
        throw new Error(`${response.status} ${text}`);
      }
      return await response.json();
    }
    

    Submitted by hugo697 235 days ago