0

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  
});

</script>

<script>
    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

1 Answer 1

0

Can you try to call https://graph.microsoft.com/v1.0/teams/{teamid}/ after you get the id. I had the same issue. For wherever reason the weburl wasn't returned in the https://graph.microsoft.com/v1.0/users/" + userid + "/joinedTeams call

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.