Skip to Main Content
  • Questions
  • Receiving Webhook Events from Stripe Payment Processing

Breadcrumb

Question and Answer

Connor McDonald

Thanks for the question, Dwain.

Asked: March 03, 2024 - 3:36 am UTC

Last updated: April 30, 2024 - 4:43 am UTC

Version: 23.2.2

Viewed 100+ times

You Asked

Here is my challenge. I am developing an application that receives webhook notifications when events occur. I have successfully used the restful services functionality in Apex (SQL Workshop>Restful Services) to retrieve data at the first (root?) level successfully. From the "request" sent from stripe below I can use paramters to retrieve the id, object, api_version, created, etc. but fail to retrieve the data.object.id or anything nested at a lower level. (apologies if I am using wrong descriptors here).

I have tried two approaches unsuccessfully:
1) a number of ways to identify the field as a parameter in the handler without success
2) retrieve the full json payload using :body, :body_text, :payload, :json_payload, etc.

Any guidance on how I could identify specific fields lower in the hierarchy (example: the data.object.id with value "cus_PfPbVdZHzvJq0E" below) as a parameter? Or, any guidance on how I could grab the full json payload?

Any guidance is appreciated.

Dwain


{
"id": "evt_1Oq4mjJ861pVT3w2L6jYiwce",
"object": "event",
"api_version": "2018-02-28",
"created": 1709432897,
"data": {
"object": {
"id": "cus_PfPbVdZHzvJq0E",
"object": "customer",
"account_balance": 0,
"address": null,
"balance": 0,
"created": 1709432896,
"currency": null,
"default_currency": null,
"default_source": null,
"delinquent": false,
"description": null,
"discount": null,
"email": "mike@dc.com",
"invoice_prefix": "2420987A",
"invoice_settings": {
"custom_fields": null,
"default_payment_method": null,
"footer": null,
"rendering_options": null
},
"livemode": false,
"metadata": {
},
"name": "mike",
"next_invoice_sequence": 1,
"phone": null,
"preferred_locales": [
],
"shipping": null,
"sources": {
"object": "list",
"data": [
],
"has_more": false,
"total_count": 0,
"url": "/v1/customers/cus_PfPbVdZHzvJq0E/sources"
},
"subscriptions": {
"object": "list",
"data": [
],
"has_more": false,
"total_count": 0,
"url": "/v1/customers/cus_PfPbVdZHzvJq0E/subscriptions"
},
"tax_exempt": "none",
"tax_ids": {
"object": "list",
"data": [
],
"has_more": false,
"total_count": 0,
"url": "/v1/customers/cus_PfPbVdZHzvJq0E/tax_ids"
},
"tax_info": null,
"tax_info_verification": null,
"test_clock": null
}
},
"livemode": false,
"pending_webhooks": 1,
"request": {
"id": "req_KtKtxAnXwioenZ",
"idempotency_key": "7263ed4a-0295-4a4e-a0b8-d7d3bf7f03b3"
},
"type": "customer.created"
}

and Connor said...

Not entirely sure what you are asking here, but as long as its JSON you can extract fields with simple dot notation

SQL> with t as (
  2  select treat(
  3  '{
  4  "id": "evt_1Oq4mjJ861pVT3w2L6jYiwce",
  5  "object": "event",
  6  "api_version": "2018-02-28",
  7  "created": 1709432897,
  8  "data": {
  9  "object": {
 10  "id": "cus_PfPbVdZHzvJq0E",
 11  "object": "customer",
 12  "account_balance": 0,
 13  "address": null,
 14  "balance": 0,
 15  "created": 1709432896,
 16  "currency": null,
 17  "default_currency": null,
 18  "default_source": null,
 19  "delinquent": false,
 20  "description": null,
 21  "discount": null,
 22  "email": "mike@dc.com",
 23  "invoice_prefix": "2420987A",
 24  "invoice_settings": {
 25  "custom_fields": null,
 26  "default_payment_method": null,
 27  "footer": null,
 28  "rendering_options": null
 29  },
 30  "livemode": false,
 31  "metadata": {
 32  },
 33  "name": "mike",
 34  "next_invoice_sequence": 1,
 35  "phone": null,
 36  "preferred_locales": [
 37  ],
 38  "shipping": null,
 39  "sources": {
 40  "object": "list",
 41  "data": [
 42  ],
 43  "has_more": false,
 44  "total_count": 0,
 45  "url": "/v1/customers/cus_PfPbVdZHzvJq0E/sources"
 46  },
 47  "subscriptions": {
 48  "object": "list",
 49  "data": [
 50  ],
 51  "has_more": false,
 52  "total_count": 0,
 53  "url": "/v1/customers/cus_PfPbVdZHzvJq0E/subscriptions"
 54  },
 55  "tax_exempt": "none",
 56  "tax_ids": {
 57  "object": "list",
 58  "data": [
 59  ],
 60  "has_more": false,
 61  "total_count": 0,
 62  "url": "/v1/customers/cus_PfPbVdZHzvJq0E/tax_ids"
 63  },
 64  "tax_info": null,
 65  "tax_info_verification": null,
 66  "test_clock": null
 67  }
 68  },
 69  "livemode": false,
 70  "pending_webhooks": 1,
 71  "request": {
 72  "id": "req_KtKtxAnXwioenZ",
 73  "idempotency_key": "7263ed4a-0295-4a4e-a0b8-d7d3bf7f03b3"
 74  },
 75  "type": "customer.created"
 76  }' as json) c
 77  from dual
 78  )
 79  select t.c.data.object.id
 80  from t t;

DATA
--------------------------------------------------------------------------------------
cus_PfPbVdZHzvJq0E


More to Explore

JSON

Need more information on JSON? Check out the JSON dev guide for the Oracle Database