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

Notifications

Announcements

No record found.

Community site session details

Community site session details

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

Error getting token (SharePoint API) from Dynamics 365 app for Outlook

(0) ShareShare
ReportReport
Posted on by 5
Hi,
 
I’m developing a plugin in D365 Customer. It runs when user are creating or updating an email activity.
 
The plugin use the RestClient package making calls to SharePoint Online APIs and receive the Authorization Token.
 
 When I create this email activity from Dynamics 365, everything is fine, I get the token without problems. But using “Dynamics 365 App for Outlook” when I associate an email to a record I get the following error:
pastedimage1601043259415v2.png
C# code:
string GetAuthorisationToken(string sharepointDomain, string tenantId, string clientId, string clientSecret)
{

string access_token = string.Empty;
try
{
var client = new RestClient("">accounts.accesscontrol.windows.net/" + tenantId + "/tokens/OAuth/2");
client.Timeout = -1;
var request = new RestRequest(Method.POST);
request.AddHeader("Content-Type", "application/x-www-form-urlencoded");
//request.AddHeader("Cookie", "esctx=AQABAAAAAAAGV_bv21oQQ4ROqh0_1-tAgDWPPBacsAQbdeyMCb8UnYieeSEIupWmg6N7U4XQ_9vy_dJ-LVypH6IUms1LxtDLoGx5lWs9ZsHaUu9hxDHKNl4JsPdJ-sL31MnE8IAVGn5yhwrmBkZEnusfMItcGwqz3ZjgcPOSA3FunbPi194plFO9JRELr6ZNA_k8FtPUy6kgAA; x-ms-gateway-slice=prod; stsservicecookie=ests; fpc=AgBTR8T7lZlFqOPeTjlbiHbp89TvAQAAAKKF6tYOAAAA");
request.AddParameter("grant_type", "client_credentials");
request.AddParameter("client_id", clientId + "@" + tenantId);
request.AddParameter("client_secret", clientSecret);
request.AddParameter("resource", "00000003-0000-0ff1-ce00-000000000000" + "/" + sharepointDomain + "@" + tenantId);
IRestResponse response = client.Execute(request);
Console.WriteLine(response.Content);

if (response.IsSuccessful)
{
dynamic Data = JsonConvert.DeserializeObject(response.Content);
Console.WriteLine(Data.access_token);
access_token = (String)Data.access_token;

}
if (access_token.Length <= 0)
{
throw new InvalidPluginExecutionException("Ocurrió un error en módulo Metadatos > GetAuthorisationToken nulo");
}
return access_token;
}
catch (FaultException<OrganizationServiceFault> ex)
{
throw new InvalidPluginExecutionException("Ocurrió un error en módulo Metadatos > GetAuthorisationToken.", ex);
}//Fin Catch
}
 
I have tried to make some changes from D365 in the email record that has been created with the “Dynamics 365 App for Outlook” and I allways receive the same error.
 
Is it possible that when I associate an email to a record, it’s created in a different way? Could it be a "Special" record?
 
Thanks.
I have the same question (0)

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…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
Tom_Gioielli Profile Picture

Tom_Gioielli 146 Super User 2025 Season 2

#2
#ManoVerse Profile Picture

#ManoVerse 59

#3
Gerardo Rentería García Profile Picture

Gerardo Rentería Ga... 52 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans