Edits history of script submission #20333 for ' Add items to catalog collections (shutterstock)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Shutterstock = {
      token: string;
    };
    /**
     * Add items to catalog collections
     * This endpoint adds assets to a catalog collection. It also automatically adds the assets to the user's account's catalog.
     */
    export async function main(
      auth: Shutterstock,
      collection_id: string,
      body: { items: { asset: { id?: string; type: string } }[] },
    ) {
      const url = new URL(
        `https://api.shutterstock.com/v2/catalog/collections/${collection_id}/items`,
      );
    
      const response = await fetch(url, {
        method: "POST",
        headers: {
          "Content-Type": "application/json",
          Authorization: "Bearer " + auth.token,
        },
        body: JSON.stringify(body),
      });
      if (!response.ok) {
        const text = await response.text();
        throw new Error(`${response.status} ${text}`);
      }
      return await response.json();
    }
    

    Submitted by hugo697 235 days ago