#scmitton
1 messages · Page 1 of 1 (latest)
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?
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
if you retrieve subscription.items.data[0] what do you get?
I believe it will give this same error: 'builtin_function_or_method' object has no attribute 'data'
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?
print(subscription.items)
print(subscription.items.str()) both return : <built-in method items of Subscription object at 0x107e81490>
can you share the output in json
This is the output of event.data.object, with id's redacted:
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.
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
Same 'builtin_function_or_method' object has no attribute 'data'
you're using python?
Yes
gimme a while to get back to you
Ok
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.
this worked for me
event = json.loads(payload)
price = event['data']['object']['items']['data'][0]['price']['id']
Hi @tough imp I'm taking over