'Graph calls for installing app on Teams returns 409 (Conflict)

My graph calls have suddenly started to return 409 (Conflict) when trying install an app for a Team - any ideas on why?

The app I'm trying to install is the Dynamics 365 app with the teamsAppId: cd2d8695-bdc9-4d8e-9620-cc963ed81f41

The call I use (POST):

https://graph.microsoft.com/v1.0/teams/[my team id]/installedApps

the body:

{
  "teamsApp odata.bind": "https://graph.microsoft.com/v1.0/appCatalogs/teamsApps/cd2d8695-bdc9-4d8e-9620-cc963ed81f41"
} 

The reponse:

{
 "error": {
 "code": "Conflict",
 "message": "AppEntitlement id: 'cd2d8695-bdc9-4d8e-9620-cc963ed81f41' already exists in TeamId:  '19:[email protected]' ",
 "innerError": {
 "message": "AppEntitlement id: 'cd2d8695-bdc9-4d8e-9620-cc963ed81f41' already exists in TeamId:   '19:[email protected]' ",
 "code": "Conflict",
 "innerError": {},
 "date": "2022-03-28T18:13:36",
 "request-id": "424e8c44-ab49-4706-9dc0-1af3ecea6145",
 "client-request-id": "248ad040-ab62-5190-26a8-c2da6127716c"
}
}

Troubleshooting:

To confirm the app is not installed and If I run a call to check if the app is installed using (GET):

https://graph.microsoft.com/v1.0/teams/[my team id]/installedApps?$expand=teamsAppDefinition&$filter=teamsAppDefinition/teamsAppId eq '{cd2d8695-bdc9-4d8e-9620-cc963ed81f41}'

it returns:

{
    "@odata.context": "https://graph.microsoft.com/v1.0/$metadata#teams('a001122-2c62-4006-adaa-6d8112b660f3')/installedApp...())",
    "@odata.count": 0,
    "value": []
}

The same if use (GET):

https://graph.microsoft.com/v1.0/teams/[my team id]/installedApps/cd2d8695-bdc9-4d8e-9620-cc963ed81f41

where I get:

"No app installation found with id 'cd2d8695-bdc9-4d8e-9620-cc963ed81f41' for team '[my team id]'."

Clearly the app is not installed, so any ideas on why this suddenly started to happen as it has worked?

/Adam



Solution 1:[1]

Typo in my call to check if the app is already installed where "{" and "}" around the id shall not be there.

So using the correct call:

https://graph.microsoft.com/v1.0/teams/[my team id]/installedApps?$expand=teamsAppDefinition&$filter=teamsAppDefinition/teamsAppId eq 'cd2d8695-bdc9-4d8e-9620-cc963ed81f41'

Returns if the app is installed or not and I can use the above call prior trying to install the app to ensure it is not installed.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Jeremy Caney