How to Call Sharepoint via MS Graph, inside LispFunction?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hey all,
I am very frustrated & flustered. I do not understand connecting to MS Graph at ALL.
Can someone PLEASE help me get a working example of reaching out to MS Graph via C#?
In my IDEAL scenario, my lisp function is passed a URL string that will call Sharepoint (JUST like the old Sharepoint API), and simply return the body/text returned by the URL call.
So this Parameter passed to the Lisp Function:
http://<site url>/_api/web/lists
Would return something like:
<?xml version="1.0" encoding="utf-8"?>
<feed xml:base="https://...../_api/"
xmlns="http://www.w3.org/2005/Atom"
xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices"
xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata"
xmlns:georss="http://www.georss.org/georss"
xmlns:gml="http://www.opengis.net/gml">
<id>.....</id>
<title />
<updated>2024-09-06T19:34:06Z</updated>
<entry m:etag=""0"">
.....
</entry>
</feed>
Some info:
- I have a .NET Framework (4.7.2) project in Visual Studio
- I have registered an app via our company Azure account, so I have a TenantId and ClientID.
- I do NOT have a secret code generated from Azure, hopefully I do not need it?
- This DLL will ONLY be used within the company and by company employees on our internal computer systems.
- Users ALL have a company Microsoft account and can access the Sharepoint site (our company sharepoint site).
- I only want to perform READs from the Sharepoint site
- Whenever I run my code, I get this error:
could not load file or assembly azure.identity
If you could REALLY dumb your explanation down for me it would be greatly appreciated.
Here's my existing code:
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.Runtime;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Graph;
using Azure.Identity;
namespace HCL
{
public static class LispFunctions
{
[LispFunction("hcl-microsoft-web-get")]
public static async Task<ResultBuffer> MicrosoftWebGet(ResultBuffer rbIn)
{
if (rbIn == null) return ErrorPrompt("\n(hcl-microsoft-web-get url) error: arguments expected");
TypedValue[] args = rbIn.AsArray();
if (args.Length > 1) return ErrorPrompt("\n(hcl-microsoft-web-get url) error: too many arguments");
if (args[0].TypeCode != (int)LispDataType.Text) return ErrorPrompt("\n(hcl-microsoft-web-get url) url error: expected string");
string url = (string)args[0].Value;
var scopes = new[] { "User.Read" };
// Multi-tenant apps can use "common",
// single-tenant apps must use the tenant ID from the Azure portal
var tenantId = "{myTenantId}";
// Value from app registration
var clientId = "{myClientId}";
// using Azure.Identity;
var options = new DeviceCodeCredentialOptions
{
AuthorityHost = AzureAuthorityHosts.AzurePublicCloud,
ClientId = clientId,
TenantId = tenantId,
// Callback function that receives the user prompt
// Prompt contains the generated device code that user must
// enter during the auth process in the browser
DeviceCodeCallback = (code, cancellation) =>
{
Console.WriteLine(code.Message);
return Task.FromResult(0);
},
};
// https://learn.microsoft.com/dotnet/api/azure.identity.devicecodecredential
var deviceCodeCredential = new DeviceCodeCredential(options);
var graphClient = new GraphServiceClient(deviceCodeCredential, scopes);
var result = await graphClient.Sites["{my-company-site}"].Lists.GetAsync();
// return result.??
return null;
}
private static ResultBuffer ErrorPrompt(string message)
{
Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage(message);
return null;
}
}
}
Best,
~DD
Need AutoLisp help? Try my custom GPT 'AutoLISP Ace':
https://chat.openai.com/g/g-Zt0xFNpOH-autolisp-ace