How to save Quickbooks PDF response in Nest JS

44 Views Asked by At

I am trying to call the Quickbooks API from Nest JS using HttpService(axios). It returns the response in this format

application/pdf

which is not readable for Nest JS application. I tried to decode it using this library

iconv-lite

But no luck.

Now if I return the data like this

// Set appropriate headers for download
res.setHeader('Content-Type', 'application/pdf');
res.setHeader('Content-Disposition', `attachment; filename=221.pdf`);

// Send the PDF buffer as the response
res.send(My PDF Data);

It returns a blank pdf file in Postman but if I hit the Quickbooks API directly, it provides my desired output

Below is the sample response from QuickBooks API

    %PDF-1.7
4 0 obj
<</Type /Page/Parent 3 0 R/Contents 5 0 R/MediaBox [0 0 612 792]/Resources <</Font <</FAAAAH 7 0 R/FAAAAJ 9 0 R/FAAABC
    12 0 R>>/XObject<</X1 14 0 R>>>>/Group <</Type/Group/S/Transparency/CS/DeviceRGB>>>> endobj 5 0 obj <</Length 15 0
            R/Filter /FlateDecode>>stream x��[mo�6�+�ݰ0|����M�&M���p�1�ح�n˿ߑ�e��l�u�fh�:R>
            ���xw$��nQ��-Co��GD}E�
            �%fBj�t�[�F��V���r��T�ɠ�ݑ�\��h�ݒЋ(���-���Fc4�+�����\טX�1B�JN�N���v&B�I�G\/�Tr9�!��H"���p�"V�AD��Sǃ����R9@�zЩ��_h'US窡#��$Dž�0d��n�6�(�s�^S*M�}��p~#JP�]a��A���J�>���3h|�fFj*8��G�Ճ�`r�f�/ڛ^}Ln_��^�_�B�'蠟=�؆���@x�t8����'��8�P�Qo4����ප6��c��j�l�uz������7����q_�8ȝ[�Z�2���!6h��.��l�a|���O���o���k�vz�X�{c���/��0
            ���Sΰ�r�zP����&��D@�
0

There are 0 best solutions below