Andrew Luke
10/18/2024, 1:37 AMCeligo AI
10/18/2024, 1:38 AMAI generated answer (using internal Slack threads):Based on the conversations, it seems that the issue is related to the handling of binary content in NetSuite. When you make a GET request to an API that returns a PDF file, the response body is treated as a UTF-8 string by NetSuite. This can lead to encoding errors and the PDF file being corrupted. To solve this issue, you need to ensure that the Content-Type header of the response is recognized by NetSuite as binary. Ideally, this should be
application/pdf
. If the Content-Type header is correctly set, the response body should be in base64 format, which you can directly save into the file cabinet.
Here is a sample code snippet:
javascript
let result = https.get({
url: url+'/api/v1/wps/'+row.wp_id+'/log-exports/'+row.pdf_id+'/download',
headers: {
Authorization: 'Bearer '+token_id,
Host: url,
Accept: '*/*'
}
});
let filePdf = file.create({
name: logPdf.fileName,
fileType: file.Type.PDF,
contents: result.body,
folder: 4127544
});
In this code, result.body
is the base64 encoded content of the PDF file. This is directly used as the contents of the file being created.
If the server you are working with can't set the Content-Type header to exactly application/pdf
, you might need to look for alternatives.
******
Disclaimer:
This response was generated by an artificial intelligence assistant based on previous conversations from multiple Slack channels, and may contain inaccuracies or mistakes.
******Celigo AI
10/18/2024, 1:38 AMSlack thread 1: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.840017557
Slack thread 2: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.831069231
Slack thread 3: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.820939302
Celigo AI
10/18/2024, 1:38 AM