Edits history of script submission #20402 for ' List updated images (shutterstock)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Shutterstock = {
      token: string;
    };
    /**
     * List updated images
     * This endpoint lists images that have been updated in the specified time period to update content management systems (CMS) or digital asset management (DAM) systems. In most cases, use the `interval` parameter to show images that were updated recently, but you can also use the `start_date` and `end_date` parameters to specify a range of no more than three days. Do not use the `interval` parameter with either `start_date` or `end_date`.
     */
    export async function main(
      auth: Shutterstock,
      _type: string | undefined,
      start_date: string | undefined,
      end_date: string | undefined,
      interval: string | undefined,
      page: string | undefined,
      per_page: string | undefined,
      sort: "newest" | "oldest" | undefined,
    ) {
      const url = new URL(`https://api.shutterstock.com/v2/images/updated`);
      for (const [k, v] of [
        ["type", _type],
        ["start_date", start_date],
        ["end_date", end_date],
        ["interval", interval],
        ["page", page],
        ["per_page", per_page],
        ["sort", sort],
      ]) {
        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