Forum Discussion
naijacoder
May 19, 2020Copper Contributor
Why am i getting error when using an ajax call to retrieve my teams - using graph api
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
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:c+eq+'Unified')&$top=999, Request Method: GET, Response Status Code: NotFound, Response Headers: request-id: 4bc6af89-09f2-42da-a7f6-9589cd712a2e\r\nclient-request-id: 4bc6af89-09f2-42da-a7f6-9589cd712a2e\r\nStrict-Transport-Security: max-age=31536000\r\nDate: Tue, 19 May 2020 08:16:58 GMT\r\n, Reason Phrase: Not Found",
"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
Sort By
- naijacoderCopper ContributorGot it working
- arty0mCopper ContributorHi, How did you resolve it? Im stuck with these problem
- naijacoderCopper Contributor
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
- naijacoderCopper ContributorDoes anyone in here or from MS have any tip or answer for me?