Hi @Sainath Jaybhaye,
A 403 error when trying to post a file from Salesforce to a SharePoint folder typically indicates an issue with permissions or authentication. Here are some steps to troubleshoot and potentially resolve the issue:
1.Verify SharePoint Permissions:
Double-check the permissions on the SharePoint folder where you are trying to post the file. Ensure that the Salesforce integration user (the user making the request) has the necessary permissions to add files to the folder.
2.Authentication:
Ensure that you are correctly authenticated with SharePoint. If you are using callouts to SharePoint, make sure that you have configured the authentication correctly. You may need to use OAuth or other suitable authentication methods.
HttpRequest httpRequestToSend = new HttpRequest();
String pathToStoreFile = '/sites/Communication%20site/_api/web/GetFolderByServerRelativeUrl(\'/Shared%20Documents\')/files/add(url=\'document3.txt\',overwrite=true)';
httpRequestToSend.setEndpoint('callout:SharepointsFiles' + pathToStoreFile);
httpRequestToSend.setMethod('POST');
httpRequestToSend.setHeader('Content-Type', 'application/octet-stream'); // Set the appropriate content type
httpRequestToSend.setHeader('Authorization', 'Bearer ' + yourAccessToken); // Include your SharePoint access token here
httpRequestToSend.setBody(Blob.toPDF('test Message')); // Ensure that you are setting the appropriate content as per your requirements
System.debug('***** httpRequestToSend-->' + httpRequestToSend);
Http http = new Http();
HttpResponse httpResponse = http.send(httpRequestToSend);
System.debug('***** httpResponse-->' + httpResponse);
In this code, make sure to replace yourAccessToken
with the actual access token required for SharePoint authentication. You should also ensure that the content type and body of the request are correctly set according to SharePoint's requirements.
If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.
Best Regards
Cheng Feng