This topic contains 2 replies, has 0 voices, and was last updated by CREECE 7 years, 9 months ago.

  • Author
    Posts
  • #5976 Score: 0

    CREECE
    • Contributions: 0
    • Level 1

    I have a RESTlet that I have written that I am trying to call using Token Based Authentication (TBA) and via client code where I am already authorized. Using TBA, I get my data back and I am able to JSON.parse my body and everything works fine. Using client code however, even after setting the content-type to application/json, I get an error stating that I should be returning TEXT (which is the default Content-Type) which is not what I am expecting. If I JSON.stringify my results when returning in the restlet, my client code works fine but in my TBA code I have to do 2 JSON.parses in order to get it to an object. Seeing as how i’ve set my content-type, I should not need to stringify anything and my client code should respect the type.

    The ONLY difference between my 2 calls is that my client code is already authorized and I am just using nlapiResolveURL(‘RESTLET’, a, b) to get the internal URL whereas my TBA code is using the external URL and passing along all of the TBA stuff.

    Also, has anyone noticed that using nlapiResolveURL(‘RESTLET’, a, b, true); where true returns the external URL does not work either? From NetSuite help: Important

    If the type argument is set to SUITELET or RESTLET, set displayMode to true to return an external URL. Set displayMode to false, or simply omit the argument, to return an internal URL. For Suitelets and RESTlets, displayMode automatically defaults to false.

    So seeing as how this method throws an SSS_INVALID_TYPE_ARG error when setting to true, there is no way to retrieve the external URL of the RESTlet which forces a user to have to use the rest domains webservice to get the domains and then attach that to the internal URL.

    Has anyone run into either of these issues? any idea on how to solve?

    Thanks!
    This is a cached copy. Click here to see the original post.

  • #5977 Score: 0

    pcutler
    • Contributions: 0
    • Level 1

    I have encountered both of these issues, but haven’t spent too much time investigating them. For the first issue, I took the same approach and used JSON.parse on the stringified object. For the second issue:

    there is no way to retrieve the external URL of the RESTlet which forces a user to have to use the rest domains webservice to get the domains and then attach that to the internal URL.

    Depending what permissions your code is running under, this might work:

    var deployResults = nlapiSearchRecord(‘scriptdeployment’, null, [‘scriptid’, ‘is’, ‘customdeploy_xxxx’]);

    var deployId = deployResults[0].getId();

    var deployRecord = nlapiLoadRecord(‘scriptdeployment’, deployId);

    var url = deployRecord.getFieldValue(‘externalurl’);

    return url;

  • #5978 Score: 0

    CREECE
    • Contributions: 0
    • Level 1

    Thanks for the response pcutler

    For now, I am going to just use the external URl call. 2 JSON.parses seems a bit hacky to me and I don’t want to do it just yet if I don’t have to.

    In terms of the external URL, i’ve talked to some other people and this does seem to be a bug in NetSuite. For example, if you have a suitelet, you can only get the external url using this method if it is set to “available without login”. For now, I am going to use netsuite’s rest service to retrieve the available domains for the account and just tack on the internal url as that will not change. This will ensure I am at least up to date on the domain portion of it.

You must be logged in to reply to this topic.