RESTLet https.request to third parties i.e SharpSpring

Good evening, everyone

I am attempting to send a POST via RESTLet to the third party API SharpSpring. I have sent this POST with 200 response via POSTMAN. Also used a test Apache2 server using PHP and also received a successful 200 response. RESTLet status code returns a 406 error.

I have tried many and very few headers. I have also tried and https.request along with several permutations. Clicking on the deployed script internal URL via NetSuite interface, it goes through “get” entry instead of “post”, not sure if that matters as method is invoked and also not sure how to get NetSuite to force “post” entry point.

Pasted is the code. I removed the Keys and token values:


*@NApiVersion 2.1

*@NScriptType Restlet

        let titleValue='';
        function pull(){
            let ACCT_ID="xxxx";
            let SCT_KEY="yyyy";
            let urlSS=""+ACCT_ID+"&secretKey="+SCT_KEY;
            let headerL = [
                {"Connection": "keep-alive"},
                {"Content-Type": "application/json"},
                {"Accept-Post": "*/*"},
                {"Content-Length": 79}, //79 is the calculated value upon 200 response via POSTMAN
                {"Cache-Control": "no-cache"}
            let reqBody = {
                "method": "getLeads",
                "params": {"where": {}},
                "id": "9999"
            let resp=https.request({
                method : https.Method.POST,
                url: urlSS,
                header: headerL,
                body: JSON.stringify(reqBody)
            prep="<p>Attempting to pull data from Sharp Spring.</p>";
            stat="<p>status: "+resp.code+"</p>";
            body="<p>body: "+resp.body+"</p>";
            return '<html lang="en"><head>'+title+'</head><body>'+urlSS+prep+stat+body+'<p>Script done</p></body></html>';
        return {
            get: function(){
                titleValue="NS GET entry";
                return pull();
            post: function(){
                titleValue="NS POST entry";
                return pull();

Here html result:
Attempting to pull data from Sharp Spring.
status: 406
Script done

Thank you all for your help in advance.

Rookie Asked on December 1, 2022 in SuiteScript.
Add Comment
1 Answer(s)

Answered my own question. Although it took a very long while.

Main issue is this header:

{"Accept-Post": "*/*"} MUST BE {"Accept": "*/*"}

If your GET or POST request is working everywhere else BUT NetSuite, it is most likely because you are lacking this header value.

Also an incorrect way to list headers must be {“h1_key”: “h1_value”, “h2_key”: “h2_value”, “Accept”: “*/*”, “etc1”, “etc2”}

in the http.posts OR http.requests (line 33 in my code abouve) it is ‘headers’ NOT ‘header’ (I have headers in other failed implementations).

The POST worked for me on a RESTLet and Suitelet (even through RESTLet’s “get” entry point).

Rookie Answered on December 2, 2022.
Add Comment

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.
  • This site made possible by our sponsors:   Tipalti   Celigo   Limebox   Become a Sponsor   Become a Sponsor