Edits history of script submission #20419 for ' Search editorial video content (shutterstock)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Shutterstock = {
      token: string;
    };
    /**
     * Search editorial video content
     * This endpoint searches for editorial videos. If you specify more than one search parameter, the API uses an AND condition. For example, if you set the `category` parameter to "Alone,Performing" and also specify a `query` parameter, the results include only videos that match the query and are in both the Alone and Performing categories.  You can also filter search terms out in the `query` parameter by prefixing the term with NOT.
     */
    export async function main(
      auth: Shutterstock,
      query: string | undefined,
      sort: "relevant" | "newest" | "oldest" | undefined,
      category: string | undefined,
      country: string | undefined,
      supplier_code: string | undefined,
      date_start: string | undefined,
      date_end: string | undefined,
      resolution: "4k" | "high_definition" | "standard_definition" | undefined,
      fps: string | undefined,
      per_page: string | undefined,
      cursor: string | undefined,
    ) {
      const url = new URL(
        `https://api.shutterstock.com/v2/editorial/videos/search`,
      );
      for (const [k, v] of [
        ["query", query],
        ["sort", sort],
        ["category", category],
        ["country", country],
        ["supplier_code", supplier_code],
        ["date_start", date_start],
        ["date_end", date_end],
        ["resolution", resolution],
        ["fps", fps],
        ["per_page", per_page],
        ["cursor", cursor],
      ]) {
        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