title: Sending POST request in ESB mule for API
body: <p>I try to send the post request to API using ESB mule. Hence i have created flow like below.</p>
  
  <pre><code>     &lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;mule xmlns:json="http://www.mulesoft.org/schema/mule/json" xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation"
      xmlns:spring="http://www.springframework.org/schema/beans" 
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd
  http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
  http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd
  http://www.mulesoft.org/schema/mule/json http://www.mulesoft.org/schema/mule/json/current/mule-json.xsd"&gt;
      &lt;http:listener-config name="HTTP_Listener_Configuration" host="0.0.0.0" port="8110" doc:name="HTTP Listener Configuration"/&gt;
      &lt;http:request-config name="HTTP_Request_Configuration"  host="api.bonanza.com" port="443" doc:name="HTTP Request Configuration" protocol="HTTPS"/&gt;
      &lt;flow name="bonanza_fetchtoken_ceFlow"&gt;
          &lt;http:listener config-ref="HTTP_Listener_Configuration" path="/fetchtoken" allowedMethods="GET" doc:name="HTTP"/&gt;
          &lt;message-properties-transformer doc:name="Message Properties"&gt;
              &lt;add-message-property key="X-BONANZLE-API-DEV-NAME" value="t**********I"/&gt;
              &lt;add-message-property key="X-BONANZLE-API-CERT-NAME" value="l**********F"/&gt;
          &lt;/message-properties-transformer&gt;
          &lt;set-payload value="fetchTokenRequest" doc:name="Set Payload"/&gt;
          &lt;set-property propertyName="Content-Type" value="text/plain" doc:name="Property"/&gt;
          &lt;set-property propertyName="Accept" value="application/json" doc:name="Property"/&gt;
          &lt;http:request config-ref="HTTP_Request_Configuration" path="/api_requests/secure_request" method="POST" doc:name="HTTP" followRedirects="true" parseResponse="false"&gt;
              &lt;http:success-status-code-validator values="0..599"/&gt;
          &lt;/http:request&gt;
      &lt;/flow&gt;
  &lt;/mule&gt;
  </code></pre>
  
  <p>In the API documentation, they have provided the sample code for java to send and receive response and it is working in my local too. The java code snippet is below.</p>
  
  <pre><code>import org.json.JSONObject;
  import java.io.BufferedReader;
  import java.io.InputStreamReader;
  import java.io.OutputStreamWriter;
  import java.net.URL;
  import java.net.HttpURLConnection;
  
  public class FetchToken {
  
      public static void main(String[] args) {
          // TODO Auto-generated method stub
          try {
              String devId = "t******I";
              String certId = "l*******F";
  
              URL url = new URL("https://api.bonanza.com/api_requests/secure_request");
              HttpURLConnection connection = (HttpURLConnection) url.openConnection();
  
              connection.setRequestMethod("POST");
              connection.setDoOutput(true);
              connection.setRequestProperty("Accept", "application/json");
              connection.setRequestProperty("X-BONANZLE-API-DEV-NAME", devId);
              connection.setRequestProperty("X-BONANZLE-API-CERT-NAME", certId);
  
              OutputStreamWriter writer = new OutputStreamWriter(connection.getOutputStream());
  
              String requestName = "fetchTokenRequest";
  
              writer.write(requestName);
              writer.flush();
              writer.close();
  
              BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
              String response = in.readLine();
  
              JSONObject jsonResponse = new JSONObject(response);
  
              if (jsonResponse.optString("ack").equals("Success") 
                      &amp;&amp; jsonResponse.optJSONObject("fetchTokenResponse") != null) {
                  // Success! Now read more keys from the json object
                  JSONObject fetchTokenJson = jsonResponse.optJSONObject("fetchTokenResponse");
  
                  System.out.println("Your token: " + fetchTokenJson.optString("authToken"));
                  System.out.println("Token expiration time: " + fetchTokenJson.optString("hardExpirationTime"));
                  System.out.println("Authentication URL: " + fetchTokenJson.optString("authenticationURL"));
              }
  
  
          } catch (Exception e) {
              System.out.println(e);
          }
      }
  }
  </code></pre>
  
  <p>The above java program retuning token without issue. When i use my esb mule i am getting below API error. What are the mistakes i doing while building request. How can i get successful response from API ?</p>
  
  <pre><code>{
    "ack": "Failure",
    "version": "1.0beta",
    "timestamp": "2016-03-09T10:35:16.000Z",
    "errorMessage": {
      "message": "Cannot determine what type of request you are making. Often this can be the result of data that has not been escaped before being passed to the API. If you are passing data with quotation marks or other special characters, you should translate it to JSON, then escape it, before sending it over the API."
    }
  }
  </code></pre>