#mxd-access-json
1 messages · Page 1 of 1 (latest)
productsubscription = event['data']['object']['items']['data']['plan']['id'] TypeError: string indices must be integers
im trying to get the id value, any tips on how to achieve this goal?
Is plan an object in this context? It's possible you just need to remove that final ['id']
ok thanks for the help!
mxd-access-json
@limpid stratus the second data is an array and you don't need the bracket if you have deserialized the Event already so you should be able to do event.data.object.items.data[0].plan.id
AttributeError: 'dict' object has no attribute 'data'
ah you use python I assume? Sorry you gave no context at all here. But stripe-python has an edge-case because we use dict for all objects so you have to special-case items too
event.data.objectitems.data[0].plan.id
yeah its so tricky, same error ```
productsubscription = event.data.objectitems.data[0].plan.id
AttributeError: 'dict' object has no attribute 'data'```
Did you deserialize the Event? Did you follow our docs? Sorry I just assumed you were following https://stripe.com/docs/webhooks/quickstart which explains how to go from JSON to a real Event instance
yeah im using the exact same code
ill keep trying to parse the json until i get the id
well you're not since that code de-serializes an Event and shows you how to cast then in another resource
and you seem to just access the JSON which you don't need to
can you share real code with multiple lines around this?
payment_intent = event['data']['object'] # contains a stripe.PaymentIntent```
like we say this, so event['data']['object'] in your case should be a stripe.Subscription right?
yeah
You said "yeah" but is it? What did you try What's your exact code? What do you see when you log?
testing it now
[Tue Nov 29 17:48:21.522000 2022] [wsgi:error] [pid 483567:tid 140415815821056] [client 54.187.174.169:50379] File "/usr/local/lib/python3.7/dist-packages/stripe/stripe_object.py", line 85, in __getattr__
[Tue Nov 29 17:48:21.522004 2022] [wsgi:error] [pid 483567:tid 140415815821056] [client 54.187.174.169:50379] raise AttributeError(*err.args)
[Tue Nov 29 17:48:21.522008 2022] [wsgi:error] [pid 483567:tid 140415815821056] [client 54.187.174.169:50379] AttributeError: objectitems```
what is objectitems?
if event['type'] == 'customer.subscription.created':
subscription = event['data']['object']
#activemembership = request['data']['object']
activemembership = 'YES'
# bronze: price_1M2H21LOEVMWAWDDt5NZ1Qki // object>data>object>items>data>0>plan>id
#productsubscription = event['data']['object']['items']['data']['plan']['id']
productsubscription = event.data.objectitems.data[0].plan.id
that doesn't give me more info, that's just more code. What's objectitems? What does subscription look like? What don't you use that object?
whats objectitems idk you wrote that part productsubscription = event.data.objectitems.data[0].plan.id
trying again with a dot after object
ahhhhh sorry, I mistyped, didn't realize that came from me
if event['type'] == 'customer.subscription.created':
subscription = event['data']['object']
price_id = subscription['items'].data[0].price.id```
this should work
['items'] is special for stripe-python, it's not needed for anything else but that specific property name
Of course, I'm sorry it's such a pain to grasp webhooks in python
we want to add clear "types" to stripe-python in the future for all resources which will hopefully makes this way easier
thanks again