Edits history of script submission #20396 for ' List recommended images (shutterstock)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Shutterstock = {
      token: string;
    };
    /**
     * List recommended images
     * This endpoint returns images that customers put in the same collection as the specified image IDs.
     */
    export async function main(
      auth: Shutterstock,
      id: string | undefined,
      max_items: string | undefined,
      safe: string | undefined,
    ) {
      const url = new URL(`https://api.shutterstock.com/v2/images/recommendations`);
      for (const [k, v] of [
        ["id", id],
        ["max_items", max_items],
        ["safe", safe],
      ]) {
        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