Upload Binary Doc to Salesforce using ContentVersion API

Describe the problem/error/question

I am trying to upload a pdf documment to Salesforce using the ContentVersion API. I can get the API call to work in CURL and Postman but cannot seem to get it to work in n8n. My prior node successfully gets the PDF and uses the default field name “data”, I can view and download the file. I have tried using the HTTP Request node to peform the same call without luck both importing the CURL and creating from scratch. I’ve tried a couple variations where you send all the non-binary info via entity_content as well as using separate form-data fields for each text value. I have also tried using the “RAW” option, but always get the multipart error message (see below)

What is the error message (if any)?

Multipart message must include a non-binary part (see below)

Here is the CURL which I am able to use succesfully

curl --location ‘https://<MY_SALESFORCE>.salesforce.com/services/data/v62.0/sobjects/ContentVersion’
–header ‘Authorization: Bearer <MY_BEARER_TOKEN>’
–header ‘Cookie: BrowserId=ran5c-8EEe-piOV_YXtb8Q; CookieConsentPolicy=0:1; LSKey-c$CookieConsentPolicy=0:1’
–form ‘entity_content=“{"Title":"CustomizedReport","PathOnClient":"IP103report.pdf", "FirstPublishLocationId": "a0Nct000000qHftEAE"}”;type=application/json’
–form 'VersionData=@“/Users//Downloads/work_order_335.pdf”

Please share your workflow

{
“nodes”: [
{
“parameters”: {
“method”: “POST”,
“url”: “https://<MY_SALESFORCE>.salesforce.com/services/data/v62.0/sobjects/ContentVersion”,
“sendHeaders”: true,
“headerParameters”: {
“parameters”: [
{
“name”: “Authorization”,
“value”: “Bearer <MY_BEARER_TOKEN>”
}
]
},
“sendBody”: true,
“contentType”: “multipart-form-data”,
“bodyParameters”: {
“parameters”: [
{
“name”: “entity_content”,
“value”: “{"Title":"CustomizedReport","PathOnClient":"IP103Inspection.pdf", "FirstPublishLocationId": "a0Nct000000qHftEAE"}”
},
{
“parameterType”: “formBinaryData”,
“name”: “VersionData”,
“inputDataFieldName”: “data”
}
]
},
“options”: {}
},
“type”: “n8n-nodes-base.httpRequest”,
“typeVersion”: 4.2,
“position”: [
1340,
20
],
“id”: “70ce3d07-f5ed-4318-9148-dfbfc0def613”,
“name”: “HTTP Request”
}
],
“connections”: {
“HTTP Request”: {
“main”: [

]
}
},
“pinData”: {},
“meta”: {
“templateCredsSetupCompleted”: true,
“instanceId”: “4cf87b053818c94970a26b26a1d49a4554be81c871b7fc39918fab0cdd14c239”
}
}

Share the output returned by the last node

Error code

400

Full message

400 - “[{"message":"Multipart message must include a non-binary part","errorCode":"INVALID_MULTIPART_REQUEST"}]”
Request

{ “headers”: { “authorization”: “hidden”, “accept”: “application/json,text/html,application/xhtml+xml,application/xml,text/;q=0.9, image/;q=0.8, /;q=0.7”, “content-type”: “multipart/form-data; boundary=--------------------------193924788825046287331893” }, “method”: “POST”, “uri”: “https://dream-connect-482--inlab.sandbox.my.salesforce.com/services/data/v62.0/sobjects/ContentVersion”, “gzip”: true, “rejectUnauthorized”: true, “followRedirect”: true, “resolveWithFullResponse”: true, “followAllRedirects”: true, “timeout”: 300000, “formData”: { “_overheadLength”: 311, “_valueLength”: 113, “_valuesToMeasure”: [ { “fd”: null, “path”: “/home/node/.n8n/binaryData/workflows/YDJwPRiSq5qtySo1/executions/1706/binary_data/1a55f009-d507-4e67-a26d-7206d9dce5e7”, “flags”: “r”, “mode”: 438, “end”: null, “bytesRead”: 28565, “_events”: {}, “_readableState”: { “highWaterMark”: 65536, “buffer”: , “bufferIndex”: 0, “length”: 0, “pipes”: , “awaitDrainWriters”: null }, “_eventsCount”: 2 } ], “writable”: false, “readable”: true, “dataSize”: 0, “maxDataSize”: 2097152, “pauseStreams”: true, “_released”: true, “_streams”: , “_currentStream”: null, “_insideLoop”: false, “_pendingNext”: false, “_boundary”: “--------------------------193924788825046287331893”, “_events”: {}, “_eventsCount”: 3 }, “encoding”: null, “json”: false, “useStream”: true }

Information on your n8n setup

  • n8n version:
    Cloud Version 1.85.4

  • Database (default: SQLite):
    Default

  • n8n EXECUTIONS_PROCESS setting (default: own, main):

  • Running n8n via (Docker, npm, n8n cloud, desktop app):
    Cloud

  • Operating system:
    Mac Os Sequoia 15.0.1 (24A348)

I ended up solving this by just using an AWS lambda/python. n8n calls it like an API and it uploads the attachment and returns the response from Salesforce. Not sure why the HTTP Node in n8n couldn’t do the same - seems like some work needs to be done there to improve the product.

1 Like

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