I need help getting the “cappedAmount” for the CURRENT usage based subscription plan (not past subscriptions). I’ve tried all of the examples on this page but they don’t work:
My code sample below (taken from the page above) is the closest to accomplishing this, but you have to use a lot of API credits to loop through all of the customer’s previous cancelled subscriptions to get to the CURRENT subscription plan.
If you notice the the part of my GQL code (line 3) that says “allSubscriptions(first: 99)” it’s using the number 99 in case someone uninstalls and re-installs the app many times (like I do for testing purposes).
QUESTION: How do I get the “last” subscription here? Like instead of “first:99” how do I get the very last result here? I have seen the example on the page for “currentAppInstallation” but didn’t get anywhere with it.
My output is below the code sample if you want to view it. The problem is that it eats up too many API credits to find the current “cappedAmount”. I’m happy to use the REST API if there is a simpler way to do this. Again, I just want to get the “cappedAmount” value of a current subscriber to our usage plan. Thank you friends.
===========================================================
My GQL:
query {
currentAppInstallation {
allSubscriptions(first: 10) {
edges {
node {
lineItems {
plan {
pricingDetails {
__typename
... on AppRecurringPricing {
price {
amount
currencyCode
}
}
... on AppUsagePricing {
balanceUsed {
amount
currencyCode
}
cappedAmount {
amount
currencyCode
}
}
}
}
}
createdAt
id
name
status
test
}
}
}
}
}
Outputs:
Array
(
[data] => Array
(
[currentAppInstallation] => Array
(
[allSubscriptions] => Array
(
[edges] => Array
(
[0] => Array
(
[node] => Array
(
[lineItems] => Array
(
[0] => Array
(
[plan] => Array
(
[pricingDetails] => Array
(
[__typename] => AppRecurringPricing
[price] => Array
(
[amount] => 10.0
[currencyCode] => USD
)
)
)
)
)
[createdAt] => 2022-11-14T01:59:16Z
[id] => gid://shopify/AppSubscription/27798241593
[name] => Super Duper Plan
[status] => EXPIRED
[test] =>
)
)
[1] => Array
(
[node] => Array
(
[lineItems] => Array
(
[0] => Array
(
[plan] => Array
(
[pricingDetails] => Array
(
[__typename] => AppRecurringPricing
[price] => Array
(
[amount] => 10.0
[currencyCode] => USD
)
)
)
)
)
[createdAt] => 2022-11-14T02:00:48Z
[id] => gid://shopify/AppSubscription/27798274361
[name] => Super Duper Plan
[status] => EXPIRED
[test] =>
)
)
[2] => Array
(
[node] => Array
(
[lineItems] => Array
(
[0] => Array
(
[plan] => Array
(
[pricingDetails] => Array
(
[__typename] => AppRecurringPricing
[price] => Array
(
[amount] => 10.0
[currencyCode] => USD
)
)
)
)
)
[createdAt] => 2022-11-14T02:06:15Z
[id] => gid://shopify/AppSubscription/27798307129
[name] => Super Duper Plan
[status] => EXPIRED
[test] =>
)
)
[3] => Array
(
[node] => Array
(
[lineItems] => Array
(
[0] => Array
(
[plan] => Array
(
[pricingDetails] => Array
(
[__typename] => AppRecurringPricing
[price] => Array
(
[amount] => 10.0
[currencyCode] => USD
)
)
)
)
)
[createdAt] => 2022-11-14T02:06:39Z
[id] => gid://shopify/AppSubscription/27798339897
[name] => Super Duper Plan
[status] => EXPIRED
[test] =>
)
)
[4] => Array
(
[node] => Array
(
[lineItems] => Array
(
[0] => Array
(
[plan] => Array
(
[pricingDetails] => Array
(
[__typename] => AppRecurringPricing
[price] => Array
(
[amount] => 10.0
[currencyCode] => USD
)
)
)
)
)
[createdAt] => 2022-11-14T02:06:49Z
[id] => gid://shopify/AppSubscription/27798372665
[name] => Super Duper Plan
[status] => EXPIRED
[test] =>
)
)
[5] => Array
(
[node] => Array
(
[lineItems] => Array
(
[0] => Array
(
[plan] => Array
(
[pricingDetails] => Array
(
[__typename] => AppRecurringPricing
[price] => Array
(
[amount] => 10.0
[currencyCode] => USD
)
)
)
)
)
[createdAt] => 2022-11-14T02:14:33Z
[id] => gid://shopify/AppSubscription/27798405433
[name] => Super Duper Plan
[status] => EXPIRED
[test] => 1
)
)
[6] => Array
(
[node] => Array
(
[lineItems] => Array
(
[0] => Array
(
[plan] => Array
(
[pricingDetails] => Array
(
[__typename] => AppRecurringPricing
[price] => Array
(
[amount] => 10.0
[currencyCode] => USD
)
)
)
)
)
[createdAt] => 2022-11-14T02:16:05Z
[id] => gid://shopify/AppSubscription/27798438201
[name] => Super Duper Plan
[status] => EXPIRED
[test] => 1
)
)
[7] => Array
(
[node] => Array
(
[lineItems] => Array
(
[0] => Array
(
[plan] => Array
(
[pricingDetails] => Array
(
[__typename] => AppRecurringPricing
[price] => Array
(
[amount] => 10.0
[currencyCode] => USD
)
)
)
)
)
[createdAt] => 2022-11-14T02:17:26Z
[id] => gid://shopify/AppSubscription/27798470969
[name] => Super Duper Plan
[status] => EXPIRED
[test] => 1
)
)
[8] => Array
(
[node] => Array
(
[lineItems] => Array
(
[0] => Array
(
[plan] => Array
(
[pricingDetails] => Array
(
[__typename] => AppRecurringPricing
[price] => Array
(
[amount] => 10.0
[currencyCode] => USD
)
)
)
)
)
[createdAt] => 2022-11-19T18:35:03Z
[id] => gid://shopify/AppSubscription/27850473785
[name] => Brian Groovy Plan
[status] => EXPIRED
[test] =>
)
)
[9] => Array
(
[node] => Array
(
[lineItems] => Array
(
[0] => Array
(
[plan] => Array
(
[pricingDetails] => Array
(
[__typename] => AppRecurringPricing
[price] => Array
(
[amount] => 10.0
[currencyCode] => USD
)
)
)
)
)
[createdAt] => 2022-11-19T18:41:52Z
[id] => gid://shopify/AppSubscription/27850604857
[name] => Brian Groovy Plan
[status] => EXPIRED
[test] =>
)
)
)
)
)
)
[extensions] => Array
(
[cost] => Array
(
[requestedQueryCost] => 43
[actualQueryCost] => 43
[throttleStatus] => Array
(
[maximumAvailable] => 1000
[currentlyAvailable] => 957
[restoreRate] => 50
)
)
)
)
Please help!