Please Help with XML / HTTP Post Request,,

I can´t get it to work :(
There must be an error with the XML/Body attachment.

Without the XML Body it does work - but i need to attach the XML.

Can someone please help me ?

My Code:

//Create a new post request

var xmlFle = new XML(‘test’); // → Creating the XML Object

var client = plugins.http.createNewHttpClient(); // Creating new http client
var poster = client.createPostRequest(‘https://mws.amazonservices.de’);

poster.addParameter(‘AWSAccessKeyId’,‘AKIAIMWQ2C12345678’)
poster.addParameter(‘Action’,‘SubmitFeed’)
poster.addParameter(‘Merchant’,‘A2D9F123456789’)
poster.addParameter(‘MWSAuthToken’,‘A1PA6123456789’)
poster.addParameter(‘SignatureVersion’,‘2’)
poster.addParameter(‘Timestamp’,time) // using a time variable → variable works ( used and tested with other requests)
poster.addParameter(‘Version’,‘2009-01-01’)
poster.addParameter(‘Signature’,signature) // Signature is correct ( used and tested with other requests)
poster.addParameter(‘SignatureMethod’,‘HmacSHA256’)
poster.addParameter(‘FeedType’,‘POST_PRODUCT_DATA’)
poster.addParameter(‘PurgeAndReplace’,‘false’)
poster.addParameter(‘x-amazon-user-agent’,‘AmazonJavascriptScratchpad/1.0 (Language=Javascript)’)
poster.addParameter(‘Content-MD5’,‘LwpPrQqp+k0hA6qImf+wdQ==’) // Value is verfied and works
poster.addParameter(‘Content-Type’,‘text/xml’)

poster.setBodyContent(xmlFle.toString()) // !!! the error must be here !!!

poster.setCharset(‘UTF-8’);

var response = poster.executeRequest()

//Get the content of the response as String.e
var pageData = response.getResponseBody();

application.output(pageData)

Thank you for your help !

Rainer Böhm

Did you inspect what xmlFle.toString() gives you? I think that gives you the string ‘test’, not ‘’test‘’

pbakker:
Did you inspect what xmlFle.toString() gives you? I think that gives you the string ‘test’, not ‘’test‘’

I think you want to use:

xmlFile.toXMLString()

Also notice your not setting any headers. Would double check the API and see if it requires any standard headers. For example, things like these are normally part of the header, not the poster/body:

poster.addParameter('x-amazon-user-agent','AmazonJavascriptScratchpad/1.0 (Language=Javascript)')
poster.addParameter('Content-MD5','LwpPrQqp+k0hA6qImf+wdQ==') // Value is verfied and works
poster.addParameter('Content-Type','text/xml')

You probably want:

poster.addHeader('x-amazon-user-agent','AmazonJavascriptScratchpad/1.0 (Language=Javascript)')
poster.addHeader('Content-MD5','LwpPrQqp+k0hA6qImf+wdQ==') // Value is verfied and works
poster.addHeader('Content-Type','text/xml')