Rohit
Rohit

Reputation: 7161

How to fetch userID, tenantID and serviceURL from MSTeams?

I was looking into Microsoft Graph Postman Collections but could not locate the tenantID, serviceURL or userID?

Is there a way to fetch userID, tenantID and serviceURL from MSTeams?

Upvotes: 0

Views: 672

Answers (2)

Trinetra-MSFT
Trinetra-MSFT

Reputation: 1015

Please take a look at Get context using Microsoft Teams javascript library.

  // Call the initialize API first
  microsoftTeams.initialize();

  // Check the initial theme user chose and respect it
  microsoftTeams.getContext(function (context) {
    if (context) {
      console.log(context);
    }
  });

Upvotes: 1

Hilton Giesenow
Hilton Giesenow

Reputation: 10804

As the other answer mentions, you can get this via the "context" object, which in turn means you need to create a Teams application, and it must include a Tab. There is another similar option, which is to create a Bot for Teams, and when the user installs the bot, either 1-1, or into a channel or group chat, you get the chance to retrieve that information. You can see more about that here, including some options based on the type of bot and when you want to retrieve the information.

If it's ok to have an app, then simply go ahead with this approach. If you really don't -want the user to interact with an app, then you could consider the following:

  1. create the application (e.g. a bot) in order to get the context you need
  2. Auto-install the bot, as per this Graph call
  3. Retrieve and save the information in the conversationUpdate, which is fired when you bot is installed by the user / team / chat
  4. Auto uninstall the app using this Graph call

However, you haven't explained why you need those bits of information. That set is often used to send a proactive message from a bot, and if that's what you're trying to do, you'll need the bot anyway.

Upvotes: 1

Related Questions