How to get the link to team via graph api

Copper Contributor

I have the script below and i can get myteams (graph api /joinedTeams).
But i also want the url link to the individual teams.

This is for a webpart on a classic sharepoint page. It shows as null when i retrieve the response. The property webUrl is null. Any ideas how to get this url via the teams api?
See code below

 

$(document).ready(function() {  
    requestToken(); // call the requesttoken function on page load  
});

function requestToken() {
        $.ajax({
            "async": true,
            "crossDomain": true,
            "url": "https://cors-anywhere.herokuapp.com/https://login.microsoftonline.com/xxx/oauth2/v2.0/token", // Pass your tenant name instead of sharepointtechie  
            "method": "POST",
            "headers": {
                "content-type": "application/x-www-form-urlencoded"
            },
            "data": {
                "grant_type": "client_credentials",
                //Provide your app id  
                //Provide your secret  
                "scope ": "https://graph.microsoft.com/.default"
            },
            success: function (response) {
                //console.log(response);
                token = response.access_token;
                var email = _spPageContextInfo.userEmail;

                //get userid to filter teams
                getUserId(email);

            },
            error: function (error) {
                console.log(JSON.stringify(error));
            }
        })
    }

    function getTeams(userid) {
    var teamsId;
        $.ajax({
            method: 'GET',
            url: "https://graph.microsoft.com/v1.0/users/" + userid + "/joinedTeams",
            headers: {
                'Authorization': 'Bearer ' + token,
                'Content-Type': 'application/json'
            },

        }).success(function (response) {
            //console.log(response);
            var data = response.value;

            data.map(function (myTeams) {
                var Name = myTeams.displayName;
                teamsId = myTeams.id;
                //can list the teams here
                $('#myTeams').append("<div id=" + teamsId + "><a href=''>" + Name + "</a></div>");

            })

        }).error(function (error) { });

    }

function getUserId(email) {
        $.ajax({
            method: 'GET',
            url: "https://graph.microsoft.com/v1.0/users/" + email,
            headers: {
                'Authorization': 'Bearer ' + token,
                'Content-Type': 'application/json'
            },

        }).success(function (data) {
            //console.log("UserId " + data.id);
            var userid = data.id;
            getTeams(userid);

        }).error(function (error) { });
    }  

Thanks in Advance

0 Replies