#scmitton

1 messages · Page 1 of 1 (latest)

maiden walrusBOT
lavish crest
#

hello! can you share the code snippet the event id, and what's the error message you're seeing when you say nothing seems to work?

tough imp
#

But I get this error: 'builtin_function_or_method' object has no attribute 'data'

#

It has to do with getting the price id

#

Woops, sorry, wrong handler: def handle_customer_subscription_created(self, event):
"""Create corresponding subscription in our database."""

    subscription = event.data.object
    price_id = subscription.items.data[0].price.id

    db_subscription = Subscription.objects.create(
        id=subscription.id,
        customer_id=subscription.customer,
        price_id=price_id,
        current_period_end=subscription.current_period_end,
        status=subscription.status,
        cancel_at_period_end=subscription.cancel_at_period_end,
        default_payment_method=subscription.default_payment_method,
        created=subscription.created,
        trial_start=subscription.trial_start,
        trial_end=subscription.trial_end,
    )
    db_subscription.save()
#

It has to do with the price id, all of the other attribute I can confirm are being accessed just fine via this api

lavish crest
#

if you retrieve subscription.items.data[0] what do you get?

tough imp
#

I believe it will give this same error: 'builtin_function_or_method' object has no attribute 'data'

lavish crest
#

can you verify bit by bit if every key you're accessing actually exists? for example, if you log subscription, subscription.items, etc, what do you get?

tough imp
#

print(subscription.items)
print(subscription.items.str()) both return : <built-in method items of Subscription object at 0x107e81490>

lavish crest
#

can you share the output in json

tough imp
#

Which in my code I then assign to subscription, and I try to access the data farther down with things like subscription.items.data, but I've gotten the errors I've previously mentioned.

lavish crest
#

can you access subscription.items.data?

#

without accessing a specific index in the array

#

there's no reason why it should fail since it clearly exists in the object

tough imp
#

Same 'builtin_function_or_method' object has no attribute 'data'

lavish crest
#

you're using python?

tough imp
#

Yes

lavish crest
#

gimme a while to get back to you

tough imp
#

Ok

maiden walrusBOT
tough imp
#

The farthest down the tree of the json I've been able to get is to items (event.data.object.items), which if I print that out is <built-in method items of Subscription object at 0x103955580>. I tried printing dir(event.data.object.items) and got this, ['call', 'class', 'delattr', 'dir', 'doc', 'eq', 'format', 'ge', 'getattribute', 'gt', 'hash', 'init', 'init_subclass', 'le', 'lt', 'module', 'name', 'ne', 'new', 'qualname', 'reduce', 'reduce_ex', 'repr', 'self', 'setattr', 'sizeof', 'str', 'subclasshook', 'text_signature']

#

Just trying to provide any information I can to help.

lavish crest
#

this worked for me

#

event = json.loads(payload)
price = event['data']['object']['items']['data'][0]['price']['id']

devout kraken
#

Hi @tough imp I'm taking over

tough imp
#

Yeah, that worked for me too. I can use this I suppose: subscription['items']['data'][0]['price']['id']

#

subscription = event.data.object