Is the subscriptiongroupidentifieritem data in the Get All Subscription Statuses response sorted

Hi, I want to fetch the latest status of a subscription when we have the original transaction id. Using the suggested API: Get All Subscription Statuses can we assume the response is ordered? Is there a way to fetch the current status or fetching only the lastest transaction data?

Replies

Hello,

If you're looking for the current status of a user's subscription in your app, the Get All Subscription Statuses endpoint is the correct one to use. You'll want to call the endpoint and provide a transactionId of the user in the path; an originalTransactionId works too. The StatusResponse contains the data array, and each entry in this array corresponds to a single subscription group, identified by the subscriptionGroupIdentifier field in the SubscriptionGroupIdentifierItem:

https://developer.apple.com/documentation/appstoreserverapi/subscriptiongroupidentifieritem

If you're looking for the updated status of a specific subscription, first find the appropriate SubscriptionGroupIdentifierItem using the subscriptionGroupIdentifier of that subscription. Then, check the lastTransactions array. This array contains an entry for each entitlement the user has for the subscription; typically this will mean just a single entry, but it could be multiple if the user had access to the sub through a personal purchase as well as a family-shared purchase. In the lastTransactions array you can find the lastTransactionsItem entry with the matching originalTransactionId that you're looking for:

https://developer.apple.com/documentation/appstoreserverapi/lasttransactionsitem

The status in this entry is what you're looking for. You might also find the signedTransactionInfo and signedRenewalInfo useful, as these signed objects contain the most up-to-date transaction and renewal information for the subscription. None of the arrays I mentioned have a sorting guarantee, but because Get All Subscription Statuses contains only the most up-to-date information for each subscription, you shouldn't need to do any sorting.

Another way to stay up-to-date with the status of subsscriptions is using App Store Server Notifications V2; each notification sent for auto-renewable subscriptions also contains the status of the subscription at the time the notification was generated:

https://developer.apple.com/documentation/appstoreservernotifications/data

Let me know if you have any follow-up questions or need clarification.