@bates-solutions/squareup API Reference - v3.2.0
    Preparing search index...

    Class OrdersService

    Orders service for managing Square orders

    // Using the builder (recommended)
    const order = await square.orders
    .builder()
    .addItem({ name: 'Latte', amount: 450 })
    .withCustomer('CUST_123')
    .build();

    // Or create directly
    const order = await square.orders.create({
    lineItems: [{ name: 'Latte', amount: 450 }],
    });
    Index
    • Parameters

      • client: SquareClient
      • OptionaldefaultLocationId: string
      • defaultCurrency: "USD" | "CAD" | "GBP" | "EUR" | "AUD" | "JPY" = 'USD'

      Returns OrdersService

    • Create a new order builder

      Parameters

      • OptionallocationId: string

        Optional location ID (uses default if not provided)

      Returns OrderBuilder

      Order builder instance

      const order = await square.orders
      .builder()
      .addItem({ name: 'Coffee', amount: 350 })
      .addItem({ name: 'Muffin', amount: 250 })
      .withTip(100)
      .build();
    • Create an order directly (without builder)

      Parameters

      • options: CreateOrderOptions

        Order creation options

      • OptionallocationId: string

        Optional location ID

      Returns Promise<Order>

      Created order

      const order = await square.orders.create({
      lineItems: [
      { name: 'Coffee', amount: 350 },
      { catalogObjectId: 'ITEM_123', quantity: 2 },
      ],
      customerId: 'CUST_123',
      });
    • Get an order by ID

      Parameters

      • orderId: string

        Order ID

      Returns Promise<Order>

      Order details, including its tenders (the payments applied to it) and each tax's appliedMoney

      const order = await square.orders.get('ORDER_123');
      const paid = (order.tenders?.length ?? 0) > 0;
    • Pay for an order

      Parameters

      • orderId: string

        Order ID

      • paymentIds: string[]

        Payment IDs to apply

      • Optionaloptions: { idempotencyKey?: string }
        • OptionalidempotencyKey?: string

          Reuse the same key when retrying

      Returns Promise<Order>

      Updated order

      const order = await square.orders.pay('ORDER_123', ['PAYMENT_456']);
      
    • Search for orders

      Parameters

      Returns Promise<{ cursor?: string; data: Order[] }>

      Paginated list of orders

      // Simple search
      const { data, cursor } = await square.orders.search({
      locationIds: ['LXXX'],
      limit: 10,
      });

      // Search with filters
      const { data } = await square.orders.search({
      locationIds: ['LXXX'],
      query: {
      filter: {
      dateTimeFilter: {
      createdAt: {
      startAt: '2024-01-01T00:00:00Z',
      endAt: '2024-12-31T23:59:59Z',
      },
      },
      stateFilter: {
      states: ['OPEN', 'COMPLETED'],
      },
      fulfillmentFilter: {
      fulfillmentTypes: ['PICKUP', 'SHIPMENT'],
      },
      },
      sort: {
      sortField: 'CREATED_AT',
      sortOrder: 'DESC',
      },
      },
      });
    • Search for recent orders with simplified filter options

      Parameters

      Returns Promise<{ cursor?: string; data: Order[] }>

      Paginated list of orders

      // Get completed orders from the last hour
      const { data } = await square.orders.searchRecent({
      states: ['COMPLETED'],
      since: new Date(Date.now() - 60 * 60 * 1000),
      });

      // Get first page of orders from a date range
      const { data, cursor } = await square.orders.searchRecent({
      since: new Date('2024-01-01'),
      until: new Date('2024-01-31'),
      limit: 50,
      });

      // Fetch next page
      const page2 = await square.orders.searchRecent({
      since: new Date('2024-01-01'),
      until: new Date('2024-01-31'),
      cursor,
      limit: 50,
      });
    • Update an order. Only the fields you set are sent (a sparse update), so everything else on the order is left as it is.

      Parameters

      • orderId: string

        Order ID to update

      • updates: UpdateOrderOptions

        The order's current version, and the fields to change. Pass idempotencyKey and reuse it when resending the identical request (say, after a timeout) so Square deduplicates it. After re-reading the order for a new version, use a new key: Square rejects a reused key with a different body.

      • OptionallocationId: string

        Override the client's default location

      Returns Promise<Order>

      Updated order

      const order = await square.orders.get('ORDER_123');

      // Mark a shipment shipped, with tracking
      await square.orders.update('ORDER_123', {
      version: order.version!,
      fulfillments: [{
      uid: order.fulfillments![0].uid!,
      state: 'COMPLETED',
      shipmentDetails: { carrier: 'Canada Post', trackingNumber: '1234567890' },
      }],
      });

      // Cancel an order
      await square.orders.update('ORDER_123', { version: order.version!, state: 'CANCELED' });