Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handling multipart/form data to upload items to the attachable endpoints. #152

Open
devcaco opened this issue Feb 4, 2024 · 1 comment

Comments

@devcaco
Copy link

devcaco commented Feb 4, 2024

I was wondering if this library supports uploading files to the attachable endpoint? Currently if I try to do this.

`const image = images[0];
const imageFile = fs.createReadStream(image.rawInfo.path);

    const uploadedImage = await QBFileUpload(
      image.rawInfo.filename,
      image.rawInfo.mimetype,
      imageFile,
      'Item',
      newQBProduct.Id
    );

    console.log({ uploadedImage });

    const form = new FormData();

    form.append('file_content_01', imageFile, {
      filename: image.rawInfo.filename,
      contentType: image.rawInfo.mimetype,
    });

    form.append(
      'file_metadata_01',
      JSON.stringify({
        AttachableRef: [
          {
            EntityRef: { type: 'Item', value: newQBProduct.Id },
          },
        ],
        ContentType: image.rawInfo.mimetype,
        FileName: image.rawInfo.filename,
      }),
      {
        contentType: 'application/json',
        filename: 'file_metadata_01',
      }
    );

    console.log({ formHeader: form.getHeaders() });

    const imageResponse = await qbClient.makeApiCall({
      url: `${process.env.QB_API_URL}/v3/company/${process.env.QB_COMPANY_ID}/upload?minorversion=69`,
      method: 'POST',
      headers: {
        ...form.getHeaders(),
      },
      body: form,
    });`

I get a response error: Content length missing in request","Detail":"We cannot find the content-length header in the request.","code":"6020"}

Thanks

CES

@rajeshgupta723
Copy link
Collaborator

rajeshgupta723 commented Feb 19, 2024

Hi,

We do not have support for multipart/form-data at the moment.
Appreciate it if you have can put in a PR if you have it handy.

Please see the API references for uploading attachment:
https://developer.intuit.com/app/developer/qbo/docs/workflows/attach-images-and-notes#attaching-a-file-to-an-object

Error codes (e.g. 6020) in your case reflects that Content length is missing in request and Can’t find the content-length header, as per the QBO V3 API error codes: https://developer.intuit.com/app/developer/qbo/docs/develop/troubleshooting/error-codes

Try passing Content-Length in the header. e.g.
''Content-Length': Buffer.byteLength(body)

Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants