Why am i getting error when using an ajax call to retrieve my teams - using graph api

Copper Contributor

I'm trying to get my teams(The teams i have joined) via an ajax call.

Sample below

function getmyTeams() {  
    $.ajax({  
        method: 'GET',  
        //url: "https://graph.microsoft.com/v1.0/users/user@tenant.onmicrosoft.com",  
     url: "https://graph.microsoft.com/v1.0/me/joinedTeams",        headers: {  
            'Authorization': 'Bearer ' + token,  
            'Content-Type': 'application/json'  
        },  
    }).success(function(response) {  
        console.log(response); 

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

This is my request token code which i believe i'm missing something.If i hardcode the token i get from graph explorer it works.Any ideas?

 

function requestToken() { 
$.ajax({ 
"async": true, 
"crossDomain": true, 
"url": "https://cors-anywhere.herokuapp.com/https://login.microsoftonline.com/myteanant.onmicrosoft.com/oauth2/v2.0/token", // Pass your tenant name  
"method": "POST", 
"headers": { 
"content-type": "application/x-www-form-urlencoded" 
}, 
"data": { 
"grant_type": "client_credentials", 
"client_id ": "from azure", //Provide your app id 
"client_secret": "from azure", //Provide your secret 
"scope ": "https://graph.microsoft.com/.default" 
}, 
success: function(response) { 
console.log(response); 
token = response.access_token;
//this works if i hardcode a token from graph. But i guess it could expire and how can i refresh it
//token="Token from Graph"; 
getmyTeams(); 
}, 
error: function(error) { 
console.log(JSON.stringify(error)); 
} 
}) 
}

 

 

But i'm getting error

GET https://graph.microsoft.com/v1.0/me/joinedTeams 404 (Not Found)

I can also confirm i have setup postman and the above api url works fine and it returns the data i need

Also confirming the access token works with no issues as i can retrieve data when i use this api below

https://graph.microsoft.com/v1.0/users/user@tenant.onmicrosoft.com

to get current users details I have also added this api permissions for graph 

 

TeamsPerms.PNG

Update*
I tried postman again but getting the error below

{
  "error": {
    "code""NotFound",
    "message""Failed to execute MsGraph backend request GetUserGroupsS2SRequest. Request Url: https://graph.microsoft.com/edu/users/guid/memberOf/$/microsoft.graph.group?$filter=groupTypes/any(c...",
    "innerError": {
      "request-id""1a3e4b4e-e96e-47ab-9bbc-6a7ea7da8d6a",
      "date""2020-05-19T08:16:58"
    }
  }
}

 

Any ideas what i'm missing? 

Thanks in Advance

5 Replies
Does anyone in here or from MS have any tip or answer for me?
Hi, How did you resolve it? Im stuck with these problem

@arty0m Sorry for the late reply.
I would have to look at it again and will let you know.
It has been a while i had a look at it

@naijacoder can you provide me the update on how did you manage to complete. I am able to get the refresh token from the postman and on basis of that i was able to generate new access token. how would i build the application that uses this