Edits history of script submission #11792 for ' Managing the status of the order (brevo)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Brevo = {
      apiKey: string;
    };
    /**
     * Managing the status of the order
     * Manages the transactional status of the order
     */
    export async function main(
      auth: Brevo,
      body: {
        id: string;
        createdAt: string;
        updatedAt: string;
        status: string;
        amount: number;
        storeId?: string;
        identifiers?: {
          ext_id?: string;
          loyalty_subscription_id?: string;
          phone_id?: string;
          email_id?: string;
        };
        products: {
          productId: string;
          quantity: number;
          variantId?: string;
          price: number;
        }[];
        billing?: {
          address?: string;
          city?: string;
          countryCode?: string;
          country?: string;
          phone?: string;
          postCode?: string;
          paymentMethod?: string;
          region?: string;
        };
        coupons?: string[];
      },
    ) {
      const url = new URL(`https://api.brevo.com/v3/orders/status`);
    
      const response = await fetch(url, {
        method: "POST",
        headers: {
          "Content-Type": "application/json",
          "api-key": auth.apiKey,
        },
        body: JSON.stringify(body),
      });
      if (!response.ok) {
        const text = await response.text();
        throw new Error(`${response.status} ${text}`);
      }
      return await response.text();
    }
    

    Submitted by hugo697 428 days ago