cli-microsoft365: Bug UnhandledPromiseRejectionWarning - 404 when creating a team using teams team add

Description

When executing the m365 teams team add --name ‘Architecutre’ --description ‘Architecture’ command you might receive 404 error message like this one:

UnhandledPromiseRejectionWarning: StatusCodeError: 404 - {"error":{"code":"NotFound","message":"No team found with Group Id 58c19f12-6bb5-4846-8ccd-36d9eb04ef2a","i nnerError":{"date":"2020-10-25T08:59:38","request-id":"083e431a-deb6-4f85-987e-a59487c18cea","client-request-id":"083e431a-deb6-4f85-987e-a59487c18cea"}}}

The Team is being created but the operation to retrieve group information fails because graph still does not have the group available when querying it.

The suggestion is to put a try catch with retries (for example up to 5 with a sleep time of 5 seconds) until the result is correctly returned.

Steps to reproduce

  • execute the command m365 teams team add --name ‘Architecutre’ --description ‘Architecture’
  • It will throw an exception
  • The team is created but the command fails due to the lines trying to return the group object

Expected result

  • Command does not return an exception

Environment

  • Windows 10
  • PowerShell
  • Latest Microsoft 365 CLI

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 24 (24 by maintainers)

Most upvoted comments

All right, so the consensus is to add a loop that will keep waiting until the group has been created, correct?

Apologies @plamber looks like I didn’t quite understand the issue you reported here.

You are referring to the request made below to the group endpoint after the teamsAsyncOperation status has returned as Succeeded.

https://github.com/pnp/cli-microsoft365/blob/630901e5efa0cf413b5a0d22803d70db107887ca/src/m365/teams/commands/team/team-add.ts#L140-L147

As we are currently using the beta/teams endpoint for creating the Team, I think we should look to update this command to use the v1.0 endpoint now it is in GA, maybe that will provide more reliability, if not we can look to add some defensive code to cover a potential timing issue in the Graph.

@garrytrinder we are using 1.0 for team creation, couple of months ago we used beta as 1.0 was not available. Works better than beta, especially when after creation we want to add tabs/apps or call sitedesign for sharepoint. In many cases we get 404 error.

@waldekmastykarz @plamber

As there are two changes to be made here, I think we should we create two new issues to carry out the work.

One to update to the v1.0 endpoint and another to include the loop as an enhancement as we have discussed here, this makes our intentions clearer.

Do you agree?

Issues #2020 & #2021 raised as discussed.

Thank you for your input all, lets move this forward 👍

Let me check if I can dig up any more information on it

@waldekmastykarz, @garrytrinder I found this working better:

  1. create/clone team. It does return location in header
  2. call graph with https://graph.microsoft.com/v1.0/{Location} which returns operation status. When doing it in the loop in flow very quickly I can see return status of creation operation changing from in Progress to succeed. An only when I get “Succeed” i am doing something with team. nice thing that when checking via https://graph.microsoft.com/v1.0/{Location} you also getting team id, can be found either in {Location} value or use response ResourceId which is also team id.

@waldekmastykarz would be nice to have some insight from MS about endpoints and async creation mainly on how or most importantly when sharepoint sites are created. I have a number of examples of sites not get created sometimes unless “files” tab clicked in teams. So I assume clicking it does call some endpoint. would be great to know which one and if I can use it for provisioning solutions.

@garrytrinder: step 1 is definitively the update. The v1.0 endpoints are much faster. Nevertheless, we need a fallback on that specific command because from experience these operations are not synchronous in nature

Something similar happens if you create a group and you try to immediately create a team afterwards. In many cases it works immediately but in some you have to perform some retries up to 15 seconds in average.

Apologies @plamber looks like I didn’t quite understand the issue you reported here.

You are referring to the request made below to the group endpoint after the teamsAsyncOperation status has returned as Succeeded.

https://github.com/pnp/cli-microsoft365/blob/630901e5efa0cf413b5a0d22803d70db107887ca/src/m365/teams/commands/team/team-add.ts#L140-L147

As we are currently using the beta/teams endpoint for creating the Team, I think we should look to update this command to use the v1.0 endpoint now it is in GA, maybe that will provide more reliability, if not we can look to add some defensive code to cover a potential timing issue in the Graph.

You are correct @waldekmastykarz, the beta endpoint returns a team creation object and a reference to another endpoint so you can check the status of your request.

The current v1.0 endpoint returns a 404 if the underlying group is not provisioned immediately as @plamber points out.

I believe the guidance from the Graph team is that this can take up to 15 mins for the Group to be provisioned however.

I believe I’ve heard something about a new API that should allow for synchronous Teams creation. Let’s check if we’re using that API already and if not, see if we could switch to it for more reliable teams creation.