Hi,
I am trying to download 2 PDF files from RESTLet code - both from different hosts/urls. Once succeeds, the other fails with an "unexpected error" when nlapiReuqestURL is called.
The calling code is the same, just the URL differs:
// Setting up Headers
var headers = new Array();
headers['Accept'] = 'application/json'; // must be json (null or pdf returns "not acceptable" from the server side)
headers['Content-Type'] = 'application/json';
headers['Authorization'] = 'Bearer ' + access_token;
headers['client_id'] = client_id;
// Submit Request - Throws "Unexpected Error"
var response = nlapiRequestURL( encodeURI(myURL), null, headers );
NOTE: The token code works fine for simple API endpoints that return JSON. It;s only when I ask for a PDF file that it filas so it's not that.
They both return fine in Postman. Here are the postman result headers:
This one is OK in postman and NetSuite:
Accept-Ranges →bytes
Connection →Keep-Alive
Content-Length →1111632
Content-Type →application/pdf
Date →Thu, 06 Nov 2014 03:45:54 GMT
ETag →"41bfc6b-10f650-4394b3eb19b00"
Keep-Alive →timeout=1
Last-Modified →Tue, 04 Sep 2007 08:40:44 GMT
Server →Apache/2.2.24 (Unix) mod_ssl/2.2.24 OpenSSL/1.0.0-fips mod_pubcookie/3.3.4a mod_uwa/3.2.1 Phusion_Passenger/3.0.11
This one is OK in Postman but fails in NetSuite with the "Unexpected Error":
Authorization →Bearer xxxxx
Connection →keep-alive
Content-Type →application/pdf
Date →Thu, 06 Nov 2014 03:48:11 GMT
Server →nginx
X-MULE_ENCODING →UTF-8
X-MULE_ENDPOINT →https://api.endpoint
X-MULE_ROOT_MESSAGE_ID →ba28cb30-6567-11e4-8eed-0654f24a0ad6
X-MULE_SESSION xxxxx
X-PingFederate-username →blah@blah.com
transfer-encoding →chunked
So I am pretty sure there is some difference in the way the data is returned, not in the way it is requested. Is it an encoding issue? Or content length?
Thanks,
Rich