We are using application permission, and need to create a planner task.
All things are working fine, but we need to add "assignedBy" and "CreatedBy" users (We have the object Id's of users).
By default when we are creating a Planner task with ClientSecretCredential[appication permission], it passes application id(Client Id of Azure AD registered application ) "assignedBy" and "CreatedBy", but we need to pass the user object Id also, So then in planner,
It shows "assigned to" and "assigned by" user also.
Note:
- Application permission and Microsoft.Graph V5.3.0
Below is the code which we are using:
string tenentId = "xxxxxxxx";
string clientId = "xxxxxxx";
string clientScret = "xxxxxxxxx";
// Application permission
ClientSecretCredential clientSecretCredential = new ClientSecretCredential(tenentId, clientId, clientScret);
GraphServiceClient gsClient = new GraphServiceClient(clientSecretCredential);
var plannerAssignments = new PlannerAssignments();
// Add assign to
var plannerAssignment = new PlannerAssignment();
plannerAssignment.OrderHint = " !";
plannerAssignment.OdataType = "#microsoft.graph.plannerAssignment";
plannerAssignments.AdditionalData.Add("af0c0624-3138-446d-9d9e-f86159890745", plannerAssignment);
var requestBody = new PlannerTask
{
PlanId = "wOJWGexB0U-a3n-LZ9nX_2UAD-xT",
BucketId = "RWBdSfn0h0OsFR9XBksEKmUAIgaG",
Title = "Update client list 100",
Assignments = plannerAssignments,
CreatedBy = new IdentitySet() { User = new Identity() { DisplayName= "Adele Vance", Id = "ba8ebefe-fdb9-4ef6-b6c0-80c745d12a0e", OdataType = "#microsoft.graph.identitySet" } }
};
var plannerTaskRes = await gsClient.Planner.Tasks.PostAsync(requestBody);
Rajkiran SwainPosted Mar 29, 2023, 8:28 PM
To add "assignedBy" and "createdBy" users when creating a Planner task using application permissions, you need to modify the request payload and include the object Id of the users. Here's an example of how you can modify the payload:
In the payload, replace
,,, andwith the appropriate values. TheassignedToandassignedByproperties use theplannerAssignmenttype, which includes anassignedUserIdproperty to specify the user's object Id. ThecreatedByproperty uses theidentitySettype, which includes both the application and user identities.Make sure to include the appropriate permissions in your Azure AD application registration for creating Planner tasks with user and application identities.
Manoj S PantPosted Mar 29, 2023, 6:45 AM
Hello @Tuhin Paul,
Thanks for the reply.
1. Over my side inside the PlannerTask object, not able to get the property "CreatedById " and "AssignedById ".
2. I have the CreatedBy property in the Task planner, but I think it is over application permission, so it is not taking the user details which we are passing in the createdBy property.
CreatedBy = new IdentitySet() { User = new Identity() { DisplayName= "Adele Vance", Id = "ba8ebefe-fdb9-4ef6-b6c0-80c745d12a0e", OdataType = "#microsoft.graph.identitySet" } }
Tuhin PaulPosted Mar 28, 2023, 8:05 PM
The CreatedById and AssignedById properties are set to the user object ID "ba8ebefe-fdb9-4ef6-b6c0-80c745d12a0e". You can replace these values with the actual user object IDs you want to use.
Tuhin PaulPosted Mar 28, 2023, 8:04 PM
You can use the Microsoft.Graph.Core library and set the CreatedById and AssignedById properties on the PlannerTask object.