能否通过Square Connect API按日期条件检索客户、订单及交易数据?
Hey there! Great question—yes, you absolutely can filter customer, order, and transaction data by date using the Square Connect APIs. Let's break this down for each endpoint you're asking about:
Filtering Customer Data by Date
First off, your example call is on the right track! The Customers API supports the begin_time and end_time query parameters to filter customers based on their creation timestamp.
Key Details:
- The parameters require an ISO 8601 formatted timestamp in UTC (like
2016-01-15T00:00:00Z). Your example is almost perfect—just note the trailingZis mandatory to denote UTC (your sample link misses it at the end of theend_timevalue). - This filters customers created between the
begin_time(inclusive) andend_time(exclusive).
Example Request:
GET /v2/customers?begin_time=2016-01-15T00:00:00Z&end_time=2016-01-31T00:00:00Z
Keep in mind: If you get a large volume of results, you'll need to handle pagination using the cursor parameter returned in the response.
Filtering Order Data by Date
For orders, you'll use the SearchOrders endpoint (a POST request) instead of a simple GET. Date filters are defined in the request body's query object.
Key Details:
- You can filter by either
created_atorupdated_attimestamps. - Use the
date_time_filterobject to set your start and end times (again, UTC ISO 8601 format is required).
Example Request Body:
{ "location_ids": ["YOUR_LOCATION_ID"], "query": { "filter": { "date_time_filter": { "created_at": { "start_at": "2024-01-01T00:00:00Z", "end_at": "2024-01-31T23:59:59Z" } } } } }
Pro Tip:
If you want to filter by when orders were updated instead of created, just replace created_at with updated_at in the date_time_filter object.
Filtering Transaction Data by Date
The Transactions API (specifically the ListTransactions endpoint) uses begin_time and end_time query parameters, similar to the Customers API, to filter transactions by their creation time.
Key Details:
- Timestamps must be in UTC ISO 8601 format.
- This filters transactions created between the
begin_time(inclusive) andend_time(exclusive).
Example Request:
GET /v2/locations/YOUR_LOCATION_ID/transactions?begin_time=2024-01-01T00:00:00Z&end_time=2024-01-31T23:59:59Z
As with customers, pagination using the cursor parameter applies if you have more transactions than the default page limit.
General Notes:
- Always use UTC timestamps to avoid timezone mismatches—Square's APIs operate exclusively in UTC.
- Double-check your API permissions: Ensure your access token has the necessary scopes (like
CUSTOMERS_READ,ORDERS_READ,PAYMENTS_READ) to retrieve this data. - If you run into issues, verify the timestamp format is exact (no typos, correct
TandZseparators).
内容的提问来源于stack exchange,提问作者Rahul Nataraj

