2

I'm building a headless solution on top of Salesforce and using Community Users to log in.

I want those users to be able to upload files to a case. In experience builder it is calling this endpoint to upload the file: POST https://experience-site/chatter/handlers/file/body with the authentication headers and multipart/form-data.

When I try to do this with Postman and my access token I have from 0Auth2 I get the following:

{
    "errormessage": "The action you performed was invalid for your session. Please refresh your page and try again."
}

Using the REST API to POST a new ContentVersion (POST /services/data/v58.0/sobjects/ContentVersion) I get this:

[
    {
        "message": "You do not have the level of access necessary to perform the operation you requested. Please contact the owner of the record or your administrator if access is necessary.",
        "errorCode": "INSUFFICIENT_ACCESS_ON_CROSS_REFERENCE_ENTITY",
        "fields": [
            "NetworkId"
        ]
    },
    {
        "message": "You must have a valid content feature license to publish into a private library.",
        "errorCode": "INVALID_ID_FIELD",
        "fields": [
            "FirstPublishLocationId"
        ]
    }
]

How can I let community users upload files so I get back the ContentVersionId I need to attach it to a Case?

1
  • Have you found a solution to this error message?
    – tugce
    Commented Jun 12, 2023 at 16:04

1 Answer 1

2

I figured it out and it's better to use the REST Object API for this.

You can upload a new files with:

POST /services/data/v58.0/sobjects/ContentVersion
{
    "Title": "test",
    "PathOnClient": "test.txt",
    "ContentLocation": "S",
    "VersionData": "base64 encoded file"
    "NetworkId": :networkId
}

Then get the ContentDocumentId with the following call:

GET /services/data/v58.0/sobjects/ContentVersion/:ContentVersionId

Then Post a ContentDocumentLink to link the attachment to i.e. a Case object:

POST /services/data/v58.0/sobjects/ContentDocumentLink
{
    "ContentDocumentId": :ContentDocumentId,
    "LinkedEntityId": :CaseId,
    "ShareType": "I",
    "Visibility": "AllUsers"
}

For ShareType / Visibility options see: https://developer.salesforce.com/docs/atlas.en-us.object_reference.meta/object_reference/sforce_api_objects_contentdocumentlink.htm

1
  • Thanks for adding an answer. I did also figure out the issue (I was already using Rest API), adding NetworkId fixed the problem for me.
    – tugce
    Commented Jun 15, 2023 at 9:15

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .