+ Start a Discussion
Nitin MuthyalaNitin Muthyala 

INSUFFICIENT_ACCESS_ON_CROSS_REFERENCE_ENTITY when adding file to a content library using REST API

Im tring to replicate some of the Content Library features in my custom app so Im usgint the REST API to achive this. I successfully managed to add  Library features features like 
View Files in Folder (Inside a library)
Download a File 
Rename File
But when I try to Upload a file it says

[{"errorCode":"INSUFFICIENT_ACCESS_ON_CROSS_REFERENCE_ENTITY","message":"Cannot move a file into a folder you do not have access to."}]
Im sending a post request to https://ap1.salesforce.com/services/data/v40.0/connect/folders/07H900000008W0MEAU/items

However if I use the same API to upload to a sync folder I dont have any issues, it works.

Also if i upload a file from the browser it works, so defiantly I have the permission, I have double checked in the permission settings as well I have all permissions to upload a file. 

Doesn anyone know whats the possible reason ?

Hello Nitin, did you find an answer to your issue? We have encountered the exact same error, but aren't sure how to resolve.
Nitin MuthyalaNitin Muthyala
Hello Isalew ! Sorry, so far we couldn't find a solution either. Will update if we ever manage to solve it.
Neil HayekNeil Hayek
Hi Nitin,

The problem is that POST through Chatter REST isn't supported for Libraries.  I know the error message isn't clear.

I'm not sure how to achieve what you want through REST, but using SOAP, you can upload a file to a library by inserting a ContentVersion and setting the FirstPublishLocationId to the libraryId.  Once it's in the library, using SOAP you could update the ContentFolderMember to move it the folder you want, or I think REST would work to move it to a new folder as well (I'm not certain).

One possibily I haven't tried to use ONLY rest would involve:
  1. Uploading the file to the user (not in a library) so it will be private to the user
  2. Using the File Shares (https://developer.salesforce.com/docs/atlas.en-us.chatterapi.meta/chatterapi/connect_resources_files_shares.htm) endpoint to share the file with the library you want
  3. Move the file to the folder you want
I understand the current options are convoluted, and I will log a user story to address the REST api for libraries.