web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id :
Customer experience | Sales, Customer Insights,...
Answered

Access to Sharepoint using Microsoft Graph API from Dynamics CRM Custom Workflow Activity

(2) ShareShare
ReportReport
Posted on by 4
I'm trying to read files from SharePoint folder using the Microsoft Graph API inside Custom Workflow activity Dynamics CRM online, getting below error when trying to get SiteId, Unable to create an instance of type Microsoft.Graph.ItemReference
Code:
public string GetSiteId()
{
    var rootSite = _graphClient.Sites[$"{_rootSiteUrl}"];
    var siteResult = rootSite.Request().GetAsync();
    if (siteResult != null)
        return siteResult.Result.Id;
    return string.Empty;
}
 
Please refer to the attached for error details.
I have the same question (0)
  • Verified answer
    Hamza H Profile Picture
    1,800 on at
    Access to Sharepoint using Microsoft Graph API from Dynamics CRM Custom Workflow Activity
    The error "Unable to create an instance of type Microsoft.Graph.ItemReference" usually happens because the SDK expects a fully qualified identifier or the format is incorrect.
    For getting SiteId from a URL, use this approach instead:
    var site = await _graphClient.Sites
        .GetByPath(_rootSiteUrl, "root")
        .Request()
        .GetAsync();
    
    return site.Id;

    Or if you have the hostname and site path separately:
    var site = await _graphClient.Sites["{hostname}:/sites/{site-path}"]
        .Request()
        .GetAsync();
    return site.Id;



    Make sure _rootSiteUrl only contains the relative path or the hostname correctly.
    Also, ensure async calls are awaited properly, don’t mix .Result with async.
     

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Andrés Arias – Community Spotlight

We are honored to recognize Andrés Arias as our Community Spotlight honoree for…

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
Daniyal Khaleel Profile Picture

Daniyal Khaleel 150

#2
DAnny3211 Profile Picture

DAnny3211 73

#3
Abhilash Warrier Profile Picture

Abhilash Warrier 66 Super User 2025 Season 2

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans