Automate Salesforce File Sharing as Public Link with Chatter REST API
In certain use cases you may have a need to share files on a record or group with people outside your organisation. E.g. You’re working on a project with stakeholders outside your organisation.
Here is a Chatter Rest API which allows 1 link per a file
and an SObject API which allows multiple, as well as setting other options.
Our Lightning UI uses the Connect API, but if you do something custom, you’d probably want to use SObject.
You can trigger on many files actions, such as upload to create such links.
Chatter REST API Example
Use Case: File attached to a record and we want to share it as we do with the Public Link Sharing via UI. Chatter REST API PUT action to /services/data/v43.0/connect/files/<FileID>/file-shares/link with this body
{
"sharingType" : "V"
}
here the API message response containing the URL for the file thats shared:
{
"fileViewUrl" : "https://xxxxdomain.my.salesforce.com/sfc/p/1H000000NiOk/a/1H000000Xgo9/d1mg90l6hgr87uJ2TAPZBV2sn7tleCLPp5eKJThXf8s", "sharingType" : "V"
}
and here other options but for the public share the V sounds good enough
Of course another option here is to use a community portal to securely share the file(s) with a group of users but sharing this lightweight approach in case it is useful for others.