Skip to content

can’t fetch msgraph data using vanilla js

I am trying to pull data from the endpoint I have done this using python but I can’t seem to fetch data from Microsoft Graph using vanilla js.

When I attempt to perform a fetch request. I get a 200 response but nothing is inside the response object.

Here is the fetch code:

fetch("", {
  method: "GET",
  "headers": {
    "authorization": "Bearer ENTERTOKENHERE"}
}).then(data =>{console.log(data)});

I get a response of:

Response {type: 'cors', url: '', redirected: false, status: 200, ok: true, …}

but I am expecting more of a response like the one I get from the website like this:

    "@odata.context": "$metadata#users/$entity",
    "businessPhones": [],
    "displayName": "Edd Bighead",
    "givenName": "Edd",
    "jobTitle": null,
    "mail": "",
    "mobilePhone": null,
    "officeLocation": null,
    "preferredLanguage": "en-US",
    "surname": "Bighead",
    "userPrincipalName": "",
    "id": "2fa321d9-bda3-41c1-8be8-5d4049ed8765"

Is there anything I am missing to get the data from msgraph using vanilla js only?



I figured it out – I needed to jsonize the data then print that data. Can’t believe I missed that. lol

fetch("", {
  method: "GET",
  "headers": {
    "authorization": "Bearer ENTERTOKENHERE"}
}).then(response => response.json())
.then(data => {console.log(data)})
User contributions licensed under: CC BY-SA
4 People found this is helpful