intuit / oauth-jsclient

Intuit's NodeJS OAuth client provides a set of methods to make it easier to work with OAuth2.0 and Open ID
https://developer.intuit.com/
Apache License 2.0
120 stars 154 forks source link

Adding Transport Override for PDF use case #98

Closed haislip closed 3 years ago

haislip commented 3 years ago

https://github.com/intuit/oauth-jsclient/issues/97

In order to save the PDF generated from the APIs properly, the transport passed into the popsicle API needs to be one of type "buffer" instead of "text" (which is the default). This changes keeps the default of using "text", but allows the calling function to pass in the override.

abisalehalliprasan commented 3 years ago

Thanks, @haislip for the contribution. This PR will go in our next release.

krishnal commented 3 years ago

hi @abisalehalliprasan

Any idea when this will be published over npm? Seems like you merged it but i think it's not published yet.

sdegutis commented 3 years ago

The /pdf route is broken until this is pushed to NPM. Not that I'm part of the dev team, but I just reviewed and verified it and it looks good, and there is currently no non-patching workaround to this afaik.

abisalehalliprasan commented 3 years ago

@sdegutis : Just curious what is the transport that you passed to the makeApiCall method ?

Would it be similar to :

oauthClient
    .makeApiCall({ url: `${url}v3/company/${companyID}/invoice/${invoiceNumber}/pdf?minorversion=59` , transport: popsicle.createTransport({type: "buffer"})})
sdegutis commented 3 years ago

Yep

abisalehalliprasan commented 3 years ago

I get a server error. wondering if the transport parameter that I have passed is correct :

    response: Response {
      Url: [Url],
      rawHeaders: [Array],
      body: <Buffer 7b 22 46 61 75 6c 74 22 3a 7b 22 45 72 72 6f 72 22 3a 5b 7b 22 4d 65 73 73 61 67 65 22 3a 22 41 6e 20 61 70 70 6c 69 63 61 74 69 6f 6e 20 65 72 72 6f ... 184 more bytes>,
      status: 500,
      statusText: 'Server Error'
    },
    body: <Buffer 7b 22 46 61 75 6c 74 22 3a 7b 22 45 72 72 6f 72 22 3a 5b 7b 22 4d 65 73 73 61 67 65 22 3a 22 41 6e 20 61 70 70 6c 69 63 61 74 69 6f 6e 20 65 72 72 6f ... 184 more bytes>,
    json: { Fault: [Object], time: '2021-05-26T14:33:13.224-07:00' },
    intuit_tid: '1-60aebe99-2bd8211b0a8e83d913308d52'
  },
  originalMessage: 'Response has an Error',
  error: 'Server Error',
  error_description: 'Server Error',
  intuit_tid: '1-60aebe99-2bd8211b0a8e83d913308d52'
abisalehalliprasan commented 3 years ago

@sdegutis : I did not pass the Accept header also as application/pdf

.makeApiCall({ url: `${url}v3/company/${companyID}/invoice/2/pdf?minorversion=59` , headers:{'Content-Type': 'application/pdf','Accept':'application/pdf'}, transport: popsicle.createTransport({type: 'buffer'})})

This returns a binary BLOB for the pdf response. Thanks for your help. I am good here 👍