Search code examples
paginationsquare-connect

How to paginate Payment list using SquareConnect V1 java SDK?


SquareConnect V1 documentation indicates that pagination is supported using the Link, as shown below, in response header.

Link:<https://connect.squareup.com/v1/LOCATION_ID/payments?batch_token=BATCH_TOKEN>;rel='next'

How do I list all payments for a location, in the given date range, say 6 months, using JavaSDK? listPayments method does not provide a return value with access to pagination.

List<V1Payment> result = apiInstance.listPayments(locationId, order, beginTime, endTime, limit);

Is the only way to paginate is by slicing the date range? If so, depending on the slice size,

  • one might either miss transactions, as the limit is 200, if the time slice is too large
    • OR hit the request rate threshold, if the time slice is too small.

Appreciate any help.


Solution

  • If you have a time based segment (such as all transactions for the last six months) you should use the the time segment in the request and then paginate through all the responses.

    The issue you are running into here is that the header based pagination tokens are not exposed in the SDK for the v1 endpoints, (nor would you be able to easily override the url with their results). You can either:

    • Use v2 transaction endpoints which do not use header/link based pagination
    • Slice the date range and iterate, like you mentioned (with its associated challenges)
    • Not use the SDK, and just call the v1 endpoints with your java code directly
    • Use some of the underlying methods of the SDK (like InvokeAPI which would be a blend between using the SDK and calling the endpoints directly.