Braintree documentation:
- Braintree GraphQL API
- Braintree pagination and relay connections
- Braintree creating transactions
- GraphQL pagination and edges
This article explains how to manage pagination in a Braintree GraphQL integration.
A. Before you begin
Create an integration flow with an import to Braintree. If you have not created the integration flow, see the Connect to the Braintree GraphQL API article or the Braintree GraphQL community post.
B. Select the integration flow
Open the integration flow you created that contains an import to Braintree. Here’s an example flow. You can substitute the destination endpoint in this example (NetSuite) with any similar app.
C. Edit the Braintree export or lookup in the flow
Open the Braintree export or lookup POST method and define the following pagination settings.
-
Under the What would you like to export? section in HTTP request body, define a query as shown. Change the value in the first parameter according to your requirements.
Initial search query
{
"query": "query InitialSearch($input: TransactionSearchInput!) { search { transactions ( input : $input, first: 20 ) { pageInfo { hasNextPage startCursor endCursor }, edges { node { id status } } } } }",
"variables": {"input": {"amount": {"value": {"greaterThanOrEqualTo": "0.00"}}}}
}This query returns 20 most recent transactions as nodes, each wrapped in an edge, with a cursor marking its place in the full result set based on the input search criteria. The value in the pageInfo parameter indicates whether there are more than 20 transactions that meet your search criteria.
{
"data": {
"search": {
"transactions": {
"edges": [
// ...19 prior nodes...
{
"node": {
"id": "transaction-id-for-last-result-in-list"
},
"cursor": "cursor-for-last-transaction-in-list"
}
],
"pageInfo": {
"hasNextPage": true
}
}
}
}
}
- Under the Does this API use paging? section in Override HTTP request body for subsequent page requests, define a query based on your requirements. Make sure that you change the value in the first parameter.
Second search query
{{#if data.data.search.transactions.pageInfo.hasNextPage}}
{
"query": "query SecondSearch($input: TransactionSearchInput!) { search { transactions ( input : $input, first: 20, after: \\"{{{data.data.search.transactions.pageInfo.endCursor}}}\\") { pageInfo { hasNextPage startCursor endCursor }, edges { node { id status } } } } }",
"variables": {"input": {"amount": {"value": {"greaterThanOrEqualTo": "0.00"}}}}
}
{{/if}}Based on the input search criteria, the query returns 20 different transactions, that is, the next 20 transactions created subsequent to the transaction indicated by the cursor-for-last-transaction-in-list parameter. When the hasNextPage parameter is
false
, there are no more objects that meet your search criteria and the last element in the list is the oldest object in your result set. - Optional: If you want to break the data being exported into one or more pages of records, under the Advanced section in Page size, specify the number of transaction groups you want on each page of data. (In these queries, 20 different transactions are returned as 1 group.)
Page size
If the Page size value is left blank, the default value is 20 records. There is no maximum value, but a page automatically gets capped when it exceeds 5 MB.
- Click Save & close.
D. Test the integration flow
Test your integration flow with the defined pagination settings. See API pagination to resolve any pagination issue in integrator.io.
Comments
Please sign in to leave a comment.