Saturday, December 8, 2018

INVALID_HOST Error 403 on RESTlet Scripts

When debugging a RESTlet, Cookie must always be passed along with the RESTlet header.  Otherwise, Error 403 ("INVALID_HOST", "message" : "Invalid host debugger.netsuite.com. Please send RESTlet requests to https://rest.netsuite.com/.)" is thrown.  The Cookie alone serves as credentials to NetSuite when debugging RESTlets.

Below is a sample HTTP Request of a RESTlet being debugged:

GET https://debugger.netsuite.com/app/site/hosting/restlet.nl?script=267&deploy=1&recordtype=customer&id=7 HTTP/1.1
Content-Type: application/json
Cookie: NS_VER=2012.1.0; JSESSIONID=Y5QpPRrXlhryvJQl9TJXFGvXGfnMw073WxMnWZfxD31f8nMcc0zp1vhyJqCcrhph4mSTfMDYMgd00s39QLPSKPSTMGdnnv1Bq2tTTz9bcGYQKskyMtGQ9vQT1WhSJmPv!-1587019226
Host: debugger.netsuite.com

 

Below is a sample code on how to apply a Cookie on the RESTlet header using C#:

String restletUrl = "https://debugger.sandbox.netsuite.com/app/site/hosting/restlet.nl?script=232&deploy=1&recordtype=customer&id=7";
HttpWebRequest req = WebRequest.Create(new Uri(restletUrl.ToString())) as HttpWebRequest;
req.Method = WebRequestMethods.Http.Get;
req.ContentType = "application/json";
req.Headers.Add("Cookie", "NS_VER=2012.1.0; JSESSIONID=MhMHQ5JZmlCbMv8pG6hzdRqHvGMYhCyN4hd6yc1QRJvcjcTzkJGh8hwQnlw0PHmTyzWyHV2Dghyf4tfC1jpYkyDcpGVt1DKty4n2Z10w1VkShNLyrLxg1Cqc2DYnJZrf!2059529241");


string result = null;
using (HttpWebResponse resp = req.GetResponse() as HttpWebResponse) {
   StreamReader reader = new StreamReader(resp.GetResponseStream());
   result = reader.ReadToEnd();
   Console.WriteLine("Result: " + result);
}

For instructions on how to debug a RESTlet, go to Help Guide > SuiteCloud (Customization, Scripting, and Web Services) > SuiteScript > Understanding NetSuite Script Types > RESTlets > Debugging a RESTlet.

No comments:

Post a Comment