Get app subscription usage records only for current period

Hi,

the currentAppInstllation query on the GraphQL API returns the activeSubscriptions with the the current app subscription if it has any.

This AppSubscription object always reflects the current state of the current billing period with the respective field currentPeriodEnd and the line items.

If a app subscription is usage-based, the line items contains a AppSubscriptionLineItem with AppUsagePricing which has a cappedAmount and a balanceUsed. Again, the balanceUsed reflects the state of the current billing period.

Now, in contrast, the usageRecords on the line item contain all records ever created. It is not limited to the current billing period. I think a common use case, at least for me, is to get all usage records for the current period to determine what was already charged.

This is not easily possible, as we have to paginate through all the usage records and check if their creation date is within the current period, which we have to calculate ourselves by using the currentPeriodEnd and subtracting the interval length (30 or 365 days).

Since there is a dedicated appUsageRecordsCreate mutation, I’d like to suggest a query counterpart like appUsageRecords($subscriptionLineItemId) and currentAppUsageRecords($subscriptionLineItemId) which only returns records for the current period.

This would make working with billing API much easier.

Hey @zirkelc :waving_hand: - thanks for reaching out here. You’re right, at the moment, the easiest way to grab that info is to query on the usageRecord object itselg when running an AppSubscription query AppSubscription - GraphQL Admin

You can paginate the query to segment over a specific amount of time/sort the order by the CREATED_AT value, but it definitely would make things a lot easier to have a dedicated appUsageRecords query. I’ll log this as a feature request on my end here - let me know if I can add any share any more feedback internally!

1 Like