Marty Zigman

Conversations with Marty Zigman

Certified Administrator • ERP • SuiteCloud

Marty Zigman LinkedIn

Marty Zigman

Holding all three official certifications, Marty is regarded as the top NetSuite expert and leads a team of senior professionals at Prolecto Resources, Inc.. He is a former Deloitte & Touche CPA and has held CTO roles. For over 30 years, Marty has produced leadership in ERP, CRM, and eCommerce business systems. Contact Marty to set up a conversation.

BiographyYouTubeLinkedInX (Twitter)

24 thoughts on “How To: Code Pattern for NetSuite Driven JSONP Cross Domain JavaScript

  1. corey says:

    The only problem I have with JSONP and the use of Suitelets is the fact that your Suitelet has to be available anonymously. If they allowed for RESTlets to be used cross domain that would open up a whole array of uses.

  2. Marty Zigman says:

    Hi Corey,

    I agree.

    I believe the Restlets were designed with the Cross Origin Sharing technique in mind where you pass in headers for authentication. Yet, I don’t believe that’s effective on public web sites where you don’t want to expose a credential.

    Marty

  3. corey says:

    Negative. CORS is not allowed.

    Access-Control-Allow-Origin: none

    I believe. I have brought it up in the last two roadmap sessions to Elham at SuiteWorld.

    I was pursuing AJAX calls from mobile apps for a while, where having your credentials in the code woutldn’t be a problem as it was all compiled into native using Phonegap build.

    That was just for yucks, though. I was really wanting to use them from either Portlets or Suitelets. Since forms. system. and rest. are different domains, you can’t. You can get away with using JSONP and a Suitelet as a work around. And it works great, I just don’t like the idea of security through obscurity.

  4. Marty Zigman says:

    Thanks Corey,

    Yes, I was suspecting that CORS may have an offer. Thank you for the clarification. I don’t mind the compiled credential in the mobile app so long as everything is SSL (should be).

    During SuiteWorld 2013, there was some conversation about moving these SuiteLets to the new SSPs (.ss) mechanisms. But there has been little guidance. I do want to understand that option however.

    Marty

  5. corey says:

    I would love to be able to explore more with the SSP stuff. It kind of reminds me of Classic ASP with some MVC thrown in. I haven’t built anything yet using it, but I would like to, at some point.

  6. David says:

    Hi Marty,

    I have a question…

    I developed a Suitelet Form available externally, and used a RESTlet to get the information from the form to create a record.

    In order for the RESTlet to be intialize we must pass credentials, etc in the Suitelet… is this a security risk?

    Can the credentials some how be exposed?

    Thanks,
    David

  7. Marty Zigman says:

    Hi David,

    Restlets need the credential passed as part of the http headers in the request. Because of this, they should only be used in server side applications where you can secure the log in information. See below for code on how to construct the restlet credential:

    String authorization = “NLAuth nlauth_account=” + account + “, nlauth_email=” + email + “, nlauth_signature=”+password+”, nlauth_role=”+role+””;
    post.setHeader( “Authorization”, authorization );
    post.setHeader( “Content-Type”, “application/json” );
    post.setHeader( “Accept”, “*/*” );

    I am a little confused by your implementation, but can you have your Suitelet post to NetSuite and then make another call to the Restlet? I assume the security context of the Suitelet prevents using straight SuiteScript to get at your logic.

    Marty

  8. David says:

    Hi Marty,

    I must have confused you with the last post.

    My implementation works, I just wanted to know if there were any security risks.

    Here’s the logic behind the implementation:
    1. Create Suitelet Form
    2. The deployment of the Suitelet form will be available without login – accessible outside NetSuite through External URL
    3. Create RESTlet to create record based on Suitlet Form input
    3a. Suitlets available without login have limited API’s – RESTlet allows the use of nlapiCreateRecord
    4. Suitelet Form contains header information and credentials to be passed to RESTlet, as well as the JSON string data (form input)

    Are there any risks with the Suitelet form, which is available without login (avaible via external URL), containing the login credentials?

  9. Marty Zigman says:

    Hi David,

    I like this implementation. It should work. Consider that there are multiple http calls which will be slower. You may want to use deployment parameters to keep the credentials outside the script and more configurable.

    As far as risks, there may be some. But I am not sure. NetSuite probably would not endorse this practice. I think they have probably regretted ever offering “Available without Login” SuiteLet capacities. One way they work on these concerns is to avoid giving you the “Built for NetSuite” certification when you are attempting to work in the SuiteCloud Developer Network program.

    Marty

  10. Eric says:

    I’m really interested in using this method to get a user’s cart data from outside the netsuite.com domain. Possible?

    We’re running into an issue where users’ cart data isn’t available to suitescripts, but that seems crazy. Why wouldn’t you expose that data? Is there NO way to get cart data from outside netsuite.com? We’ve also tried sending the request through a proxy, but then it’s not possible to get the user’s cart ID to send as part of the request headers.

  11. Marty Zigman says:

    Hi Eric,

    I think I need more context. Can you lay down a client side script into the web site? if so, can you make a call to the server environment via this JSONP approach? If you are using the Site Builder platform, there is no real server side capacity. But if you are hitting SuiteCommerce Advanced, you can produce server side calls.

    Marty

  12. Mitisha Mehta says:

    Can you share example where the input format to RESTlet is XML/SOAP?

  13. Marty Zigman says:

    Hi Mitsha,

    I am a little confused by your request. Are you trying to call XML/Soap Services from within the REST Tier?

  14. Henry says:

    Is there a unique ID for shopping carts that we can access for use in an API call?

    When a user adds an item to the cart we would like to send the cart’s ID in the API call so we can track abandoned carts.

  15. Nada Khamis says:

    Hi Marty ,
    Thank you for you helpful articles. I have a question. I have an MVC application with Login using Netsuite Credentials (Suitetalk) and through the app i perform search, insert , and update. Now we need to open this application directly from netsuite customer page through a button. Once the MVC application is launched, it should not ask for the user credentials since they already logged into netsuite. How do I do this ? any help is greatly appreciated . Thanks

  16. Marty Zigman says:

    Hi Nada,

    This may be tricky to solve and I am not sure I fully understand your situation. A diagram would help… 🙂 We have done some work with the JSession cookie that is laid down on the client during login. But now that there is token based authentication, my instinct is to see if this can help.

    Marty

  17. Manoj Tyagi says:

    I have an integration with ShipStation where Shipstation makes a GET request to a Suitelet (ENDPOINT) and the Suitelet internally calls (with oAuth) a Restlet to get the data. This works fine.

    The issue is, Shipstation is supposed to send the response (the shipping details like Tracking number etc.) to the same ENDPOINT, as “POST”. It fails with “405 Method not allowed” error.

    I have checked the deployment, Available without login, Run as Administrator , Event Type (tested with alloptions: BLANK, GET request, POST request). No Success

    After readign this post, I added &callback=? at the end of the endpoint.

    Nothing works.
    Can you suggest anything ?

  18. Michael Kubala says:

    Manoj,

    I’m not sure if you’ve already found a solution to your issue, but I encountered that message when I setup my OAuth suitelet as well. The fix that worked for me was adding a header to my request for User-Agent:Mozilla/5.0

  19. Manoj Tyagi says:

    Michael: Yes I used the same. Actually, Shipstation doesn’t Allow to modify the header, so I ended up introducing an intermediate script which transforms the Response and request by adding this. So I am good for now. Thanks

  20. AkberAlwani says:

    Hello Marty,

    Can you share with me the code of this, I already sent you a message.
    I am a newbie and learning still these technologies.

  21. Marty Zigman says:

    Thanks. We are following up via a private conversation.

    Marty

  22. Laura Drill says:

    Hey,

    I am running into trouble similar to the above article when trying to load a file in an iframe of a suitelet. I’m getting the error that “Blocked a frame with origin… from accessing a cross-origin frame”.
    Any ideas?

Leave a Reply

Your email address will not be published. Required fields are marked *