How to get the Stripe subscription items from Strpe API on the server side (accessing nested list in API response)

In the app I am working on, a company admin user signs up and pays for subscription for 1 seat. Then he adds 4 more users, and I need to update his susbscription from 1 seat to 5 seats. In order to do that I can update the subscription item to 5 seats. However, I have trouble getting the subscription items from the subscription API response.

The subscrption API returns a list of subscription items in a nested list, items:data[ ] as “Get a Subscription body data”. It is not available in WF steps because it is a list. So how I can access the list in a WF step?

2

Here is what is availabe from the response in a WF step. I can’t find any reference to the list.

You cant iterate on a list if its action type is action make it data and then on a you can schedule a workflow on that list and add the user for which you are creating a subscription id.

Not fully got setuation when i be on my system i be in better position to help

Oh, you are saying because the api call return a list you were not able to access it, its not possible you definitely be able to access it in referencing that step.

Name can be a little annoying but can reference it.

Referencing nested objects in an API response is definitely confusing in Bubble. In case it’s helpful, ...object quantity is the property I reference to get the number of seats in a subscription from Stripe’s Update subscription webhook.
image

@davidb I need to get the subscription item id first in order to update the the quantiy of the subscription item.

I’m unclear on what ID you’re specifically trying to reference and whether you’re trying to update the number of seats in Bubble or in Stripe.

If you’re not already doing the following, considering implementing some or all as a means to facilitate managing subscription changes.

  • When you create a subscription in Stripe, save in your app whatever Stripe IDs you need to reference later.
  • When you create a subscription in your app, save in the Stripe’s subscription a metadata value comprising your app’s ID for the subscription.
  • Enable your apps’ users to manage their subscriptions via a Stripe customer portal.

I use checkout session API to create a subscription, which returns a subscription ID in the webhook, which I have saved.

https://api.stripe.com/v1/checkout/sessions

A subscription is a collection of subscription items. In this case, I only have 1 subscription item. I need to get the subscription item ID in order to update subscription item’s quantity. So I call the subscription API which returns a list of subscription items. Because the list is a nested list, I don’t know how to access the list.

Yeah I had a similar issue with the Stripe API.

The nested elements will appear in the response if they are available. So if the elements are not there it may mean you need to make a different call.

So from a very generalistic pointing of view, I had an unexpected situation which may be similar. SO what I was doing was setting up subscriptions. And they could either be set up on the back on a full payment or on the back of deferred payment (intent).

What I learned was on the full payment the nested JOSN I was expecting to be there was, but when I used the same API for the deferred payment, the data wasn’t.

So I had to put in a conditional to make a slightly different call for the deferred payment through the intents API rather than the payment API to get the data I needed.

I suspect there is something similar going on there for you.

@alan8

The data (subsription item list) exists. It is there when I initialize the API. It is the same subsctiption ID that I use in the app. The problem is that Bubble does not show a nested list in WF step. So the solution is to find out how to access a nested list in Bubble or find a different way to get the subscription items that is not in a nested list. :sweat_smile:

If you compare these two screenshots you will the raw API data in the call returned from the call to Stripe and then the data as shown in the editor. It returns the nested data as a list within the list.

What you need to do is to go down to the nest parts and then look at the sub items in there and select those - as shown below.

Otherwise the other way to do it, is to make the call two part. You can call the nested elements directly with another API call if you know the ID to make that call rather than rely on it being nested.

I don’t see that type of options in the drop down.

Ah OK, have you asked the API to expand the sub elements? See my example here:

I have removed all expansions. It doens’t make any difference.

I notice from your video you have body in the list twice (I think). Click the one further down the list. That may be hiding the body subset.

I also see you have the body object (see what that reveals).

also the other thing is, when you initialise the API, it is always (as in the your screen shot) for a very specific subscriptions ID.

That is the ideal scenario. Where as in practice, the data may not exist in your actual real life call to the same API with a live ID - for various reasons, but broadly speaking because the use case is not there.

What I do in situations like this is work through an example in postman, and make the call as you step through.

Or, the other way to debug is to set up a database table where you print the data to the table during the workflow (using it like a log file). Create a new row for each step in the work flow and you can see the real request/reponse data and you will soon see why data you are expecting is missing (I find this a much more efficient way to debug, bs the live debugger, which often skips ahead or behind of the real request and can be very tedious).

You need to see the real data going back and forth and then inspect it to see where the error is.

I use the same subscription ID in the API Connector and in the WF because I only have 1 subscription. But the issue is not the miss data. The problem is that I can’t get the subscription item list in the WF step to access the subscription item ID field to assign it to a DB field. On your screenshot, you can see each item’s id, etc. I don’t see those.

I have resolved the issue. The dropdown does show the list. It may be under “object” or other field name that is not obvious.

1 Like