# Webhook delivery errors when length is incorrect

**URL:** https://meta.discourse.org/t/webhook-delivery-errors-when-length-is-incorrect/49912
**Category:** Support
**Created:** [September 8, 2016, 10:09pm UTC](https://meta.discourse.org/t/webhook-delivery-errors-when-length-is-incorrect/49912 "2016-09-08T22:09:01Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![rhyolight](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/rhyolight/32/120422_2.png) [@rhyolight](https://meta.discourse.org/u/rhyolight)
#### Post date: [September 8, 2016, 10:09pm UTC](https://meta.discourse.org/t/webhook-delivery-errors-when-length-is-incorrect/49912/1 "2016-09-08T22:09:01Z")

</div>

Some of the HTTP requests being sent to one of my webhooks are being returned with 400 errors. From what I can tell on the client of these requests, it seems like the request body might be getting cut short, or that the `Content-Length` of the requests doesn’t match the POST body.

For you admins on our hosted instance, you can see the webhook deliveries [here](https://discourse.numenta.org/admin/web_hooks/1/events).

 ![](https://global.discourse-cdn.com/meta/original/3X/7/6/76c80d12d7d6fe87bd71b7de009e5efd643efd61.png)

I cannot tell why some of these requests are valid and some are not. The same logic is processes each request and just logging it to console. From inspecting them in the UI, they all look good, but some of them returned 400. The server logs show `SyntaxError: Unexpected end of input` which leads me to believe the JSON is possibly invalid because the POST body was cut short?

Any ideas?

---

<div class="post-metadata">

### Author: ![tgxworld](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/tgxworld/32/106117_2.png) [@tgxworld](https://meta.discourse.org/u/tgxworld)
#### Post date: [September 9, 2016, 1:12am UTC](https://meta.discourse.org/t/webhook-delivery-errors-when-length-is-incorrect/49912/2 "2016-09-09T01:12:43Z")

</div>

> [@rhyolight](#):
>
> The server logs show SyntaxError: Unexpected end of input which leads me to believe the JSON is possibly invalid because the POST body was cut short?

Does your server log all requests that it receives? That’ll help us determine if the request or its body is invalid or not.

---

<div class="post-metadata">

### Author: ![rhyolight](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/rhyolight/32/120422_2.png) [@rhyolight](https://meta.discourse.org/u/rhyolight)
#### Post date: [September 9, 2016, 3:56pm UTC](https://meta.discourse.org/t/webhook-delivery-errors-when-length-is-incorrect/49912/3 "2016-09-09T15:56:57Z")

</div>

So I just replicated this error locally with curl based upon the last failing webhook I saw. I extracted the JSON POST body, minified it, and sent it along with the headers Discourse used when sending the data. I saw that upon minifying the JSON POST body, it was not the same size in bytes as the `Content-Length` header used by Discourse, so my curl command failed. When I changed the `Content-Length` to match the number of bytes actually in the POST body, it worked.

So the problem is that the `Content-Length` _sometimes_ does not match the number of bytes in the POST body, causing JSON parsing to fail because the entirely of the JSON CLOB was not loaded.

---

<div class="post-metadata">

### Author: ![tgxworld](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/tgxworld/32/106117_2.png) [@tgxworld](https://meta.discourse.org/u/tgxworld)
#### Post date: [September 22, 2016, 7:28am UTC](https://meta.discourse.org/t/webhook-delivery-errors-when-length-is-incorrect/49912/4 "2016-09-22T07:28:00Z")

</div>

@rhyolight Can you provide me with the curl command to reproduce the issue? 🙂 Thanks!

---

<div class="post-metadata">

### Author: ![rhyolight](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/rhyolight/32/120422_2.png) [@rhyolight](https://meta.discourse.org/u/rhyolight)
#### Post date: [September 30, 2016, 3:44pm UTC](https://meta.discourse.org/t/webhook-delivery-errors-when-length-is-incorrect/49912/5 "2016-09-30T15:44:15Z")

</div>

Everything is working properly since 2016-09-21, so no need to continue with this thread. 🙂

---

<div class="post-metadata">

### Author: ![Falco](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/falco/32/179432_2.png) [@Falco](https://meta.discourse.org/u/Falco)
#### Post date: [September 30, 2016, 3:48pm UTC](https://meta.discourse.org/t/webhook-delivery-errors-when-length-is-incorrect/49912/6 "2016-09-30T15:48:34Z")

</div>


