Edits history of script submission #11384 for ' Update asset groups. (pinterest)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Pinterest = {
      token: string;
    };
    /**
     * Update asset groups.
     * Update a batch of asset groups with the specified parameters.
     */
    export async function main(
      auth: Pinterest,
      business_id: string,
      body: {
        asset_groups_to_update?: {
          asset_group_id: string;
          name?: string;
          description?: string;
          asset_group_types?:
            | "BRAND"
            | "LOCATION_OR_LANGUAGE"
            | "PRODUCT_LINE"
            | "OTHER"[];
          assets_to_add?: string[];
          assets_to_remove?: string[];
        }[];
      },
    ) {
      const url = new URL(
        `https://api.pinterest.com/v5/businesses/${business_id}/asset_groups`,
      );
    
      const response = await fetch(url, {
        method: "PATCH",
        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 537 days ago