Manoj S  Pant

Manoj S Pant

  • 746
  • 1k
  • 1.1m

add "assignedBy" and "createdBy" in PlannerTask

Mar 28 2023 5:22 PM

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.


  1. 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);


Answers (4)