Calling MS Graph API from MS Access

-- -- 922 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 Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
11,843 questions
Access Development
Access Development
Access: A family of Microsoft relational database management systems designed for ease of use.Development: The process of researching, productizing, and refining new or existing technologies.
873 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. CarlZhao-MSFT 41,286 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 Answers by the question author, which helps users to know the answer solved the author's problem.