Calling MS Graph API from MS Access

-- -- 957 Reputation points
2022-09-19T03:49:55.727+00:00

Hi

How can I call MS Graph api such as given below from within MS Access?

await graphClient.Me.Drive.Items["{driveItem-id}"].Content  
	.Request()  
	.PutAsync<DriveItem>(stream);  

Thanks

Regards

Microsoft 365 and Office | Access | Development
Microsoft Security | Microsoft Graph
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. CarlZhao-MSFT 46,406 Reputation points
    2022-09-19T09:58:54.813+00:00

    Hi @-- --

    Try my code, I have tested it locally and it works fine.

    using Azure.Identity;  
    using Microsoft.Graph;  
    using System.Text;  
      
    var scopes = new[] { "https://graph.microsoft.com/.default" };  
      
    var tenantId = "tenant id";  
      
    // Values from app registration  
    var clientId = "client id";  
    var clientSecret = "client secret";  
      
    // using Azure.Identity;  
    var options = new TokenCredentialOptions  
    {  
        AuthorityHost = AzureAuthorityHosts.AzurePublicCloud  
    };  
      
    // https://learn.microsoft.com/dotnet/api/azure.identity.clientsecretcredential  
    var clientSecretCredential = new ClientSecretCredential(  
        tenantId, clientId, clientSecret, options);  
      
    var graphClient = new GraphServiceClient(clientSecretCredential, scopes);  
      
    using var stream = new System.IO.MemoryStream(Encoding.UTF8.GetBytes(@"The contents of the file goes here."));  
      
    await graphClient.Users["user id"].Drive.Items["item id"].Content  
        .Request()  
        .PutAsync<DriveItem>(stream);  
    

    242521-image.png


    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.


Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.