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
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"
/>
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>
Copy link to clipboard
Copied
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"
/>