• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

JSON Webhooks

Contributor ,
Mar 09, 2019 Mar 09, 2019

Copy link to clipboard

Copied

Hello,

This is my first venture into webhooks. I am trying to read a response from ChargeOver and insert it into a database. For now, I am just dumping it to a txt file to see what it looks like. My current code is:

<cfset HTTPRequestData = deserializeJSON(ToString(getHTTPRequestData().content))>

<cfdump var="#form#" output="C:/webhook.txt">

The webhook is posting something like this:

{

  "context_str": "package",

  "context_id": "556",

  "event": "status",

  "data": {

    "package": {

      "terms_id": 2,

      "currency_id": 1,

      "external_key": null,

      "token": "ozevrx738b02",

      "nickname": "",

      "paymethod": "inv",

      "paycycle": "yrl",

      "bill_addr1": null,

      "bill_addr2": null,

...etc

My webhook.txt file shows over and over:

struct [empty]

************************************************************************************

What am I missing?

Thanks in advance!

Gary

Views

1.3K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Contributor , Mar 09, 2019 Mar 09, 2019

Figured out what I was doing wrong...

<cfset requestBody = toString( getHttpRequestData().content ) />

<cfset webhook = deserializeJSON( requestBody )>

    <cfdump

        var="#webhook#"

        label="HTTP Body" output="C:/webhook.txt"

        />

Votes

Translate

Translate
Community Expert ,
Mar 09, 2019 Mar 09, 2019

Copy link to clipboard

Copied

For this to work, a form had to be submitted to the current page. But it apparently wasn't.

It might help to add code to validate the form, like this

<cfif isDefined("form.fieldnames")>

    <cfdump var="#form#" output="C:/webhook.txt">

<cfelse>

No form was submitted.

</cfif>

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Mar 09, 2019 Mar 09, 2019

Copy link to clipboard

Copied

LATEST

Figured out what I was doing wrong...

<cfset requestBody = toString( getHttpRequestData().content ) />

<cfset webhook = deserializeJSON( requestBody )>

    <cfdump

        var="#webhook#"

        label="HTTP Body" output="C:/webhook.txt"

        />

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation