Folks:
I’m attempting to build an integration application in C# which talks to the Square API. The application will be calling multiple API endpoints to poll changed data, and I was hoping that I could develop a single consistent, reusable pattern to access the list/search API endpoints, which are very similar to each other - but the Square .Net SDK is not allowing me to do that.
For example, the Customers.SearchAsync()
method returns a SearchCustomersResponse
object that contains one page of data plus the cursor
value for the next page, if there is any. This is simple and mirrors the actual API definition and allows me to explicitly code pagination in a manner our application already supports.
However, the GiftCards.Activities.ListAsync()
method has similar parameters but returns a Pager<GiftCardActivity>
that encapsulates the pagination details. Even though the ListActivitiesRequest
object has a Cursor
property, there is no apparent way to get the cursor value from the current page to provide to a request for the next page, so that a code pattern consistent with customer search could be used.
The GiftCards.Activities.ListAsync()
method does have exactly what I want, it just doesn’t expose it for public use:
private async Task<ListGiftCardActivitiesResponse> ListInternalAsync(
ListActivitiesRequest request,
RequestOptions? options = null,
CancellationToken cancellationToken = default
)
{
...
}
The GiftCards.ListAsync()
method has the same problem: the only way to use it is via the provided Pager<GiftCard>
wrapper which encapsulates the details of pagination.
This inconsistency, and the way it blocks creating list/search API request code using one reusable pattern, is extremely frustrating.
It’s fine having a client method that returns a Pager
that hides all of the details of pagination for large response sets to make it easier to code for the API, but not when that comes at the cost of not being able to manage pagination myself if I wish to.
Please have the SDK provide consistent access methods across all of the endpoints, as far as possible, to allow an application to use either approach (explicit paging, or implicit “automatic” paging behind a Pager
) as needed: either expose the ListInternalAsync()
method for use somehow, or expose the current page’s “next page” cursor value in the Page<TItem>
object..
Neither of the workarounds that I see - using reflection to access the private list method, or using a local fork of the Square SDK library with custom changes - are appealing.
Thank you.