1

I am using a registered app to create/modify/upload folders and files one one drive business account through Graph API. I have everything set up and working when copying the AuthToken from Graph Explorer directly into my code. When I create the token in my code myself and I run my queries with my generated token I receive a Response Code 404 Not found. I will include my permissions below. Any help would be great, thank you!

const APP_ID ='xxxxxx';
const APP_SECERET = 'xxxxxx'
const TOKEN_ENDPOINT ='https://login.microsoftonline.com/b1a8639c-5c80-4ded-9347-d937b05848cb/oauth2/v2.0/token';
const MS_GRAPH_SCOPE = 'https://graph.microsoft.com/.default';

const postData = {
  client_id: APP_ID,
  scope: MS_GRAPH_SCOPE,
  client_secret: APP_SECERET,
  grant_type: 'client_credentials'
};

axios.defaults.headers.post['Content-Type'] =
  'application/x-www-form-urlencoded';

let token = '';


  function getToken () {
    return new Promise((resolve, reject) => {
      axios
      .post(TOKEN_ENDPOINT, qs.stringify(postData))
      .then(response => {
        var access_token = response.data.access_token; 
        resolve();
        console.log(access_token)
      })
    .catch(error => {
      console.log(error);
    });
    }).catch(err => console.log(err))
  }

  // getToken() 
      oneDriveAPI.items.createFolder({
        accessToken: accessToken,
        rootItemId: "root",
        name: "ssss"
      }).then((item) => {
        console.log(item)[enter image description here][1]
      }).catch( (err) => {
        console.log(err);
      })
Venkata Shivaram
  • 343
  • 4
  • 18
  • (1) Have you validate the tokens (make sure you have necessary scope/permissions) in https://jwt.ms? (2) Share the error info (requestid, timestamp) – Dev Dec 14 '20 at 17:51
  • @Dev, all of the permissions show up under "Roles" in jwt.ms Error: HTTPError: Response code 404 (Not Found) at Request. code: undefined, timings: { start: 1607968397536, socket: 1607968397536, lookup: 1607968397537, connect: 1607968397581, secureConnect: 1607968397672, upload: 1607968397672, response: 1607968398977, end: 1607968398979, error: undefined, abort: undefined, phases: { request: 0, firstByte: 1305, download: 2, total: 1443 } } } – Joel Ferrales Dec 14 '20 at 17:55
  • Validate the token that you got from Graph Explorer and the other one you got it from your application as well. Ok, also i see this that you're using Client Credentials flow. Instead of Graph Explorer i would suggest you to try setting the same flow in POSTMAN utility (not with Graph explorer), test the API call - you will see it will be failing with the same error. – Dev Dec 14 '20 at 18:01
  • @Dev, I did that. The token from graph has all permissions under "scp" and the one from my app has them under "roles" – Joel Ferrales Dec 14 '20 at 18:03
  • Microsoft graph explorer is using auth code flow. You code is using client credential flow. This API supports both flows. So 404 should not be caused by this. 404 should mean the path you want to create folder in doesn't exist. Could you show us what `oneDriveAPI.items` is? – Allen Wu Dec 15 '20 at 02:43
  • Yep i agree with @AllenWu that's the reason i wanted you to try the same with POSTMAN (client credentials). – Dev Dec 15 '20 at 07:16

0 Answers0