Answered

Custom Action is automatically inserting escape characters into request body and causing request to fail

  • 16 October 2023
  • 5 replies
  • 142 views

Badge

I’m attempting to create a custom action that sends a POST request to Shortcut API.  The request succeeds when I test it in Postman or other testing tools; however, when I try to test the request in Intercom’s Custom Action building tool, Intercom arbitrarily inserts escape characters into the JSON in the Request Body, which causes the Shortcut API to return a code 400 Bad Request.

 

Here’s a comparison of the Intercom and Postman consoles (Intercom on the left, Postman on the right).  Notice that Intercom has added escape characters to the body.  I’ve already confirmed that the error is caused by Intercom inserting those escape characters.

 



Is there any way to force Intercom to send the request as-is?  It makes no sense that it would alter a Request Body...those should ALWAYS be sent as-is.

 

Here’s a zoom recording showing the issue, if that helps:  https://us02web.zoom.us/rec/share/C1W_oCh039rZ4cvJOi639opBCb2-kocdh16CjsHyILJrqE-gUKno1holp0EI_4rk.7_lD0QAgj0pYeCkQ?startTime=1697468415000

icon

Best answer by Doug Taylor 19 October 2023, 22:11

View original

5 replies

Userlevel 3
Badge

Hey @Doug Taylor 👋 Eden from the support engineer team here.

 

Can you please try removing the line breaks from your request in the Custom Action, then try to send the request again? So instead of using the format of: 

{“name”: “test name”, 

“project_id”: 1

}

 

Formatting the request like: 

{“name”: “test name”,  “project_id”: 1}

 

If that doesn’t resolve this issue for you, I can go ahead and escalate this with our Support team for a deeper investigation.👍

Badge

After playing around with this more, I’m still having trouble, but I noticed that there is something weird with the way Custom Builder is handling JSON.

JSON is typically formatted as

{
"key":"value"
}

That’s how I format it in Postman for my tests, which work.   That’s how I originally formatted it here in Intercom, which failed.

After playing around, I found that Intercom seems to want it formatted like this instead

key="text value"

No brackets, no quotes around the key.  Quotes for text values, but no quotes for integer values.  Very weird.  

So, my original request body in Intercom was this:

{"name": "Just a test card from Intercom",
"project_id": "2116",
"story_type": "bug"
}

This works fine in Postman and any other testing tool, but in Intercom I was getting a response from Shortcut that it was missing “name”, a required key.  Weird, since that was provided.

If I format it like this:

name="Test card from Intercom",
project_id=2116,
story_type="bug"

I no longer get an error about missing the “name” key.  Instead, I get an error about needing a “project id”.

So, it looks like Intercom is wanting JSON formatted with no brackets as key=”value”, but the problem is, I’m still running into issues because only the first item (name) appears to be recognized by Shortcut.

This isn’t an issue with Shortcut’s API, because this works just fine in Postman.  The issue must be something in the Custom Action in intercom.

Does anyone have more details on how to correctly format JSON for intercom?

 

Badge

Hi @Eden !

I had already tried that.  Just tried it again, and ran into the same issue.

I’ve also tried having no line breaks using the formatting mentioned in my 2nd post, but again, still running into the issue.

 

name="Test card from Intercom",project_id=2116,story_type="bug"

This time, Shortcut doesn’t give me a 400 Bad Request, because it seems to recognize the name key as being present, but it gives me a 422 Unprocessable Entity error instead “must specify project id”.

Again, I’m using the same data that succeeds when I test in Postman

Userlevel 3
Badge

Thanks for giving that a try @Doug Taylor. I’ve escalated this as a conversation with the Support team for a support engineer to investigate further with you. They will reach out to you in the conversation as soon as possible! 👍

Badge

Resolved!

Even though the request was automatically using Content-Type: application/json (I kept an eye on that in the console), it looks like I needed to actually specify that in the Headers in the Custom Action builder.

Good to keep in mind if you are running into similar issues.  Be sure to specify Content-Type: application/json in the headers!

@Eden  and Kyle!

Reply