Help with post variables to get Strip webhook data

I’m trying to pull some webhook data into my webhook. The other data I am able to extrapolate, just not sure what I"m doing wrong on trying to get the data that I need.

This is from my post variables:


And this is screenshot of the data I am trying to get to:

and here is the full json file:

{
  "id": "evt_1NAcw3Bm4iGyEaV7BuWODnqQ",
  "object": "event",
  "api_version": "2022-11-15",
  "created": 1684778059,
  "data": {
    "object": {
      "id": "cs_test_a1YtSy57hwxuXGjH7GLbzJesW0fp4X44pTyspSySZdWEHiwSzXNu4QS6CV",
      "object": "checkout.session",
      "after_expiration": null,
      "allow_promotion_codes": false,
      "amount_subtotal": 29000,
      "amount_total": 29000,
      "automatic_tax": {
        "enabled": true,
        "status": "complete"
      },
      "billing_address_collection": "auto",
      "cancel_url": "https://stripe.com",
      "client_reference_id": "390684553355",
      "consent": null,
      "consent_collection": {
        "promotions": "none",
        "terms_of_service": "none"
      },
      "created": 1684778015,
      "currency": "usd",
      "currency_conversion": null,
      "custom_fields": [
        {
          "dropdown": {
            "options": [
              {
                "label": "Orthotics Module",
                "value": "orthoticsmodule"
              },
              {
                "label": "Prosthetics Module",
                "value": "prostheticsmodule"
              }
            ],
            "value": "orthoticsmodule"
          },
          "key": "module",
          "label": {
            "custom": "Module",
            "type": "custom"
          },
          "numeric": null,
          "optional": false,
          "text": null,
          "type": "dropdown"
        }
      ],
      "custom_text": {
        "shipping_address": null,
        "submit": null
      },
      "customer": "cus_NwVxs8o3zK9G6v",
      "customer_creation": "always",
      "customer_details": {
        "address": {
          "city": "Osage Beach",
          "country": "US",
          "line1": "65065",
          "line2": "1325 Spindrifter Ct",
          "postal_code": "65065",
          "state": "MO"
        },
        "email": "baubeis@protonmail.com",
        "name": "Jules Verne",
        "phone": null,
        "tax_exempt": "none",
        "tax_ids": [

        ]
      },
      "customer_email": null,
      "expires_at": 1684864414,
      "invoice": "in_1NAcw0Bm4iGyEaV7GDDzV4Sm",
      "invoice_creation": null,
      "livemode": false,
      "locale": "en",
      "metadata": {
      },
      "mode": "subscription",
      "payment_intent": null,
      "payment_link": null,
      "payment_method_collection": "always",
      "payment_method_options": null,
      "payment_method_types": [
        "card",
        "link",
        "cashapp"
      ],
      "payment_status": "paid",
      "phone_number_collection": {
        "enabled": false
      },
      "recovered_from": null,
      "setup_intent": null,
      "shipping_address_collection": null,
      "shipping_cost": null,
      "shipping_details": null,
      "shipping_options": [

      ],
      "status": "complete",
      "submit_type": null,
      "subscription": "sub_1NAcw0Bm4iGyEaV7v8FtJOIw",
      "success_url": "https://licensing.hitekfab.com/subscription-complete.aspx",
      "total_details": {
        "amount_discount": 0,
        "amount_shipping": 0,
        "amount_tax": 0
      },
      "url": null
    }
  },
  "livemode": false,
  "pending_webhooks": 2,
  "request": {
    "id": null,
    "idempotency_key": null
  },
  "type": "checkout.session.completed"
}

If no other objects are potentially added to custom_fields, then this will work:

$_POST.data.object.custom_fields[0].dropdown.value

But since it is an array, it is safe to assume there could be multiple values, so you need to do a lookup on some unique key:

$_POST.data.object.custom_fields.where('type', '==', 'dropdown')[0].dropdown.value

That did the trick Ken! Thanks a lot.

So how do you know that you would need to use the [0] index from looking at the JSON?

In the POST json, anything inside square brackets [ ] is an array. Arrays can be referenced by their index number, in this case 0, which is the first item in the array.

yeah that makes total sense! duh. I’ll know next time