'Error sending HTTP request. Message payload is of type: HashMap
I am failing at generating a POST message from within Anypoint Studio:
What I am trying to accomplish is to send a POST to our Kykloud api endpoint with 3 key-value-pairs as the payload as x-www-form-urlencoded content.
This is the current visual setup:
(Sidenote: I know its bad practice to store secrets and login data in plain view. I'll try to figure out how to do this properly later on)
The appropriate XML looks like this:
<flow name="LoginFlow">
<set-payload value="#[['ApiToken': 'xxxXXXxxxXXXxxxXXX']]" doc:name="Set ApiToken"/>
<set-payload value="#[['Email':'serv[at]someaddress.com']]" doc:name="Set Email"/>
<set-payload value="#[['Password':'VeryLongPenis']]" doc:name="Set Password"/>
<http:request config-ref="KyklouConnectorns" path="/api/v2/sessions?format=json" method="POST" doc:name="Login to Kykloud" port="80" />
<logger level="INFO" message="SessionId is #[message.payload.'SessionId']" doc:name="Logger"></logger>
</flow>
In theory the response should be some JSON with a SessionId object in it.
What I am actually receiving in POSTMAN is:
Error sending HTTP request. Message payload is of type: HashMap
Obviously I am doing something wrong in defining my payload, but they documentation on this isn't clear on how to do it the correct way:
HTTP Request Body The Mule Message payload is converted into a byte array and sent as the HTTP Request’s body. This behavior is carried out always, except in the following scenarios:
The Mule Message’s Payload is a Map of keys and values
The Message has outbound attachments
Generate the Request Body with Content-Type:application/x-form-urlencoded Whenever the message payload is a Map, the connector automatically generates an HTTP request with the header Content-Type:
application/x-www-form-urlencoded
. The keys and values of the map in the payload are converted into form parameter keys and values in the body of the HTTP request.
Solution 1:[1]
You dont need to do a set payload for each of the parameters e.i(username/pwd/api token) in set payload you will only have the content you want to post which is not needed in your case. You need to set (username/pwd/api token) as headers in your http request. Added to the above three you may also need to set the Content-type as application/json this depends based on your api.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | scorpion |