Edits history of script submission #4456 for ' Cancel a fulfillment order (shopify)'

  • nativets
    One script reply has been approved by the moderators
    Ap­pro­ved
    type Shopify = {
      token: string;
      store_name: string;
    };
    /**
     * Cancel a fulfillment order
     * Marks a fulfillment order as cancelled.
     */
    export async function main(
      auth: Shopify,
      api_version: string = "2023-10",
      fulfillment_order_id: string,
      body: {
        fulfillment_order?: {
          assigned_location?: {
            address1?: { [k: string]: unknown };
            address2?: { [k: string]: unknown };
            city?: { [k: string]: unknown };
            country_code?: string;
            location_id?: number;
            name?: string;
            phone?: { [k: string]: unknown };
            province?: { [k: string]: unknown };
            zip?: { [k: string]: unknown };
            [k: string]: unknown;
          };
          assigned_location_id?: number;
          destination?: {
            address1?: string;
            address2?: string;
            city?: string;
            company?: { [k: string]: unknown };
            country?: string;
            email?: string;
            first_name?: string;
            id?: number;
            last_name?: string;
            phone?: string;
            province?: string;
            zip?: string;
            [k: string]: unknown;
          };
          fulfillment_service_handle?: string;
          id?: number;
          line_items?: {
            fulfillable_quantity?: number;
            fulfillment_order_id?: number;
            id?: number;
            inventory_item_id?: number;
            line_item_id?: number;
            quantity?: number;
            shop_id?: number;
            variant_id?: number;
            [k: string]: unknown;
          }[];
          merchant_requests?: unknown[];
          order_id?: number;
          request_status?: string;
          shop_id?: number;
          status?: string;
          supported_actions?: string[];
          [k: string]: unknown;
        };
        [k: string]: unknown;
      }
    ) {
      const url = new URL(
        `https://${auth.store_name}.myshopify.com/admin/api/${api_version}/fulfillment_orders/${fulfillment_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;
    };
    /**
     * Cancel a fulfillment order
     * Marks a fulfillment order as cancelled.
     */
    export async function main(
      auth: Shopify,
      api_version: string = "2023-10",
      fulfillment_order_id: string,
      body: {
        fulfillment_order?: {
          assigned_location?: {
            address1?: { [k: string]: unknown };
            address2?: { [k: string]: unknown };
            city?: { [k: string]: unknown };
            country_code?: string;
            location_id?: number;
            name?: string;
            phone?: { [k: string]: unknown };
            province?: { [k: string]: unknown };
            zip?: { [k: string]: unknown };
            [k: string]: unknown;
          };
          assigned_location_id?: number;
          destination?: {
            address1?: string;
            address2?: string;
            city?: string;
            company?: { [k: string]: unknown };
            country?: string;
            email?: string;
            first_name?: string;
            id?: number;
            last_name?: string;
            phone?: string;
            province?: string;
            zip?: string;
            [k: string]: unknown;
          };
          fulfillment_service_handle?: string;
          id?: number;
          line_items?: {
            fulfillable_quantity?: number;
            fulfillment_order_id?: number;
            id?: number;
            inventory_item_id?: number;
            line_item_id?: number;
            quantity?: number;
            shop_id?: number;
            variant_id?: number;
            [k: string]: unknown;
          }[];
          merchant_requests?: unknown[];
          order_id?: number;
          request_status?: string;
          shop_id?: number;
          status?: string;
          supported_actions?: string[];
          [k: string]: unknown;
        };
        [k: string]: unknown;
      }
    ) {
      const url = new URL(
        `https://${auth.store_name}.myshopify.com/admin/api/${api_version}/fulfillment_orders/${fulfillment_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