Orders API to replicate "Online" > "Orders" > "Export Orders"

I’m working within the Square API to try to re-create the Export Orders option for all online orders. So far, I’m working with the following payload:

    let payload = {
      "return_entries": false,
      "limit": 5000,
      "location_ids": ["xxxxx"],
      "query": {
        "filter": {
          "state_filter": {
            "states": ["OPEN"]
        "source_filter": {
          "source_names": [
            "Square Online",


This is doing a pretty good job, but a few things don’t seem to be quite right. The IDs associated with each order do not match the format from the raw export (raw export Order ID #s are 10-digit strings, here I’m getting 25 or 29-digit ID values); but the most important thing is the customer_id field, which just isn’t populating in about 70-80% of cases. When I do the online export, I can always get the customer name and email, but I don’t see a clear way to do that if I can’t hit the customers api when I have an order in hand. In Stripe, this would be done simply by “extending” the API queries, which makes it WAY easier to just quickly and simply get the customer info–is there an equivalent version in Square? If not, are there other endpoints I should be looking at?

With the Orders API the short order_id that’s shown in the seller Dashboard isn’t currently returned in the API response. We’re constantly working to improve our features based on feedback like this, so I’ll be sure to share your request to the API product team.

If the customer_id isn’t in the order body you’ll want to call the Payments API GetPayment with the payment_id to get the customer_id.

If a customer is not assigned to a payment, Square attempts to infer the associated customer. First, Square checks the customer_id field in the corresponding order. If this field is not set, Square searches the Customer Directory for a matching profile using payment or related information (such as the billing and shipping address, email address, and payment source). If one cannot be found, Square attempts to create an instant profile. Note that this process is asynchronous and might take some time before customer_id is added to the payment.

If Square cannot find a matching customer profile and cannot create an instant profile, the customer_id field of the payment remains unset. :slightly_smiling_face: