This topic contains 8 replies, has 0 voices, and was last updated by ironside 7 years, 6 months ago.

  • Author
    Posts
  • #5686 Score: 0

    FHC
    • Contributions: 0
    • Level 1

    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:

    Code:
    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&currency=USD&pricelevel=31&offset=0”;

    var dataFeed = nlapiRequestURL(url, null, a);

    response.write(dataFeed.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!
    This is a cached copy. Click here to see the original post.

  • #5687 Score: 0

    david.smith
    • Contributions: 0
    • Level 1

    Suitelets are not secure and open to anyone. I personally would never suggest using one externally unless you really need to.

    Restlets are secure and give you the ability to track and revoke access when and if needed. For example, if an affiliate becomes irate and decides to misuse the information you can cut their access easily.

    JSON is also the way to go. It’s a lot more common now over XML.

    It looks like you’re trying to pull the data from an SCA site? Why not just give them that URL if that’s what you’re trying to do? If that’s not feasible, why not just do a quick nlapiSearchRecord for the items your looking for.

  • #5688 Score: 0

    FHC
    • Contributions: 0
    • Level 1

    I’ve looked into Restlets a bit, but I can’t stop getting authentication errors.

    The affiliate only accepts datafeeds according to Google’s Product Feed Specifications, which are XML. I haven’t approached them about the idea of just the JSON yet. That might be an idea…

    nlapiSearchRecord was what I had originally done and gotten pretty far with. However, with SCA, I don’t have access to the item’s images. Items Search API does.

  • #5689 Score: 0

    FHC
    • Contributions: 0
    • Level 1

    Yep. No JSON support. Gotta be XML…

  • #5690 Score: 0

    david.smith
    • Contributions: 0
    • Level 1

    A restlet will support text/plain output but I’m not sure if that will work. I know you can return XML with the suitelet.

    I would still go with the search and return what you need rather than trying to use the connection to SCA. I have tried to do that in the past and for some reason I couldn’t get it to work server-side.

  • #5691 Score: 0

    chanarbon
    • Contributions: 0
    • Level 1

    Hi @FHC,

    What I could suggest for this scenario is use a RESTlet which returns a xml string output for your SCA site. The XML string should be parsable on the in the SCA site since it should support text to XML conversions. Pretty much what you’re going to do on your RESTlet is to convert the object resulting from nlapiSearchRecord() to JSON then transform it to XML then stringify the XML and return it. Converting JSON to XML can be done using a library x2js.

  • #5692 Score: 0

    FHC
    • Contributions: 0
    • Level 1

    OK, after talking with some other NetSuite folks, RESTlet definitely seems like to go. However, I’m still having trouble understanding how to set one up, especially using token-based authentication. I’ve setup the integration, and received the consumer key and consumer secret, but the documentation says I need the oauth_signature. Where to do I get that?

    In other news, I discovered that the code above may actually work, but suitelets may not have access to all available SuiteScript APIs and will require a valid NetSuite session. For instance, I found that if I visited the URL that nlapiRequestURL() was trying to call first and then went back to the URL of the suitelet, I would actually return results. Hence me experimentation with RESTlets…

  • #5693 Score: 0

    david.smith
    • Contributions: 0
    • Level 1

    FHC Suitelets are not very secure. If you’re connecting from an external source use the RESTlet.

    After you create the integration, you need to create Access Tokens (under User/Role menu). Once you have all 4 you can create a call to your restlet using OAuth 1.0. This part is now “outside” of NetSuite and you would need to let us know what programming language you’re using to integrate with NS if you need further help.

    You can also look in SuiteAnswers. There are examples and explanations there on how to connect.

  • #5694 Score: 0

    ironside
    • Contributions: 0
    • Level 1

    Just for the record, david.smith is wrong in the blanket statement that suitelets are not secure.


    david.smith replied on 02/24/2017, 07:49 AM: OK. As a “blanket statement”, sure. But when used as externally available they have no security measures in place.

You must be logged in to reply to this topic.