Skip to main content
Answered

Set correct Content-Type for custom action by default to application/json


Hi,

following the custom action guide, I tried to do an outbound HTTP call with a POST request. In the request body I added the corresponding JSON (according to the description in the UI wizard: "Specify the body of your request in JSON format. You can use the selector ({...}) to pass Intercom attribute values in your request body.") like this:

 

{
"ownerEmail": "ash-ketchum@example.com",
"pet":"Pikachu"
}

 

When retrieving the call in my application, I see the following HTTP request coming in:

POST /my-endpoint HTTP/1.1
Host: myserver.com
User-Agent: Faraday v0.17.3
Content-Length: 66
Accept: */*
Accept-Encoding: gzip,deflate
Content-Type: application/x-www-form-urlencoded
Date: Fri, 01 Jul 2022 12:19:53 GMT
 
{
"ownerEmail": "ash-ketchum@example.com",
"pet":"Pikachu"
}

The problem is that the "Content-Type" HTTP header is set to ​"application/x-www-form-urlencoded" instead of "application/json".

 

Therefore my application framework will reject the request, as the HTTP body does not match the content type.

 

I'm able to change the body of the HTTP call by using the format of "application/x-www-form-urlencoded" like this:

 

ownerEmail=ash-ketchum%40example.com&pet=Pikachu

but I'm not sure if this is how I should do it, as the description explicitly says it should be JSON.

 

I am also able to override the HTTP header explicitly in the wizard (and this actually works), but I was wondering why the default value is "application/x-www-form-urlencoded".

 

 

Cheers

Mario

Best answer by Aparna

Hey @mario d​  You can add your own headers, so it is set to the specific content type

View original
Did this topic help you find an answer to your question?

3 replies

  • Employee
  • 328 replies
  • July 5, 2022

Hey @mario d​ I will check this and get back to you.


  • Employee
  • 328 replies
  • Answer
  • July 12, 2022

Hey @mario d​  You can add your own headers, so it is set to the specific content type


  • Author
  • New Participant
  • 1 reply
  • August 5, 2022

Hi @aparna​ , thanks for the answer. It is true, as I wrote I set the content type header to "application/json" and then it worked. I was just wondering why this is not set as the default and instead it is set to "application/x-www-form-urlencoded" although the body of the request is supposed to be JSON.


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings