Hi everyone, i'm making a request to an api to obt...
# suitescript
a
Hi everyone, i'm making a request to an api to obtain a pdf , with this code:
filePDFId = file.create({
name: transactionType + '_' + transactionId + '.pdf' ,
fileType: file.Type.PDF,
contents: responsepdf.body,
description: 'PDF document for ' + transactionType + ' ' + transactionId,
folder: getOutboundDocumentsFolderID('Outbound PDF Documents'),
isOnline: false,
}).save();
but it show me an error , and when i tried to convert to base64, save the pdf in blank. the error without converting is: Intenó escribir datos no binarios en un archivo binario 'invoice_9755.pdf' del tipo 'PDF'. Los datos binarios deben estar codificados como cadenas base64. Usted proporcionó los siguientes datos: %PDF-1.4 %���� 1 0 obj </Producer (Skia/PDF m125) /CreationDate (D:20241210192442+00'00') /ModDate (D:20241210192442+00'00')>> endobj 3 0 obj </ca 1 /LC 0 /LJ 0 /LW 1 /ML 4
m
What is the encoding of
responsepdf.body
?
a
const headers = { 'Content-Type': 'application/pdf', 'Accept': 'application/pdf', 'ApiKey': credentials.apikey, 'CurrentCompanyId': credentials.currcompid, 'Country': credentials.country, 'Authorization': AuthHeader, }; return https.get({ url: url, headers: headers, });
i
im confused as to what you are trying to do? are you trying to create a pdf and store in the filecabinet? or are you just trying to get a pdf file for a transation on the fly?
a
i want to save it in the cabinet, the issue is that when I convert it to Base64, the PDF is saved in the cabinet, but it’s empty. However, when I don’t convert it, I get the error I previous mentioned.
i
what does responsepdf.body look like?
a
in postman looks like:
i
and your making your call to a restlet? why dont you send the data as bade64 encoded already
a
is in a electroninc invoicing plugin, when make the certification try to obtain the pdf and save it in the cabinet but show me the error when dont make the convert
const responsepdf = getDocumentPDFNew(transactionId, transactionType, idAuth);
filePDFId = file.create({
name: transactionType + '_' + transactionId + '.pdf' ,
fileType: file.Type.PDF,
contents: responsepdf.body,
description: 'PDF document for ' + transactionType + ' ' + transactionId,
folder: getOutboundDocumentsFolderID('Outbound PDF Documents'),
isOnline: false,
}).save();
b
the only thing that matters is the headers of the response, not the request
if the contet type of the response is one of the ones that netsuite recognizes as binary, then it will base 64 encode the binary
if the content type of the response isnt one of the ones that netuiste recongize as binary, then it will will assume that the response is plain text and encode it to utf-8
encoding binary content as utf-8 will destroy it like the text in the screenshot you shared in postman
there is no recovery from ut-8 encoding errors