#mikebm - expanding object

1 messages ยท Page 1 of 1 (latest)

hallow python
#

Hi ๐Ÿ‘‹

#

Yeah I ran into this recently while trying to solve someone else's problem. It's a max expansion depth problem.

grizzled tartan
#

Yep

hallow python
#

Unfortunately this meant I had to separate my approach into two API calls. One to expand down to the price object.

#

Then using the associated product_id field to retrieve the product.

grizzled tartan
#

Yeah, this is what I was afraid of. Darn

hallow python
#

Well hold on

#

Do you have a request ID that triggered the error?

#

I want to double check

grizzled tartan
#

I know I had a request that resulted in max expansion depth on another query for this same issue.

This one right now is resulting in this

#

com.stripe.exception.InvalidRequestException: This property cannot be expanded (data.subscription.price).; request-id: req_COcyGZXPsiM75h

hallow python
#

Okay...yeah in this case you should be good to just exclude the data. portion for subscriptions.price.product

grizzled tartan
#

com.stripe.exception.InvalidRequestException: This property cannot be expanded (subscription). You may want to try expanding 'data.subscription' instead.; request-id: req_3XKkCigiEROzl0

#

oh oops, one sec

hallow python
#

Wait wait wait...

#

Is there a reason you want to go through the subscription?

grizzled tartan
#

Same exception -
com.stripe.exception.InvalidRequestException: This property cannot be expanded (subscriptions). You may want to try expanding 'data.subscriptions' instead.; request-id: req_ouGKmxU7Wn1vjd

hallow python
#

You could go from invoice.lines.data->expand price -> expand product

grizzled tartan
#

Well, basically, I want invoice lines yes

#

however, i think that is when I hit the max expansion limit

hallow python
#

Hold on, I'm going to test this myself

#

Alright, I used Python so the syntax may be a bit off but

stripe.Invoice.retrieve('in_1K7qghIlCeH6bP8RRGEKswRj', expand=['lines.data.price.product',])

worked for me

grizzled tartan
#

Trying... I think one of the challenges is I never know when data is needed, or something else.

hallow python
#

I honestly can't go a day without referencing them

#

That's where I found the lines.data attribute and then followed that to the description of the line_item object

grizzled tartan
#

Yeah, I am technically using Invoice.list right now so let me try with that structure. One sec

#

And there it is

#

com.stripe.exception.InvalidRequestException: You cannot expand more than 4 levels of a property; request-id: req_Hp4Sa0U4po7Lqg

#

Need me a table flip emoji hah

#

InvoiceListParams params =
InvoiceListParams.builder()
.setCustomer(usc.getStripe_customerID())
.setStatus(Status.PAID)
.setLimit(100L)
.addExpand("data.charge")
.addExpand("data.subscription")
.addExpand("data.lines.data.price.product")
.build();

        // .addExpand("data.lines.data.plan")

        InvoiceCollection ic = Invoice.list(params, RequestOptions.builder().build());
hallow python
#

okay, looking at this request

grizzled tartan
#

This is for an order history screen

hallow python
#

In your third expand parameter

grizzled tartan
#

Yes, the 100 limit sucks. Need to implement some pagination soon.

#

We don't have a lot of orders right now

#

per customer

hallow python
#

you don't need the first data

grizzled tartan
#

I do though, it gave an exception if i didn't use it

hallow python
#

so this "data.lines.data.price.product" becomes lines.data.price.product

grizzled tartan
#

said I needed data.lines

hallow python
#

OH...wait...

#

this is a list, right.

#

So because this is a list, it bumps the expansion past our limit of 4 levels. Sorry i didn't catch that earlier

grizzled tartan
#

yeah, no problem. I didn't really mention it until recently. My bad

hallow python
#

In that case my best advice would be the 2 request approach and cache your results.

#

Especially since it's order history you shouldn't need to get this data more than once.

grizzled tartan
#

yep. That was the path I was heading down already, I just didn't want to if i could avoid it. Thank you though.

#

I already will most likely have these in cache anyways since we cache product with all our sku and price fetches

hallow python
#

Yeah, the overhead and complexity struggles are real.

grizzled tartan
#

Well, awesome, appreciate the help! ๐Ÿ‘

hallow python
#

Any time ๐Ÿ‘