garyprinting.com

Extracting Microsoft Teams Attendance Data with Graph API

Written on

Chapter 1: Introduction to Microsoft Teams Attendance Tracking

Are you aware that Microsoft Teams keeps track of attendance after a meeting? If you facilitate meetings through this platform, you can monitor who attended, when they joined or left, and even the duration of their participation. This capability extends to both internal team members and external guests.

What exactly is Graph API? Simply put, it’s an API that organizes data as nodes and edges, enabling users to interact with multiple nodes in a single operation. The Microsoft Graph API for Teams offers an endpoint to retrieve Teams-related data for applications.

Before you can access this data, you need to register your application and acquire authentication tokens for either a user or a service. Here’s how to get started.

Section 1.1: Steps to Register Your Application

Step 1: Create an App in Azure Portal

  1. Navigate to Active Directory and select App registrations.
  2. Choose the necessary permissions under the application tab.
  3. Establish a Redirect URI for your application.
  4. Copy the Client ID, Redirect URI, and Tenant ID into your code or create a .yml file for storage.

Step 2: Authentication

Next, you will need to secure the authorization code, Access Token, and Refresh Token. First, you will create a sign-in through code that allows you to remotely access your work account. This process will generate an authorization code. Use the following code to initiate the authorization code generation:

import json

import requests

import pandas as pd

import yaml

from requests_oauthlib import OAuth2Session

import os

import time

# Load the OAuth settings

with open('oauth_settings.yml', 'r') as stream:

settings = yaml.safe_load(stream)

authorize_url = '{0}{1}'.format(settings['authority'], settings['authorize_endpoint'])

# Function to generate a sign-in URL

def get_sign_in_url():

aad_auth = OAuth2Session(settings['app_id'],

scope=settings['scopes'],

redirect_uri=settings['redirect'])

sign_in_url, state = aad_auth.authorization_url(authorize_url, prompt='login')

return sign_in_url, state

Step 3: Use the Authorization Code

Use the authorization code obtained from the sign-in process to generate Refresh and Access Tokens from the API. Here’s how:

def graphAccessToken():

response = requests.post(url,

headers={'Content-Type': 'application/x-www-form-urlencoded'},

data={

'client_id': "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",

'scope': 'openid profile offline_access user.read calendars.read Files.Read.All Files.ReadWrite.All Sites.Manage.All Sites.Read.All Sites.ReadWrite.All Directory.Read.All OnlineMeetings.Read ChannelMessage.Read.All Group.Read.All',

'code': 'xxxxxxxxxxxxxxxxxxxxxxxx',

'grant_type': 'authorization_code'

})

response_data = json.loads(response.text)

return response_data

Step 4: Refresh Access Token

Now that you have both the Access and Refresh Tokens, you can refresh the Access Token as follows:

def newAccessToken():

response = requests.post(url,

headers={'Content-Type': 'application/x-www-form-urlencoded'},

data={

'client_id': "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",

'scope': 'openid profile offline_access user.read calendars.read Files.Read.All Files.ReadWrite.All Sites.Manage.All Sites.Read.All Sites.ReadWrite.All Directory.Read.All OnlineMeetings.Read ChannelMessage.Read.All Group.Read.All',

'refresh_token': 'xxxxxxxxxxxxxxxxxxxxxxxxxxxx',

'grant_type': 'refresh_token'

})

json_response = response.json()

return json_response['access_token']

Section 1.2: Accessing SharePoint Data

To fetch sample data from SharePoint, use the following code snippet:

def spoint():

headers={'Authorization': 'Bearer ' + newAccessToken(),

'Content-Type': 'application/x-www-form-urlencoded'})

return response.text

You can also retrieve items from a SharePoint site using the site ID and folder names:

def datapoint():

headers={'Authorization': 'Bearer ' + newAccessToken()})

return response.json()

To obtain the attendance report, use the GET method with the following endpoint:

This request is only available in the beta version of the Microsoft Graph API. By following these steps, you will successfully extract attendance data from Microsoft Teams using the Graph API.

Chapter 2: Learning Resources

In this episode, we explore how to read Microsoft Teams reports utilizing the Microsoft Graph, offering valuable insights for data extraction.

This video discusses how to call the Graph Reports API using Power Automate, enhancing your skills in automating data retrieval processes.

Share the page:

Twitter Facebook Reddit LinkIn

-----------------------

Recent Post:

# Innovative Strategies for Everyday Challenges: Mastering Your Mindset

Discover how to effectively harness dopamine and overcome distractions for improved creativity and productivity.

Embracing Neurodiversity: Why Some Feel Envy Towards Neurodivergent Individuals

This article delves into the unique strengths of neurodivergent individuals and explores the jealousy some neurotypical individuals may feel towards them.

Mastering Gestures with Framer Motion in React Applications

Explore how to implement gesture handling with Framer Motion in your React applications for enhanced interactivity.

Harnessing the Power of ‘Fake It Till You Make It’ for Growth

Explore how embracing the concept of ‘fake it till you make it’ can lead to personal transformation and self-improvement.

Essential Considerations for Startup Fundraising: A Guide

Discover key aspects to prepare for pitching to investors, ensuring your startup is investor-ready and appealing for funding.

Public Toilets in Ancient Rome: A Curious Paradox

Explore the fascinating yet alarming realities of public toilets in Ancient Rome, revealing their engineering marvels and hygienic shortcomings.

Understanding Polymorphism in Python: A Comprehensive Overview

An insightful exploration of polymorphism in Python, covering its principles, method overriding, and abstract base classes.

Strengthening Your Communication Skills: 7 Essential Tips

Enhance your communication abilities with these seven effective strategies.