Edits history of script submission #20046 for ' Get Filtered At Destination Metrics from Delivery Overview (segment)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Segment = {
      token: string;
      baseUrl: string;
    };
    /**
     * Get Filtered At Destination Metrics from Delivery Overview
     * Get events that were filtered at Destination.
     */
    export async function main(
      auth: Segment,
      sourceId: string | undefined,
      destinationConfigId: string | undefined,
      startTime: string | undefined,
      endTime: string | undefined,
      groupBy: string | undefined,
      granularity: "DAY" | "HOUR" | "MINUTE" | undefined,
      filter: string | undefined,
      pagination: string | undefined,
    ) {
      const url = new URL(
        `${auth.baseUrl}/delivery-overview/filtered-at-destination`,
      );
      for (const [k, v] of [
        ["sourceId", sourceId],
        ["destinationConfigId", destinationConfigId],
        ["startTime", startTime],
        ["endTime", endTime],
        ["groupBy", groupBy],
        ["granularity", granularity],
        ["filter", filter],
        ["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.text();
    }
    

    Submitted by hugo697 235 days ago