-1

I'm using Graph API SDK in a C# Console Application and I'd like to list all the shift data from Microsoft Teams. But I'm unable to retrieve such information. Here is what I have done so far.

According to the documentation to list all shift, you have to provide the team ID in order to retrieve the shift, however, in my case, I have to retrieve all the shift from all the teams. So, I have to retrieve the list of the team first. The documentation says that to retrieve all team you have to retrieve the list of groups first. I've followed the same approach and the following is the code that I've used.

var groups = await graphClient
  .Groups.Request()
  .Filter("resourceProvisioningOptions/Any(x:x eq 'Team')")
  .GetAsync();

foreach (var group in groups)
{
    Console.WriteLine(group.DisplayName);
    var shifts = await graphClient
       .Teams[group.Id]
       .Schedule
       .Shifts
       .Request()
       .GetAsync();  
}

I'm able to retrieve the Group list, however, I'm not able to retrieve the Shift list. When it tries to retrieve the Shift list the following error occurs:

Code: NotFound
Message: {
  "error":{
    "code":"NotFound",
    "message":"Sorry, the team was not found, or you may not have access to it.",
    "details":[],
    "innererror":{"code":"TeamNotFound"}
  }
}

Inner error:
    AdditionalData:
      request-id: c5ab5f5c-ec3d-463b-9b1f-0798734e94ce
      date: 11/11/2019 7:50:42 AM
      ClientRequestId: c5ab5f5c-ec3d-463b-9b1f-0798734e94ce

Would appreciate any help that can help me to list all the shift list from Microsoft Teams. Thank you.

Marc LaFleur
  • 31,987
  • 4
  • 37
  • 63
Ali Asad
  • 1,235
  • 1
  • 18
  • 33
  • 1
    In the Permissions section you have a list of required permissions to be able to retrieve shifts Delegated (work or school account) Group.Read.All, Group.ReadWrite.All Your account has this permissions? – Mrg Gek Nov 11 '19 at 09:43
  • Thanks for your reply, yes I do have Group.ReadAll and Group.ReadWrite.All permission active. still facing with the same issue – Ali Asad Nov 11 '19 at 10:07

1 Answers1

1

This error most likely occurs since schedule object is not provisioned. The point is List shifts endpoint expects schedule object to be provisioned. From Get schedule documentation:

During schedule provisioning, clients can use the GET method to get the schedule and look at the provisionStatus property for the current state of the provisioning. If the provisioning failed, clients can get additional information from the provisionStatusCode property.

In msgraph-sdk-dotnet whether schedule provisioned could be determined like this:

var schedule = await graphClient.Teams[group.Id].Schedule.Request().GetAsync();
if (schedule.ProvisionStatus == OperationStatus.Completed)
{  
    //...
}

Here is an updated example (which demonstrates how to retrieve shifts for provisioned schedule):

var groups = await graphClient.Groups.Request()
            .Filter("resourceProvisioningOptions/Any(x:x eq 'Team')")
            .GetAsync();
foreach (var group in groups)
{
     var schedule = await graphClient.Teams[group.Id].Schedule.Request().GetAsync();
     if (schedule.ProvisionStatus == OperationStatus.Completed)
     {
          var shifts = await graphClient.Teams[group.Id].Schedule.Shifts.Request().GetAsync();
         //...
     }         
}
Vadim Gremyachev
  • 57,952
  • 20
  • 129
  • 193