I'm trying to programmatically upload a file (AttachedContentDocument) to an Account as an attachment using the REST API. This doesn't seem to be documented by Salesforce.
When I use the Lightning UI to upload the file on the "Documents" tab of an account, the URL it opens is /lightning/r/AttachedContentDocument/id...
so I'm trying to upload a AttachedContentDocument
.
I'm crafting a request body that looks like:
--boundary_string
Content-Disposition: form-data; name="entity_attachedcontentdocument";
Content-Type: application/json
{
"Title": "hello",
"FileExtension": "png"
}
--boundary_string
Content-Type: application/png
Content-Disposition: form-data; name="Body"; filename="myfile.png"
... binary data of file ....
All of the examples online for inserting files into salesforce use this multipart body. Note I changed the name to name="entity_attachedcontentdocument"
to reflect the sObject type being inserted. Then I craft a request:
curl https://mydomain.salesforce.com/services/data/v53.0/sobjects/AttachedContentDocument/ -H 'Authorization: ...' -H "Content-Type: multipart/form-data; boundary="boundary_string"" --data-binary @binaryjson
This errors with:
[{"message":"Invalid field: 'Body'","errorCode":"INVALID_FIELD"}]
Looking at the AttachedContentDocument
documentation page there's no documentation on which field data is supposed to go into.
I get the same error changing the endpoint and entity name to /ContentDocument/
. And no field name seems to work, not Body/Content/File.
Is it possible to use this API?