Upload File to Quickbooks

Describe the problem/error/question

I’m trying to upload a file to Quickbooks via API and attach it to a bill. I can upload a file using the normal method of using Form-Data but this just uploads and does not attach.

The QB docs suggest it needs to be send in the following format

--YOjcLaTlykb6OxfYJx4O07j1MweeMFem
Content-Disposition: form-data; name="file_metadata_01"; filename="attachment.json"
Content-Type: application/json; charset=UTF-8
Content-Transfer-Encoding: 8bit

{
   "AttachableRef": [
   {
      "EntityRef": {
      "type": "Invoice",
      "value": "95"
      }
   }
   ],
   "FileName": "receipt_nov15.jpg",
   "ContentType": "image/jpg"
}
--YOjcLaTlykb6OxfYJx4O07j1MweeMFem
Content-Disposition: form-data; name="file_content_01"; filename="receipt_nov15.jpg"
Content-Type: image/jpeg
Content-Transfer-Encoding: base64
<insert base-64 encoded file content here>
--YOjcLaTlykb6OxfYJx4O07j1MweeMFem​--

So, I tried this with Raw content and also used the exact same example in Postman (BTW - there is binary data where it needs to be inserted).

It works in Postman but not in N8N.

I’ve tried sending the same to Webhook site and I think I have the issue - the N8N node is adding it’s won boundary header with a different identifier, meaning the content that is received is empty.

Please share your workflow

Here is my node that I have set up:

Share the output returned by the last node

It returns:

[
  {
    "body": {
      "time": "2024-08-17T04:03:22.352-07:00"
    },
    "headers": {
      "date": "Sat, 17 Aug 2024 11:03:22 GMT",
      "content-type": "application/json;charset=utf-8",
      "transfer-encoding": "chunked",
      "connection": "close",
      "x-spanid": "380df781-c264-2fa2-7eea-783863bb9cc3",
      "x-amzn-trace-id": "Root=1-66c08378-06d1f90d194f45bf517eb06c",
      "x-content-type-options": "nosniff",
      "x-xss-protection": "1; mode=block",
      "qbo-version": "2034.145",
      "service-time": "total=1421, db=17",
      "expires": "0",
      "cache-control": "max-age=0, no-cache, no-store, must-revalidate, private",
      "x-envoy-upstream-service-time": "431",
      "strict-transport-security": "max-age=31536000",
      "intuit_tid": "1-66c08378-06d1f90d194f45bf517eb06c",
      "x-request-id": "1-66c08378-06d1f90d194f45bf517eb06c",
      "server": "istio-envoy"
    },
    "statusCode": 200,
    "statusMessage": "OK"
  }
]

but should return:

{
   "AttachableResponse": [
      {
         "Attachable": {
            "FileName": "receipt_nov15.jpg",
            "FileAccessUri": "...",
            "TempDownloadUri": "https://...",
            "Size": 1594261,
            "ContentType": "image/jpeg",
            "ThumbnailFileAccessUri": "...",
            "domain": "QBO",
            "sparse": false,
            "Id": "100000000004190865",
            "SyncToken": "0",
            "MetaData": {
             "CreateTime": "2015-11-16T10:59:02-08:00",
             "LastUpdatedTime": "2015-11-16T10:59:02-08:00"
            },
            "AttachableRef": [
             {
                "EntityRef": {
                   "value": "95",
                   "type": "Invoice"
                },
                "IncludeOnSend": false
             }
            ]
         }
      }
   ],
   "time": "2015-11-16T10:58:58.100-08:00"
}

Information on your n8n setup

  • n8nVersion: 1.53.2
  • platform: docker (self-hosted)
  • nodeJsVersion: 20.15.0
  • database: sqlite
  • executionMode: regular
  • concurrency: -1
  • license: community
  • consumerId: unknown

Any help you can offer would be great - I’ve been at this for hours but know there is a way around it.

1 Like

It looks like your topic is missing some important information. Could you provide the following if applicable.

  • n8n version:
  • Database (default: SQLite):
  • n8n EXECUTIONS_PROCESS setting (default: own, main):
  • Running n8n via (Docker, npm, n8n cloud, desktop app):
  • Operating system:
  • n8nVersion: 1.53.2
  • platform: docker (self-hosted)
  • nodeJsVersion: 20.15.0
  • database: sqlite
  • executionMode: regular
  • concurrency: -1
  • license: community
  • consumerId: unknow

Hey @revlearn,

Looking at the Quickbooks API and what you are doing I think the confusion is in Quickbooks documentation.

If you are adding a new file to an invoice you need to send 2 files one is a json file that contains the reference information and the other is the actual file.

So you would need to send…

{
   "AttachableRef": [
   {
      "EntityRef": {
      "type": "Invoice",
      "value": "95"
      }
   }
   ],
   "FileName": "receipt_nov15.jpg",
   "ContentType": "image/jpg"
}

and the file in this case receipt_nov15.jpg so your http request node would just need 2 binary items like below.

What Quickbooks expects for this is explained in more detail here: Intuit Developer

@Shaundcmason I believe you were looking for this in an earlier post

Thanks @Jon. That helped and I got it to work.

For anyone else looking for this, here is my workflow. There may be a more efficient way to do this but this worked for me:

The trick is to to create an additional file that includes the Attachable JSOn and convert that to Binary and then sending the 2 files as @Jon suggested. You need to give the JSON file a different name so you can select it, hence the function and merge,

Thanks so much for your help.

2 Likes

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.