Edits history of script submission #11226 for ' Create insertion order through SSIO. (pinterest)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Pinterest = {
      token: string;
    };
    /**
     * Create insertion order through SSIO.
     * Create insertion order through SSIO for ad_account_id.
    - The token's user_account must either be the Owner of the specified ad account, or have one of the necessary roles granted to them via Business Access: Admin, Finance, Campaign.
     */
    export async function main(
      auth: Pinterest,
      ad_account_id: string,
      body: {
        start_date?: string;
        end_date?: string;
        po_number?: string;
        budget_amount?: number;
        billing_contact_firstname?: string;
        billing_contact_lastname?: string;
        billing_contact_email?: string;
        media_contact_firstname?: string;
        media_contact_lastname?: string;
        media_contact_email?: string;
        agency_link?: string;
        user_email?: string;
      } & {
        accepted_terms_time?: number;
        pmp_id: string;
        order_name: string;
        order_line_type: "BUDGET" | "PERPETUALS";
        accepted_terms_id: string;
        billto_company_id: string;
        billto_business_address_id: string;
        billto_billing_address_id: string;
        estimated_monthly_spend?: number;
        currency_info:
          | "UNK"
          | "USD"
          | "GBP"
          | "CAD"
          | "EUR"
          | "AUD"
          | "NZD"
          | "SEK"
          | "ILS"
          | "CHF"
          | "HKD"
          | "JPY"
          | "SGD"
          | "KRW"
          | "NOK"
          | "DKK"
          | "PLN"
          | "RON"
          | "HUF"
          | "CZK"
          | "BRL"
          | "MXN"
          | "ARS"
          | "CLP"
          | "COP"
          | "INR"
          | "TRY";
      },
    ) {
      const url = new URL(
        `https://api.pinterest.com/v5/ad_accounts/${ad_account_id}/ssio/insertion_orders`,
      );
    
      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 537 days ago