Edits history of script submission #4461 for ' Cancels an order (shopify)'

  • nativets
    One script reply has been approved by the moderators
    Ap­pro­ved
    type Shopify = {
      token: string;
      store_name: string;
    };
    /**
     * Cancels an order
     *  Caution For multi-currency orders, the currency property is required whenever the amount property is provided. For more information, see Migrating to support multiple currencies.  Cancels an order. Orders that have a fulfillment object can't be canceled.
     */
    export async function main(
      auth: Shopify,
      api_version: string = "2023-10",
      order_id: string,
      body: {
        amount?: string;
        currency?: string;
        note?: string;
        [k: string]: unknown;
      }
    ) {
      const url = new URL(
        `https://${auth.store_name}.myshopify.com/admin/api/${api_version}/orders/${order_id}/cancel.json`
      );
    
      const response = await fetch(url, {
        method: "POST",
        headers: {
          "Content-Type": "application/json",
          "X-Shopify-Access-Token": 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 396 days ago

  • nativets
    type Shopify = {
      token: string;
      store_name: string;
    };
    /**
     * Cancels an order
     *  Caution For multi-currency orders, the currency property is required whenever the amount property is provided. For more information, see Migrating to support multiple currencies.  Cancels an order. Orders that have a fulfillment object can't be canceled.
     */
    export async function main(
      auth: Shopify,
      api_version: string = "2023-10",
      order_id: string,
      body: {
        amount?: string;
        currency?: string;
        note?: string;
        [k: string]: unknown;
      }
    ) {
      const url = new URL(
        `https://${auth.store_name}.myshopify.com/admin/api/${api_version}/orders/${order_id}/cancel.json`
      );
    
      const response = await fetch(url, {
        method: "POST",
        headers: {
          "Content-Type": "application/json",
          "X-Shopify-Access-Token": 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 942 days ago