Webhook receiving raw JSON

I’m creating my first webhook and having trouble getting the values to insert into a db record. The insert is happening (the record is created) however all the post values are null.

Here is the incoming json:

{
  "error": null,
  "item_id": "A33VGE7MZBCKrenEkzlPcnldroXXjyf1Naklq",
  "new_transactions": 17,
  "webhook_code": "INITIAL_UPDATE",
  "webhook_type": "TRANSACTIONS"
}

And the server action:

I’m assuming I’m doing something wrong here…ideas?

Thanks,

–Ken

To clarify this post…

I am receiving a webhook POST from an external vendor, which sends raw JSON. Is there a way to reference the data?

Hi Ken,

Are you sure the input is a JSON string and not a separate POST fields?

You can see the exact input if you use service like https://webhook.site/ to receive the API call.

So pass it through there and see how it calls you.

Thanks @George. Routing through an intermediary is actually how I captured the json posted above. Also, the documentation seems to confirm this…

The Plaid API uses POST requests to communicate and HTTP [response codes] to indicate status and errors. All responses come in standard [JSON]. The Plaid API is served over HTTPS TLS v1.1+ to ensure data privacy; HTTP and HTTPS with TLS versions below 1.1 are not supported. All requests must include a Content-Type of application/json and the body must be valid JSON.

Isn’t it fairly common to have a json response? Or am I missing something here?

Appreciate the help, and I really enjoy working in Wappler. :blush:

Hi Ken,

Currently we do not support raw JSON request to server connect actions yet. Some API’s post those indeed (like Stripe Webhooks) but most of the API’s use regular POST/GET variables.

Can you post here the exact headers and request body of the webhook you are making? As received from the webhook.site . You can blur any private keys if you any.

Then we can see how difficult it is to implement and what exactly your webhook gets.

Also which server model are you using? PHP?

Thanks George,

Funny you should mention stripe, because I use that webhook as well – these are both critical to our app, so hoping you can deliver on this! And yes, PHP7. It’s all sandbox stuff, so no worries on keys.

Here is the header output:

connection close
x-forwarded-for 52.21.26.131
cache-control max-age=259200
host webhook.site
accept-encoding gzip
content-type application/json
content-length 169
user-agent Go-http-client/1.1

And the body:

{
  "error": null,
  "item_id": "4obwBvv8LvHrlweWWNdLcER3G1lzJaFdvQ9JX",
  "new_transactions": 16,
  "webhook_code": "INITIAL_UPDATE",
  "webhook_type": "TRANSACTIONS"
}

EDIT: I should add, there are other webhooks from plaid that have more complex structures such as:

{
  "webhook_type": "TRANSACTIONS",
  "webhook_code": "TRANSACTIONS_REMOVED",
  "item_id": "wz666MBjYWTp2PDzzggYhM6oWWmBb",
  "removed_transactions": [
    "yBVBEwrPyJs8GvR77N7QTxnGg6wG74H7dEDN6",
    "kgygNvAVPzSX9KkddNdWHaVGRVex1MHm3k9no"
  ],
  "error": null
}

and

{
  "webhook_type": "ITEM",
  "webhook_code": "ERROR",
  "item_id": "wz666MBjYWTp2PDzzggYhM6oWWmBb",
  "error": {
    "display_message": "The provided credentials were not correct. 
Please try again.",
    "error_code": "ITEM_LOGIN_REQUIRED",
    "error_message": "the provided credentials were not correct",
    "error_type": "ITEM_ERROR",
    "status": 400
  }
}

Well good news - seems we have already partial implementation for this :slight_smile:

@patrick will investigate further and send you a test file, so you will be able to handle JSON input indeed just as regular post data.

1 Like

More than good news, GREAT news! Yes, @patrick sent over a file revision, which is working well in my initial tests. This was a real blocker for me, so I’m very appreciative of the quick turn-around on this.

Thanks @George and @patrick!

1 Like

Hi @mebeingken - I’m now at the stage of setting up webhooks for my Stripe implementation. Can you share what @patrick supplied you with or anything that would be helpful to me to get this working?

Cheers, Jon.

Hey Jon,

Actual nothing to share, as this has been in Wappler regular release for several weeks now. You can treat JSON exactly the same way you treat form fields using the $_POST process.

Here is an example of a webhook:

1 Like

Brilliant, thanks for that. This should keep me busy for a little while :slight_smile:

It case it’s not obvious…this is a webhook from Plaid, not Stripe…just showing how you can deal with the JSON.

Yep, I thought that was the case. I’m using webhook.site to see everything Stripe is sending me and building the webhook with that structure.

One (possibly daft) question. Am I right that the URL to the webhook file would be something like…

mydomain.com/dmxConnect/api/Stripe/webhook_endpoint.php

Or am I making a big mistake from the start?!

That’s correct.

1 Like

Hmm, the webhook is running and inserting a record but with no data. I’ve created the Insert action using post variables. Are you sure that’s correct? Your screenshot indicates it is but I’m just inserting blank records. Is there anything else I need to do?

The start of the JSON which is posted to the webhook is:

{
  "id": "evt_1FHzEuFybDEIfVSlJkOlnhjF",
  "object": "event",
  "api_version": "2019-08-14",
  "created": 1568321404,
  "data": {
    "object": {
      "id": "ch_1FHzEtFybDkIfVSlZ3NJntAt",
      "object": "charge",
      "amount": 2500,
      "amount_refunded": 0,
      "application": null,
      "application_fee": null,
      "application_fee_amount": null,
      "balance_transaction": "txn_1FHzEuFybDkIfVSl80OgtSs4",

so my first two fields are:

{{$_POST.id}}
{{$_POST.data.object.id}}

Yep, this is working perfectly for me. I don’t think there is anything extra to add.

I’m not immediately seeing what would be wrong with what you are doing though.

Thanks again. I shall persevere.

I’m assuming you created the POST variables, ya? And that you have updated Wappler over the last couple months?

OK, I think I’ve found the issue.

Does Plaid send it’s data as form-data? Stripe is sending it as JSON in the body and it looks like Wappler can’t access that via the {{$_POST.id}} field.

@patrick, @George, @Teodor - am I right? How can I access the JSON in the body?

I update Wappler every Thursday :wink:

What do you mean by ‘created the POST variables’?

I’ve added POST variables in the Globals section. There’s a line titled ‘Linked Field’ but I’ve no idea what that’s for.