avadev / AvaTax-REST-V2-JS-SDK

Sales Tax API SDK for Javascript / Node and AvaTax REST
https://developer.avalara.com/sdk/
Apache License 2.0
28 stars 37 forks source link

uploadCertificateImage does not work as intended #252

Closed dan2kx closed 1 year ago

dan2kx commented 1 year ago

When trying to upload a certificate image using the node client i get the following error message:

  code: 'InvalidRequestContentType',
  target: 'HttpRequest',
  details: [
    {
      code: 'InvalidRequestContentType',
      number: 1217,
      message: 'The request content type is invalid.',
      description: "The request content type must be either 'multipart/form-data' or empty string.",
      faultCode: 'Client',
      helpLink: 'http://developer.avalara.com/avatax/errors/InvalidRequestContentType',
      severity: 'Error'
    }
  ]

it looks like the rest client is always set to send application/json

i have had to handle this manually:

    const file = fs.readFileSync(path.join(__dirname, filename));

    if (file) {
      const formData = new FormData();

      formData.append("file", new Blob([file]));

      return fetch(
        `https://sandbox-rest.avatax.com/api/v2/companies/${1}/certificates/${
         certificateId
        }/attachment`,
        {
          method: "POST",
          body: formData,
          headers: {
            Authorization: createBasicAuthHeader(creds.accountId, creds.licenseKey),
          },
        }
      )
        .then((response) => response.json())
        .catch((err) => console.log(err));
svc-developer commented 1 year ago

Fixed in release 23.3.0 Please give it a try and let us know if you have any further issues https://github.com/avadev/AvaTax-REST-V2-JS-SDK/releases/tag/23.3.0