# HTTP POST receiving XML and send as email

**URL:** <https://discourse.nodered.org/t/http-post-receiving-xml-and-send-as-email/2385>\
**Category:** General\
**Created:** [18 August 2018 11:43 UTC](https://discourse.nodered.org/t/http-post-receiving-xml-and-send-as-email/2385 "2018-08-18T11:43:55Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![4integration](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/4integration/32/68504_2.png) [@4integration](https://discourse.nodered.org/u/4integration)\
**Post date:** [18 August 2018 11:43 UTC](https://discourse.nodered.org/t/http-post-receiving-xml-and-send-as-email/2385/1 "2018-08-18T11:43:55Z")

</div>

Hi,

I have setup a flow with a HTTP in/request node which receive XML payload in a POST request.  
I have this flow:

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/2/2f8b45cf1c5bf374215af8734d433dc5cbba6d3c.png)

Debug node logs the XML but the email recieved contains the same but JSON

- How can I preserve XML?
- How can I also add HTTP headers to the mail?

---

<div class="post-metadata">

**Author:** ![ghayne](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ghayne/32/39_2.png) [@ghayne](https://discourse.nodered.org/u/ghayne)\
**Post date:** [18 August 2018 11:49 UTC](https://discourse.nodered.org/t/http-post-receiving-xml-and-send-as-email/2385/2 "2018-08-18T11:49:07Z")

</div>

The xml node converts the xml to a JSON string. Just remove it!  
Can't help you with the second part, I'm sure someone else here can.

---

<div class="post-metadata">

**Author:** ![4integration](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/4integration/32/68504_2.png) [@4integration](https://discourse.nodered.org/u/4integration)\
**Post date:** [18 August 2018 15:02 UTC](https://discourse.nodered.org/t/http-post-receiving-xml-and-send-as-email/2385/3 "2018-08-18T15:02:39Z")

</div>

If I send this XML:

```
<?xml version="1.0" encoding="UTF-8"?>
<event>
   <action>updated</action>
   <type>application</type>
   <object>
      <application>
         <id>1409617777678</id>
         <created_at>2018-06-18T14:59:54+02:00</created_at>
         <updated_at>2018-08-17T16:36:59+02:00</updated_at>
         <state>live</state>
         <user_account_id>2445582229963</user_account_id>
         <first_traffic_at>2018-06-18T15:00:28+02:00</first_traffic_at>
         <first_daily_traffic_at>2018-07-02T12:46:20+02:00</first_daily_traffic_at>
         <end_user_required>false</end_user_required>
         <service_id>2555417758689</service_id>
         <user_key>ca11f21866f5d664fb59fd3afa578d44</user_key>
         <provider_verification_key>4492205d7b3f619425ee46b4e4023873</provider_verification_key>
         <plan custom="false" default="false">
            <id>2357355951502</id>
            <name>Basic Echo Plan</name>
            <type>application_plan</type>
            <state>published</state>
            <service_id>2555417758689</service_id>
            <end_user_required>false</end_user_required>
            <setup_fee>0.0</setup_fee>
            <cost_per_month>0.0</cost_per_month>
            <trial_period_days />
            <cancellation_period>0</cancellation_period>
         </plan>
         <name>Testing Echo API</name>
         <description>This is just for fun :) ....</description>
         <extra_fields />
      </application>
   </object>
</event>

```

Through XML node (as above) I get in the mail (quite crappy with HTML encodings):

```
&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;yes&quot;?&gt;&lt;&lt;?xml version&gt;&quot;1.0&quot;

encoding=&quot;UTF-8&quot;?&amp;gt;&amp;lt;event&amp;gt;&amp;lt;action&amp;gt;updated&amp;lt;/action&amp;gt;&amp;lt;type&amp;gt;application&amp;lt;/type&amp;gt;&amp;lt;object&amp;gt;&amp;lt;application&amp;gt;&amp;lt;id&amp;gt;1409617777678&amp;lt;/id&amp;gt;&amp;lt;created_at&amp;gt;2018-06-18T14:59:54

02:00&amp;lt;/created_at&amp;gt;&amp;lt;updated_at&amp;gt;2018-08-17T16:36:59

02:00&amp;lt;/updated_at&amp;gt;&amp;lt;state&amp;gt;live&amp;lt;/state&amp;gt;&amp;lt;user_account_id&amp;gt;2445582229963&amp;lt;/user_account_id&amp;gt;&amp;lt;first_traffic_at&amp;gt;2018-06-18T15:00:28

02:00&amp;lt;/first_traffic_at&amp;gt;&amp;lt;first_daily_traffic_at&amp;gt;2018-07-02T12:46:20

02:00&amp;lt;/first_daily_traffic_at&amp;gt;&amp;lt;end_user_required&amp;gt;false&amp;lt;/end_user_required&amp;gt;&amp;lt;service_id&amp;gt;2555417758689&amp;lt;/service_id&amp;gt;&amp;lt;user_key&amp;gt;ca11f21866f5d664fb59fd3afa578d44&amp;lt;/user_key&amp;gt;&amp;lt;provider_verification_key&amp;gt;4492205d7b3f619425ee46b4e4023873&amp;lt;/provider_verification_key&amp;gt;&amp;lt;plan

custom=&quot;false&quot;

default=&quot;false&quot;&amp;gt;&amp;lt;id&amp;gt;2357355951502&amp;lt;/id&amp;gt;&amp;lt;name&amp;gt;Basic Echo Plan&amp;lt;/name&amp;gt;&amp;lt;type&amp;gt;application_plan&amp;lt;/type&amp;gt;&amp;lt;state&amp;gt;published&amp;lt;/state&amp;gt;&amp;lt;service_id&amp;gt;2555417758689&amp;lt;/service_id&amp;gt;&amp;lt;end_user_required&amp;gt;false&amp;lt;/end_user_required&amp;gt;&amp;lt;setup_fee&amp;gt;0.0&amp;lt;/setup_fee&amp;gt;&amp;lt;cost_per_month&amp;gt;0.0&amp;lt;/cost_per_month&amp;gt;&amp;lt;trial_period_days/&amp;gt;&amp;lt;cancellation_period&amp;gt;0&amp;lt;/cancellation_period&amp;gt;&amp;lt;/plan&amp;gt;&amp;lt;name&amp;gt;Testing

Echo API&amp;lt;/name&amp;gt;&amp;lt;description&amp;gt;This is just for fun :) ....&amp;lt;/description&amp;gt;&amp;lt;extra_fields&amp;gt;&amp;lt;/extra_fields&amp;gt;&amp;lt;/application&amp;gt;&amp;lt;/object&amp;gt;&amp;lt;/event&amp;gt;&lt;/&lt;?xml

version&gt;

```

If I go directly from HTTP node to email node I just get the two first elements as some sort of JSON:  
`{&quot;updatedapplication&quot;}`

---

<div class="post-metadata">

**Author:** ![ukmoose](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ukmoose/32/13_2.png) [@ukmoose](https://discourse.nodered.org/u/ukmoose)\
**Post date:** [18 August 2018 15:56 UTC](https://discourse.nodered.org/t/http-post-receiving-xml-and-send-as-email/2385/4 "2018-08-18T15:56:09Z")

</div>

What are you trying to achieve?  
Is it to download the xml from the Email?  
If so have you tried sending the xml as an attachment the mail node info bar explains how

---

<div class="post-metadata">

**Author:** ![4integration](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/4integration/32/68504_2.png) [@4integration](https://discourse.nodered.org/u/4integration)\
**Post date:** [19 August 2018 10:31 UTC](https://discourse.nodered.org/t/http-post-receiving-xml-and-send-as-email/2385/5 "2018-08-19T10:31:02Z")

</div>

@ukmoose I have an API Management system that will do a HTTP POST when something change, with the XML above as an example.

I want to have a webhook in Node-RED to receive that HTTP POST and XML, then as **step one** send that XML as-is in an email body but also pick a few HTTP headers to also be added to the email body.

---

<div class="post-metadata">

**Author:** ![ukmoose](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ukmoose/32/13_2.png) [@ukmoose](https://discourse.nodered.org/u/ukmoose)\
**Post date:** [19 August 2018 11:27 UTC](https://discourse.nodered.org/t/http-post-receiving-xml-and-send-as-email/2385/6 "2018-08-19T11:27:41Z")

</div>

Sorry I must be missing something.

If you want to add http headers to the Email message body it won't then be valid xml.

But as the Email message body is msg.payload. You could convert the xml to a string and then prepend the html headers you want to the start of that string.

---

<div class="post-metadata">

**Author:** ![4integration](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/4integration/32/68504_2.png) [@4integration](https://discourse.nodered.org/u/4integration)\
**Post date:** [19 August 2018 14:27 UTC](https://discourse.nodered.org/t/http-post-receiving-xml-and-send-as-email/2385/7 "2018-08-19T14:27:47Z")

</div>

Sure, I know it won't be a valid XML but it won't be parsed initially so doesn't matter - as said this is step one.  
Will google howto's...
