Skip to content

Webhook Error: checkout.session.completed #5

@kavicastelo

Description

@kavicastelo

Description

While handling the checkout.session.completed event, the webhook fails with the following error message:

Webhook error: Invalid null ID found for url path formatting. This can be because your string ID argument to the API method is null, or the ID field in your stripe object instance is null. Please contact support@stripe.com on the latter case.

This error occurs intermittently, and the event seems to be passing null values or missing fields to the backend. The event data payload includes the expected metadata (company_id) and other relevant information, but the processing fails because of missing or null IDs.

Reproducing the Issue

  • Use the Stripe CLI to simulate the checkout.session.completed event or trigger the event in live mode.
  • Verify the payload sent to the webhook URL.
  • Observe the error in the backend logs.

Observed Behavior

-The webhook handler logs the following error:

Webhook error: Invalid null ID found for url path formatting.
  • The payload for checkout.session.completed includes valid metadata and other fields, but:
    • request.id is null.
    • Some optional fields (e.g., client_reference_id) are also null as expected for this context.
  • The backend receives this data but fails to process it due to the null ID in the URL path.

Payload Example

  • Here is a sample payload received for the checkout.session.completed event:
{
  "id": "evt_1QcTEqA9kBiWDgfZH8PBOi1F",
  "object": "event",
  "api_version": "2024-12-18.acacia",
  "created": 1735742976,
  "data": {
    "object": {
      "id": "cs_live_a1w74IcNwXiIKnEEdGftbFfg3bqNBGsazMS5w9sxMsgekWbepEuPdYwars",
      "object": "checkout.session",
      ...
      "metadata": {
        "company_id": "673b3a81c3a2b76a3ff6cbd2"
      },
      ...
      "subscription": "sub_1QcTDzA9kBiWDgfZ10X0646g",
      ...
    }
  },
  ...
  "request": {
    "id": null,
    "idempotency_key": null
  },
  "type": "checkout.session.completed"
}

Expected Behavior

  • The webhook should process the checkout.session.completed event without errors.
  • Metadata (company_id) and other fields should be correctly passed to the backend.
  • The request.id field should not be null if it is required for path formatting.

Additional Context

  • Similar to the invoice.created event, the checkout.session.completed webhook seems to intermittently send null or missing data for certain fields.
  • Both events (invoice.created and checkout.session.completed) occasionally fail when multiple events are sent to the backend simultaneously.
  • Stripe's Dashboard shows these events as delivered successfully, but the backend fails with 400 errors for these events.

Attempts to Resolve

  • Logged the raw event payload to inspect missing or null fields.
  • Verified the backend code to handle potential null values, but the error persists.
  • Reproduced the issue by triggering multiple events simultaneously; observed the intermittent nature of this issue.
  • Checked Stripe's API version compatibility (2024-12-18.acacia).

References

Invoice.created issue discussion

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workinghelp wantedExtra attention is needed

    Type

    No type
    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