Reputation: 6966
I'm using the Graph API to proactively install a Teams bot for all users in an organization.
I need to retrieve the teamsAppId
by externalId
like so :
GET https://graph.microsoft.com/v1.0/appCatalogs/teamsApps?$filter=externalId eq '{IdFromManifest}'
Is it safe to query the teamsAppId
once and keep it in the appSettings?
Upvotes: 1
Views: 668
Reputation: 1
When a teams app is first published to your organization, e.g. during development or in-house only usage (distributionMethod = "organization" in the catalog from the GET https://graph.microsoft.com/v1.0/appCatalogs/teamsApps
API request), the id
field is generated by the catalog system and the externalId
field is set to the teams app id ({IdFromManifest} in your example, and as seen in dev.teams.microsoft.com > Apps > App Id).
However, when it has been approved and published to the app store, it is a new app entry in the catalog with the id
set to the teams app id ({IdFromManifest}) that was previously the "externalId" of the organization distributed app, and with externalId
set to null.
See suggested documentation change for the api here for clarification: https://github.com/microsoftgraph/microsoft-graph-docs/pull/22146 (approved 2023-07-19)
Note that it is possible that you'll see both apps in the catalog if it was published both to the store and your organization, so querying using the {IdFromManifest} value as either the id or externalId will return both apps, which you'll have to handle.
Assuming for the purpose of development and then production release, I would recommend implementing the $filter so that you check either fields and the use the distributionMethod for selecting.
e.g.
GET https://graph.microsoft.com/v1.0/appCatalogs/teamsApps?$filter=(id eq '{IdFromManifest}' and distributionMethod eq 'store') or (externalId eq '{IdFromManifest}' and distributionMethod eq 'organization')
and using logic to determine the correct app you wish to use depending on the dev environment and the distribution method, or
alternatively you can just query with first id eq '{IdFromManifest}' or externalId eq '{IdFromManifest}'
and select the correct one using the distributionMethod base on your need.
Upvotes: 0
Reputation: 20615
When an app is published to the Microsoft Teams apps catalog an unique id (teamsAppId
) is generated for the app and this id is immutable and can be stored in the appSettings
.
I'm storing teamsAppId
in the local SQLite db and I've never had a problem with id's immutability.
Upvotes: 1