helpscout / helpscout-api-php

PHP Wrapper for the Help Scout API
MIT License
98 stars 62 forks source link

400 Bad Request response #284

Closed jonathanbull closed 2 years ago

jonathanbull commented 2 years ago

Current behavior

Our application regularly creates conversations in Help Scout using ->conversations()->create($conversation).

At 2022-01-24 21:30:02 UTC we received the following response from the API for one of those calls:

Client error: `POST https://api.helpscout.net/v2/conversations` resulted in a `400 Bad Request` response: {"logRef":"3bb98347-c884-48ba-bab9-b2a8bc73f3b3#1299214158","message":"Error parsing request body into JSON","_embedded" (truncated...) "

Seeing as this PHP client handles the construction of the request, we believe there's either a bug in the library related to producing that JSON, or a bug in the API backend related to parsing that JSON. We contacted your support team who stated that from the logs the JSON looks valid to them, but they asked that we re-create a ticket here as the request was made using the PHP client. They stated you should be able to trace that using the logRef (supplied above).

Expected behavior

For the client to not construct a request that invokes a JSON parsing error in the API.

Steps to reproduce

Re-send the request logged in logRef 3bb98347-c884-48ba-bab9-b2a8bc73f3b3#1299214158, which was created using the latest version of the PHP client. We can't include that request here as it contains confidential customer information.

miguelrs commented 2 years ago

Hey @jonathanbull, thanks for bringing this up!

I've been checking our logs and looks like the JSON data in the body of your request is being truncated at a certain point, resulting in a malformed JSON string. We will try to investigate why this happened and update you as soon as we can.

jonathanbull commented 2 years ago

Thanks @miguelrs !

miguelrs commented 2 years ago

Hey @jonathanbull. I've been looking at your issue more closely, and I can see in our logs that the JSON we receive in the body of your requests is invalid. I see that it's simply truncated at some point, around ~8KB. This JSON is basically your $conversation object, which is automatically serialized by the library.

I've been making tests using the same versions as you for PHP and the client, and using a similar $conversation contents, and I can create conversations without problems, even with much larger payloads than yours. This suggests everything is working fine in the library and on our end.

I'm not sure what the issue is. If you can usually create large conversations using the library, maybe this was a one-off issue. Otherwise, maybe you could have some limitations in the size of the requests you can send in your infrastructure.

I hope you get it fixed. Let us know if you need more help!

jonathanbull commented 2 years ago

We regularly make requests this size and it's the first time we've seen this error, so I think it must have been a one-off issue like you suggest. Happy to chalk this up to a one-off issue – perhaps network related. Thanks for taking a closer look @miguelrs.