GraphQL Query Examples

Square GraphQL lets you query for data across supported Square graphs. The query examples in this topic show common reporting scenarios that demonstrate the power and ease of using GraphQL. You can copy the examples and run them in GraphQL Explorer.

The examples use variables and include fields for pagination. To page through data, provide the cursor returned in the response as the before or after argument in your next query. Some examples also use aliases to rename response fields.

To get the merchant ID for the merchantId variable, run the following query in GraphQL Explorer:

{ currentMerchant { id }

Note

To learn about GraphQL Explorer features and how to get set up to run queries, see GraphQL Explorer Overview. GraphQL Explorer also provides a set of sample queries that you can run.

Link to section

Get payment history for a customer

Returns information about in-progress or completed payments made by a customer within a specified time range. This query also retrieves any refunds for the payment.

Query:

This example uses a refundOrderId alias to rename the orderId field in the response when it applies to orders created for a refund.

Query variables:

{ "merchantId": "8QJTJCEXAMPLE", "customerId": "9HRM2DFVBH73GGXRW4DEXAMPLE", "start": "2023-07-01T00:00:00+08:00", "end": "2023-07-31T23:59:59+08:00" }

Example response:

Link to section

Get processing fees for completed orders

Returns the processing fees associated with completed orders that were closed in a specified time range. This query retrieves the fees from the Payment object that corresponds to the tender.

Query:

This example uses orderAmount and feeAmount aliases to rename the amountMoney fields in the response for easier identification.

Query variables:

{ "merchantId": "8QJTJCEXAMPLE", "start": "2023-07-01T00:00:00+08:00", "end": "2023-07-01T23:59:59+08:00" }

Note

The Payment object is the source of truth for processing fees, but not all order tenders explicitly include a payment. In this case, you can query the Payments graph using the returned tender.id values, which represent payment IDs.

Example response:

Link to section

Get app fees for completed payments

Returns app fees earned for completed payments and deducted for refunds during a specified time period.

Developers should run this query using the access token and merchant ID of each Square seller account to report on.

Query:

This example uses a refundOrderId alias to rename the orderId field in the response when it applies to orders created for a refund.

Query variables:

{ "merchantId": "8QJTJCEXAMPLE", "start": "2023-07-01T00:00:00+08:00", "end": "2023-07-31T23:59:59+08:00" }

Response example:

Link to section

Get order details

Retrieves details about an order, including information about the associated customer, catalog items, and payment. Sellers might run this query if they want to collect order data and feed it into a different system or analytics software for reporting purposes.

Query:

Query variables:

{ "merchantId": "8QJTJCEXAMPLE", "orderId": "iMeAitUEv0KH1CAh6Nc2EXAMPLE" }

Example response:

Link to section

See also