Answered

400 Bad Request error but works fine in Postman

  • 28 July 2023
  • 4 replies
  • 4037 views

Badge

I’m building a custom action that will send a POST request to Shortcut to create a Story.  I’ve tested in Postman and it works fine, but when I use the exact same request body in Intercom, I’m getting a message back that I’m missing a parameter (the missing parameter happens to be the only required parameter).  I can recreate this error in Postman by commenting out (or removing) the parameter in question.  Otherwise, it always succeeds in Postman.

How does Intercom present the body in these requests?  Does it do it exactly as-is, or does Intercom apply some formatting?  Since it works fine in Postman, I’m kinda thinking that Intercom is changing something.

To be more specific, when creating a Story via Shortcut’s API, the only required parameter is “name”.  If my request body in Intercom is this:

{"name": "Just a test card from Intercom"}

I get this message:

400 Bad Request

{"message":"The request included invalid or missing parameters.","errors":{"name":"missing-required-key"}}

 

Works fine if I test it in Postman though. 

icon

Best answer by frencofzc 31 July 2023, 09:13

View original

4 replies

Make sure there is no error in the configuration of your request. Look for typos, whitespaces, or invalid JSON formatting. To identify the error, use the Postman's console to verify that all the data sent with the request is correct.

E-Commerce Agency In Dubai

Badge

Thanks for the response!

The request works fine in Postman.  It is only when I’m building the Custom Action in Intercom that it fails.  I’ve double-checked for typos, whitespace, and invalid JSON, but found nothing wrong.  

The error message I’m receiving (in the Testing stage of building the Custom Action in Intercom) indicates that Intercom successfully communicated with the destination (Shortcut API in this case), but the JSON lacked the required field (“name”).  In my test, that field was present in the JSON, and formatted correctly.

Here’s a comparison of the Intercom and Postman consoles (Intercom on the left, Postman on the right).  You can ignore the extra parameters in Postman, those were just to better organize the test.  The only required field is “name”.  Tests from Intercom are returning an error that the name field is missing (“name”: “missing-required-key”).  I can’t understand why the name field is recognized when sent from Postman, but is not recognized when sent from Intercom.  Could it be because Intercom is automatically adding the escape and newline characters?  (the \ before quotes, and the \n for newline)?  I have tested removing all whitespace, but Intercom still adds the ‘\' escape character to quotes.  That’s the only difference I can see.

 


 

Badge

UPDATE:

I just confirmed that the problem IS because Intercom is adding the punctuation and escape characters.  If I reproduce in Postman and try to send the body as

"{\"name\":\"test\"}"

I get the exact same message about the name field missing.

Is there any way to force Intercom to stop modifying the JSON and just send it exactly as I wrote it?

This is still not solved. I am having the exact same issue as Doug mentioned above. I can reproduce the same in Retool but not in Intercom. So bizarre. 

Reply