Edits history of script submission #20074 for ' List Connected Destinations from Source (segment)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Segment = {
      token: string;
      baseUrl: string;
    };
    /**
     * List Connected Destinations from Source
     * Returns a list of Destinations connected to a Source.
     */
    export async function main(
      auth: Segment,
      sourceId: string,
      pagination: string | undefined,
    ) {
      const url = new URL(
        `${auth.baseUrl}/sources/${sourceId}/connected-destinations`,
      );
      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