title: Node.js/Express: Read XML Post, Amazon IPN
body: <p>I want to use Amazon's IPN. So far i never worked with XML and just accessed POST params with <code>req.body.param</code>. This does not seem to work at all.</p>
  
  <p>Amazon sends a post request structured like this:</p>
  
  <pre><code>POST / HTTP/1.1
  x-amz-sns-message-type: Notification
  x-amz-sns-message-id: 0000000-0000-00000-0000-00000EXAMPLE
  x-amz-sns-topic-arn: arn:aws:sns:EXAMPLE:11111EXAMPLE:TestTopic
  x-amz-sns-subscription-arn: arn:aws:sns:EXAMPLE:11111EXAMPLE:TestTopic: EXAMPLE
  Content-Length: 999
  Content-Type: text/plain; charset=UTF-8
  Host: ec2-EXAMPLE.compute-1.amazonaws.com
  Connection: Keep-Alive
  User-Agent: Amazon Simple Notification Service Agent
  {
      Type : Notification,
      MessageId : xxxxxx-xxxx-xxxx-xxxx-xxxxxEXAMPLE,
      TopicArn : arn:aws:sns:EXAMPLE:11111EXAMPLE:TestTopic,
      Message :
      {
          NotificationReferenceId: 1111111-1111-11111-1111-11111EXAMPLE,
          NotificationType: OrderReferenceNotification,
          SellerId: A3PJMS5WFYSRB4,
          ReleaseEnvironment: Sandbox,
          Version: 2013-01-01,
          NotificationData:&lt;?xml version="1.0" encoding="UTF-8"?&gt;
              &lt;OrderReferenceNotification xmlns="https://mws.amazonservices.com/ipn/OffAmazonPayments/2013-01-01"&gt;
                  &lt;OrderReference&gt;
                      &lt;AmazonOrderReferenceId&gt;P01-0000000-0000000-000000&lt;/AmazonOrderReferenceId&gt;
                      &lt;OrderTotal&gt;
                          &lt;Amount&gt;0.0&lt;/Amount&gt;
                          &lt;CurrencyCode&gt;USD&lt;/CurrencyCode&gt;
                      &lt;/OrderTotal&gt;
                      &lt;SellerOrderAttributes /&gt;
                      &lt;OrderReferenceStatus&gt;
                          &lt;State&gt;Closed&lt;/State&gt;           
                          &lt;LastUpdateTimestamp&gt;2013-01-01T01:01:01.001Z&lt;/LastUpdateTimestamp&gt;
                          &lt;ReasonCode&gt;AmazonClosed&lt;/ReasonCode&gt;
                      &lt;/OrderReferenceStatus&gt;
                      &lt;CreationTimestamp&gt;2013-01-01T01:01:01.001Z&lt;/CreationTimestamp&gt;       
                      &lt;ExpirationTimestamp&gt;2013-01-01T01:01:01.001Z&lt;/ExpirationTimestamp&gt;
                  &lt;/OrderReference&gt;
              &lt;/OrderReferenceNotification&gt;,
          Timestamp:2013-01-01T01:01:01Z
      }
      Timestamp : 2013-01-01T01:01:001Z,
      SignatureVersion : 1,
      Signature : rkne..9=kOUhF,
      SigningCertURL : https://sns.EXAMPLE.amazonaws.com/SimpleNotificationService-aaaaaabbbbbbccccccEXAMPLE.pem,
      UnsubscribeURL : https://sns.EXAMPLE.amazonaws.com/?Action=Unsubscribe&amp;SubscriptionArn=arn:aws:sns:EXAMPLE:11111EXAMPLE:TestTopic:GUID
  }
  </code></pre>
  
  <p>My routes.js for this routes is:</p>
  
  <pre><code>app.post('/approveDonationAmazon', (req, res) -&gt;
      #receive payment result from paypal
      # update Database
      {parseString} = require 'xml2js'
      console.log "req",req
      console.log "reqbody",req.body
      console.log "raw body",req.rawBody
      if req.body.message?
        xml = req.body.message
        parseString xml, (err, result) -&gt;
        console.dir "result",result
  
        #TODO Process Payment Callback
        # databaseService.approveDonation(db, payment_status, payer_email, mc_gross, (err) -&gt;
        #   # if there is an error retrieving, send the error. nothing after res.json({ err: err }); will execute
        #   if (err)
        #     return res.json({ err: err })
        #   return true
        # )
      else
        return res.json({ err: 'no message received' })
    )
  </code></pre>
  
  <p>My server log tells me that my vars a basically not defined:</p>
  
  <pre><code>2015-05-04 12:57:18.149458500   _remoteAddress: '::1',
  2015-05-04 12:57:18.149458500   body: {},
  2015-05-04 12:57:18.149459500   route: 
  2015-05-04 12:57:18.149459500    { path: '/approveDonationAmazon',
  2015-05-04 12:57:18.149462500      stack: [ [Object] ],
  2015-05-04 12:57:18.149462500      methods: { post: true } } }
  2015-05-04 12:57:18.149462500 reqbody {}
  2015-05-04 12:57:18.149463500 raw body undefined
  </code></pre>
  
  <p><strong>Question:</strong></p>
  
  <p>How to access the message vars, e.g. SellerId or Amount?</p>