Hi,
To use SharePoint REST API, do I need to provide any permissions to the SharePoint service to be consumed?
if yes, then what would be those permissions?
Thanks,
Sadaf Zaheer
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Hi,
I am trying to copy files from Shared point library to Blob Storage by using Azure function app if that's possible - Though I've seen one method by using logic apps.
Can any one guide me on that?
Hi,
To use SharePoint REST API, do I need to provide any permissions to the SharePoint service to be consumed?
if yes, then what would be those permissions?
Thanks,
Sadaf Zaheer
Hi @Zaheer. Sadaf (Enterprise Services)
Thank you for posting this in Microsoft Q&A.
Yes, To copy files from SharePoint to Azure Blob Storage using an Azure Function App. Here's a steps
1. Create Azure Function App:
Set up a Function App in Azure.
Choose a Consumption Plan for cost-efficiency.
2. Create a Blob Trigger Function:
Create a function triggered by an HTTP request.
Use a Blob output binding to write files to Blob storage.
3. Install Required NuGet Packages:
Install packages for SharePoint Online CSOM and Azure Storage.
4. Write Function Logic:
Authenticate to SharePoint.
Retrieve files from the specified list or folder.
Download files from SharePoint.
Upload files to Blob storage using the output binding.
I hope this helps! Please mark as "Accept the answer" if the above steps helps you. Your suggestion will help others!
Hi @Zaheer. Sadaf (Enterprise Services)
Please accept as "Yes" if the answer was helpful, so that it can help others in the community.
Hi @Zaheer. Sadaf (Enterprise Services)
Yes, you need to provide permissions to the SharePoint service you want to consume using the REST API. These permissions determine what actions you can perform on the service.
There are two main ways to provide permissions:
Yes Zaheer, it's possible to copy files from SharePoint library to Blob Storage using Azure Function App. Here's a step-by-step guide:
Prerequisites:
Method 1: Using SharePoint REST API and Azure Storage SDK
Microsoft.SharePoint.Client
Microsoft.Azure.Storage.Blob
C# Example:
using Microsoft.SharePoint.Client;
using Microsoft.Azure.Storage.Blob;
[FunctionName("CopyFileToBlob")]
public static async Task Run(
[TimerTrigger("0 */5 * * * *")] TimerInfo myTimer,
ILogger logger)
{
// SharePoint authentication
var clientContext = new ClientContext("(link unavailable)");
clientContext.ExecutingWebRequest += (sender, e) => {
e.WebRequestExecutor.RequestHeaders["Authorization"] = "Bearer " + GetAccessToken();
};
// Retrieve file from SharePoint library
var file = clientContext.Web.GetFileByUrl("(link unavailable)");
clientContext.Load(file);
await clientContext.ExecuteQueryAsync();
// Upload file to Blob Storage
var storageAccount = CloudStorageAccount.Parse("DefaultEndpointsProtocol=https;AccountName=your-storage-account;AccountKey=your-storage-key;BlobEndpoint=(link unavailable)");
var blobClient = storageAccount.CreateCloudBlobClient();
var container = blobClient.GetContainerReference("your-container");
var blob = container.GetBlockBlobReference("your-file.txt");
await blob.UploadFromStreamAsync(file.OpenBinaryStream());
}
Method 2: Using Microsoft Graph API and Azure Storage SDK
Node.js Example:
const { Client } = require('@microsoft/microsoft-graph-client');
const { BlobServiceClient } = require('@azure/storage-blob');
const client = new Client(clientId, clientSecret, tenantId);
const blobServiceClient = new BlobServiceClient(`https://${storageAccountName}.(link unavailable)`, storageAccountKey);
module.exports = async function (context, timer) {
// Retrieve file from SharePoint library using Microsoft Graph API
const file = await client.api('/sites/your-site/drive/items/your-file-id/$value').get();
// Upload file to Blob Storage
const containerClient = blobServiceClient.getContainerClient('your-container');
const blockBlobClient = containerClient.getBlockBlobClient('your-file.txt');
await blockBlobClient.uploadData(file.value, file.size);
};
Logic App Alternative:
If you prefer using Logic Apps, create a new Logic App with:
Configure the trigger and action to copy files from SharePoint library to Blob Storage.
Let me know if you need further assistance or clarification!