You need to sign in to do that
Don't have an account?
Test Dev 81
issue Sharepoint integration using Apex
hi everyone,
I am trying to integrate SharePoint using apex
I generate an access token from the postman and copy the access token and then pass it to my apex method it works but when I generate into apex class and pass to method it is not working
above code returns an error response in getChildren(accesstoken)
"message": "Unable to retrieve user's mysite URL.",
but in the same method getChildren('accesstoken_generated from Postman') here I pass postman generated access token it works fine
don't know what I am missing in my apex request for an access tokenThanks,
Rahul
I am trying to integrate SharePoint using apex
I generate an access token from the postman and copy the access token and then pass it to my apex method it works but when I generate into apex class and pass to method it is not working
public class Rg_SharepointIntegration { public static void getconnection(){ String clientId = '*****************'; String clientSecret = 's**************'; String tenantId = 'c*****************72'; Http h = new Http(); HttpRequest req = new HttpRequest(); req.setMethod('POST'); req.setHeader('Content-Type', 'application/x-www-form-urlencoded'); //https://login.microsoftonline.com/< tenant Id>/oauth2/token req.setEndpoint('https://login.microsoftonline.com/'+EncodingUtil.urlEncode(tenantId, 'UTF-8').replaceAll('\\+', '%20')+'/oauth2/token'); String body = 'grant_type=client_credentials'+ '&scope=files.readwrite.all'+ '&client_id=' + EncodingUtil.urlEncode(clientId, 'UTF-8') + '&client_secret='+ EncodingUtil.urlEncode(clientSecret, 'UTF-8') + '&resource=https://graph.microsoft.com'; req.setBody(body); HttpResponse res = h.send(req); Map<String,String>connectionMap = new Map<String,String>(); String accessTockn; if(res.getStatusCode() == 200){ System.debug('Response Body: ' + res.getBody()); connectionMap = (Map<String, String>) Json.deserialize(res.getBody(),Map<String, String>.class); System.debug('connectionMap '+connectionMap); if(connectionMap.containsKey('access_token') && connectionMap.get('access_token') != null){ accessTockn =connectionMap.get('access_token'); getChildren(accessTockn); } } } public static void getChildren(String access_token){ //String access_token= 'access_token'; Http h = new Http(); HttpRequest req = new HttpRequest(); req.setMethod('GET'); req.setHeader('Authorization', 'Bearer '+ access_token); req.setHeader('Content-Type', 'application/json'); req.setHeader('Accept', 'application/json'); //req.setEndpoint('https://graph.microsoft.com/v1.0/drives/'); req.setEndpoint('https://graph.microsoft.com/v1.0/me/drive/root/children'); HttpResponse res = h.send(req); System.debug('Response Body: ' + res.getBody()); //Get your drive id from the response and store it somewhere. } }
above code returns an error response in getChildren(accesstoken)
"message": "Unable to retrieve user's mysite URL.",
but in the same method getChildren('accesstoken_generated from Postman') here I pass postman generated access token it works fine
don't know what I am missing in my apex request for an access tokenThanks,
Rahul