Edits history of script submission #20798 for ' SearchOrders (square)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Square = {
      token: string;
    };
    /**
     * SearchOrders
     * Search all orders for one or more locations.
     */
    export async function main(
      auth: Square,
      body: {
        location_ids?: string[];
        cursor?: string;
        query?: {
          filter?: {
            state_filter?: {
              states: "OPEN" | "COMPLETED" | "CANCELED" | "DRAFT"[];
            };
            date_time_filter?: {
              created_at?: { start_at?: string; end_at?: string };
              updated_at?: { start_at?: string; end_at?: string };
              closed_at?: { start_at?: string; end_at?: string };
            };
            fulfillment_filter?: {
              fulfillment_types?: "PICKUP" | "SHIPMENT" | "DELIVERY"[];
              fulfillment_states?:
                | "COMPLETED"
                | "CANCELED"
                | "PROPOSED"
                | "RESERVED"
                | "PREPARED"
                | "FAILED"[];
            };
            source_filter?: { source_names?: string[] };
            customer_filter?: { customer_ids?: string[] };
          };
          sort?: {
            sort_field: "CREATED_AT" | "UPDATED_AT" | "CLOSED_AT";
            sort_order?: "DESC" | "ASC";
          };
        };
        limit?: number;
        return_entries?: false | true;
      },
    ) {
      const url = new URL(`https://connect.squareup.com/v2/orders/search`);
    
      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 235 days ago