Skip to content

Better document how to reconstruct data object of Webhook events #1841

Description

@Viicos

Is your feature request related to a problem? Please describe.

The documentation currently recommends using stripe.Event.construct_from() to reconstruct the event object, and then access event.data.object to use the actual event data.

However, event.data.object is untyped (UntypedStripeObject[Any]). We currently do:

# Example to reconstruct `Subscription` object, but same applies for any object:
sub = stripe.Subscription.construct_from(
    event.data.object.to_dict(),
    key=None,  # The API key (required)
)

It would be nice if this was explicitly documented (in https://docs.stripe.com/webhooks): is it the expected way of reconstructing the object? do I need to call to_dict()? Also if this is the expected way, construct_from() would benefit from a proper docstring (I first got confused by the required key parameter. It does make sense to have it required, because an implicit None will mean you can't make operations from this object directly, which would be surprising for some users).

Describe the solution you'd like

No response

Describe alternatives you've considered

No response

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions