CopyPastor

Detecting plagiarism made easy.

Score: 1; Reported for: Exact paragraph match Open both answers

Possible Plagiarism

Reposted on 2024-03-25
by Sridevi

Original Post

Original - Posted on 2024-03-22
by Sridevi



            
Present in both answers; Present only in the new answer; Present only in the old answer;

I registered one Azure AD application and granted API permissions of **Application** type like this:
![enter image description here](https://i.imgur.com/K4Aj4jD.png)
Initially, I too got **same error** when I ran your code with `/beta` in container URL like this: ```csharp private async Task<PlannerPlan?> CreatePlan(Guid id, string planName) { var requestBody = new PlannerPlan { Container = new PlannerPlanContainer { Url = $"https://graph.microsoft.com/beta/groups/{id}" }, Title = planName };
var graphClient = GetGraphClient(); try { return await graphClient.Planner.Plans.PostAsync(requestBody); } catch (Microsoft.Graph.Models.ODataErrors.ODataError oDataError) { var error = oDataError.Error;
throw; } } ```
**Response:**
![enter image description here](https://i.imgur.com/L8biMqK.png)
To resolve the error, make use of v1.0 endpoint by modifying your code like this:
```c# using Azure.Identity; using Microsoft.Graph; using Microsoft.Graph.Models; using System;
class Program { static async Task Main(string[] args) { var scopes = new[] { "https://graph.microsoft.com/.default" }; var tenantId = "tenantId"; var clientId = "appId"; var clientSecret = "secret";
var options = new TokenCredentialOptions { AuthorityHost = AzureAuthorityHosts.AzurePublicCloud, };
var clientSecretCredential = new ClientSecretCredential(tenantId, clientId, clientSecret, options);
var graphClient = new GraphServiceClient(clientSecretCredential, scopes);
try { var groupId = "groupId"; // Group ID where you want to create the plan
var createdPlan = await CreatePlan(new Guid(groupId), "Demo Plan1", graphClient);
Console.WriteLine($"Plan Title: {createdPlan.Title}"); Console.WriteLine($"Plan ID: {createdPlan.Id}"); } catch (Microsoft.Graph.Models.ODataErrors.ODataError oDataError) { var error = oDataError.Error;
Console.WriteLine(error.Code); Console.WriteLine(error); } }
private static async Task<PlannerPlan?> CreatePlan(Guid id, string planName, GraphServiceClient graphClient) { var requestBody = new PlannerPlan { Container = new PlannerPlanContainer { Url = $"https://graph.microsoft.com/v1.0/groups/{id}" }, Title = planName };
try { return await graphClient.Planner.Plans.PostAsync(requestBody); } catch (Microsoft.Graph.Models.ODataErrors.ODataError oDataError) { var error = oDataError.Error;
throw; // Rethrow the exception to propagate it } } } ``` **Response:**
![enter image description here](https://i.imgur.com/z64t3xn.png)
**Reference:** [plannerPlanContainer resource type - Microsoft Graph v1.0 ](https://learn.microsoft.com/en-us/graph/api/resources/plannerplancontainer?view=graph-rest-1.0)
The error occurred as you missed granting `Tasks.Read.All` permission that is required to list plans within group while using client credentials flow.
I registered one Entra ID application granted same **API permissions** as you:
![enter image description here](https://i.imgur.com/EdzDN3c.png)
When I tried to list plans within the group, I got **same error** like this:
![enter image description here](https://i.imgur.com/zTT0CSZ.png)
To resolve the error, make sure to grant `Tasks.Read.All` permission of **Application** type by granting **admin consent** to it as below:
![enter image description here](https://i.imgur.com/amEAKlM.png)
When I ran below code after granting required permission, I got the **response** with list of plans successfully:
```c# using Azure.Identity; using Microsoft.Graph;
class Program { static async Task Main(string[] args) { var scopes = new[] { "https://graph.microsoft.com/.default" }; var tenantId = "tenantId"; var clientId = "appId"; var clientSecret = "secret";
var options = new TokenCredentialOptions { AuthorityHost = AzureAuthorityHosts.AzurePublicCloud, };
var clientSecretCredential = new ClientSecretCredential(tenantId, clientId, clientSecret, options);
var graphClient = new GraphServiceClient(clientSecretCredential, scopes);
try { var plans = await graphClient.Groups["groupId"].Planner.Plans.GetAsync();
foreach (var plan in plans.Value) { Console.WriteLine($"Plan Title: {plan.Title}"); Console.WriteLine($"Plan ID: {plan.Id}"); } } catch (Exception exception) { Console.WriteLine($"{exception.GetType().FullName}: {exception.Message}"); } } } ```
**Response:**
![enter image description here](https://i.imgur.com/Hc2igBC.png)
**Reference:** [List plans - Microsoft Graph v1.0](https://learn.microsoft.com/en-us/graph/api/plannergroup-list-plans?view=graph-rest-1.0&tabs=http#permissions)

        
Present in both answers; Present only in the new answer; Present only in the old answer;