Sending XML in a POST Request
In Unmeshed, HTTP Steps default to using JSON for request bodies. However, if your API endpoint requires XML data, you can easily configure your workflow to send XML. You can either supply the XML directly in the Body field, or construct it dynamically (e.g., in a JavaScript step) before passing it to the HTTP step as a parameter.
1. Create or Open Your Process Definition
- In the Unmeshed UI, go to Process Definitions.
- Open an existing process or create a new one.
2. Add an HTTP POST Step
- From the left panel, drag-and-drop an HTTP Post step onto your workflow canvas.
- Give it a descriptive Step Name (e.g.,
xml_post
). - In the Method dropdown, select Post.
- In the Url field, enter the endpoint URL you want to call (e.g.,
http://localhost:8080/api/test/xmlPost
).
3. Set Request Headers for XML
- Under Headers, add a header key
Content-Type
and set the value toapplication/xml
. - (Optional) Set
Accept: application/json
if your API returns JSON responses.
4. Provide the XML Body
-
Scroll down to the Body (If Applicable) section.
-
Change the Type of content dropdown to Text.
-
In the text area, paste your XML. For example:
<InvGetItemsRequest>
<Parameters>
<ItemCode>AXEABC</ItemCode>
</Parameters>
<RequestFields>
<Items>
<Item>
<ItemCode />
<GroupCode />
<TypeCode />
<ItemSuppliers>
<RequestFields>
<ItemSuppliers>
<!-- more fields if needed -->
</ItemSuppliers>
</RequestFields>
</ItemSuppliers>
</Item>
</Items>
</RequestFields>
</InvGetItemsRequest> -
You can also use placeholders from earlier steps or global variables if you have dynamic fields you want to inject into the XML.
Use Test Run Process or manually trigger the process to verify that your XML POST request works as intended.
(Optional) Construct XML Dynamically in JavaScript
If you need to build XML dynamically (e.g., based on data coming from earlier steps):
Insert a Script - Javascript step before the HTTP step. In the script, construct your XML string. For example:
let itemCode = steps.myPreviousStep.output.itemCode;
let xmlBody = `
<InvGetItemsRequest>
<Parameters>
<ItemCode>${itemCode}</ItemCode>
</Parameters>
<!-- add more XML as needed -->
</InvGetItemsRequest>
`;
// Return xmlBody so it can be used by the HTTP step
return { xmlBody: xmlBody };
In your HTTP Post step’s Body, reference the parameter returned from the JavaScript step. For example:
{{ steps.myJavascriptStep.output.results.xmlBody}}
Keep the Type of content set to Text, since this is still XML.
Screenshot Reference
Below is an example screenshot of how the HTTP step can be configured to send XML. Notice how the Type of content is set to Text, the Content-Type header is set to application/xml, and the XML body is placed directly into the Body field.