Edits history of script submission #11333 for ' List Pins (pinterest)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Pinterest = {
      token: string;
    };
    /**
     * List Pins
     * Get a list of the Pins owned by the "operation user_account".
     */
    export async function main(
      auth: Pinterest,
      bookmark: string | undefined,
      page_size: string | undefined,
      pin_filter:
        | "exclude_native"
        | "exclude_repins"
        | "has_been_promoted"
        | undefined,
      include_protected_pins: string | undefined,
      pin_type: "PRIVATE" | undefined,
      creative_types: string | undefined,
      ad_account_id: string | undefined,
      pin_metrics: string | undefined,
    ) {
      const url = new URL(`https://api.pinterest.com/v5/pins`);
      for (const [k, v] of [
        ["bookmark", bookmark],
        ["page_size", page_size],
        ["pin_filter", pin_filter],
        ["include_protected_pins", include_protected_pins],
        ["pin_type", pin_type],
        ["creative_types", creative_types],
        ["ad_account_id", ad_account_id],
        ["pin_metrics", pin_metrics],
      ]) {
        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 537 days ago