I’ve been trying to set up an XML product feed for affiliates to use to pull a feed of products on the website. Fortunately, a helpful gent from NetSuite showed me the Items Search API that should give me almost the exact data that I need, which returns JSON, but I’m struggling with how to pull that data via a Suitelet.
Normally, I would use something like an XMLHttpRequest, but it doesn’t look like that’s something that’s supported in SuiteScript. I’ve looked into nlapiRequestURL a little bit and it looks like that might do what I need, however, I’m having trouble implementing it in a way that makes sense. I’ve put it in a suitelet with the goal of being able to have the affiliates just be able to hit a URL and see/pull the XML document. I put together a quick test script, but I keep getting the HTTP response code 406, which appears to mean that the content type is not set, even if I set it in the request.
Very rudimentary script:
function getDataFeed(request, response) { var a = new Array(); a['Content-Type'] = 'application/json'; a['User-Agent-x'] = 'SuiteScript-Call'; var url = "http://mysite.com/api/items?include=facets&fieldset=search&language=en&country=US¤cy=USD&pricelevel=31&offset=0"; var dataFeed = nlapiRequestURL(url, null, a); response.write(<span style="font-family:'Helvetica'"><span style="font-size:'12px'">dataFeed</span></span>.getCode()); //always returns 406.0 } All the example code I’ve found shows using nlapiRequestURL in a RESTlet. Can it be used in a suitelet? If not, what sort of credentials should I be passing with the request in the RESTlet? Once I’m able to return the JSON object, I should be able to loop through it and output XML no problem. I just can’t seem to figure out how to pull the data in correctly. Any guidance would be much appreciated. Thanks!