Edits history of script submission #20089 for ' List Reverse ETL Sync Statuses from Model And Subscription Id (segment)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Segment = {
      token: string;
      baseUrl: string;
    };
    /**
     * List Reverse ETL Sync Statuses from Model And Subscription Id
     * Get the sync statuses for a Reverse ETL mapping subscription. 
    The sync status includes all detailed information about the sync - sync status, duration, details about the extract and load phase if applicable, etc. 
    The default page count is 10, and then the next page can be fetched by passing the `cursor` query parameter.
     */
    export async function main(
      auth: Segment,
      modelId: string,
      subscriptionId: string,
      count: string | undefined,
      cursor: string | undefined,
    ) {
      const url = new URL(
        `${auth.baseUrl}/reverse-etl-models/${modelId}/subscriptionId/${subscriptionId}/syncs`,
      );
      for (const [k, v] of [
        ["count", count],
        ["cursor", cursor],
      ]) {
        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.text();
    }
    

    Submitted by hugo697 235 days ago