Forum Discussion

whisperwind325's avatar
whisperwind325
Copper Contributor
Apr 02, 2025

Microsoft Graph API returns 404 when querying SharePoint file by siteId, listId, uniqueId

I'm retrieving the JSON representation of a SharePoint page using the endpoint:

    GET https://graph.microsoft.com/v1.0/sites/${siteId}/pages/${pageId}/microsoft.graph.sitePage?expand=canvasLayout&select=id,name,webUrl,title,description,createdBy,canvasLayout,parentReference
 I receive a JSON structure like this.

 {
  "@odata.type": "#microsoft.graph.standardWebPart",
  "id": "e90803f3-30a5-4ef5-8c7e-1056966a2930",
  "webPartType": "b4cc345e-35ed-4b30-bc91-a7d6d249494f",
  "data": {
    "dataVersion": "1.3",
    "description": "This is an example description.",
    "title": "Stream",
    "properties": {
      "label": "This is an example property",
      "isTitleEnabled": true,
      "templateId": 1,
      "maxItemsPerPage": 3,
      "maxRowsPerPageGrid": 5,
      "maxRowsPerPageTheater": 1,
      "hideWebPartWhenEmpty": true,
      "sourceType": "VIDEO",
      "listSortField": "Created",
      "playlistSortField": "Default",
      "isPlaceholderState": false,
      "dataProviderId": "StreamVideo",
      "layoutId": "Theater",
      "webId": "cf329d30-484e-4b9f-9378-533152cfcd3f",
      "siteId": "6688e890-8000-4a19-9839-905b54adb407",
      "spWebUrl": "https://example.sharepoint.com/sites/ExampleSite",
      "previewUrl": "https://example.sharepoint.com/_api/v2.1/sites/example.sharepoint.com,6688e890-8000-4a19-9839-905b54adb407,cf329d30-484e-4b9f-9378-533152cfcd3f/lists/9b049de0-9a77-4169-bd45-6dc32cf99264/items/e2ae18de-a4f2-412d-a5c8-b8e340ef9e90/driveItem/thumbnails/0/c400x99999/content?prefer=noRedirect,extendCacheMaxAge&clientType=modernWebPart",
      "videoDuration": 145100000,
      "listId": "9b049de0-9a77-4169-bd45-6dc32cf99264",
      "rootFolder": "/sites/ExampleSite/Shared Documents/ExampleFolder/movie.mp4",
      "uniqueId": "e2ae18de-a4f2-412d-a5c8-b8e340ef9e90",
      "listTitle": "Title Example",
      "serverRelativePath": "/sites/ExampleSite/Shared Documents/ExampleFolder/movie.mp4",
      "link": "https://example.sharepoint.com/sites/ExampleSite/Shared Documents/ExampleFolder/movie.mp4",
      "wopiurl": "/sites/ExampleSite/Shared Documents/ExampleFolder/movie.mp4",
      "serverRelativeUrl": "/sites/ExampleSite/Shared Documents/ExampleFolder/movie.mp4",
      "webAbsoluteUrl": "https://example.sharepoint.com/sites/ExampleSite",
      "file": "https://example.sharepoint.com/sites/ExampleSite/Shared Documents/ExampleFolder/movie.mp4",
      "query": {
        "@odata.type": "#graph.Json",
        "contentLocation": 1,
        "email address removed for privacy reasons": "#Collection(Int32)",
        "contentTypes": [
          3
        ],
        "email address removed for privacy reasons": "#Collection(Int32)",
        "documentTypes": [
          11
        ],
        "sortType": 6
      },
      "displayMaps": {
        "1": {
          "@odata.type": "#graph.Json",
          "cardType": {
            "@odata.type": "#graph.Json",
            "email address removed for privacy reasons": "#Collection(String)",
            "sources": [
              "CardType"
            ]
          },
          "telemetryProperties": {
            "@odata.type": "#graph.Json",
            "email address removed for privacy reasons": "#Collection(String)",
            "sources": [
              "TelemetryProperties"
            ]
          },
          "accentColor": {
            "@odata.type": "#graph.Json",
            "email address removed for privacy reasons": "#Collection(String)",
            "sources": [
              "AccentColor"
            ]
          },
          "initials": {
            "@odata.type": "#graph.Json",
            "email address removed for privacy reasons": "#Collection(String)",
            "sources": [
              "Initials"
            ]
          },
          "previewUrl": {
            "@odata.type": "#graph.Json",
            "email address removed for privacy reasons": "#Collection(String)",
            "sources": [
              "PreviewUrl",
              "PictureThumbnailURL"
            ]
          },
          "headingText": {
            "@odata.type": "#graph.Json",
            "email address removed for privacy reasons": "#Collection(String)",
            "sources": [
              "SiteTitle"
            ]
          },
          "itemUrl": {
            "@odata.type": "#graph.Json",
            "email address removed for privacy reasons": "#Collection(String)",
            "sources": [
              "WebPath"
            ]
          },
          "listItemId": {
            "@odata.type": "#graph.Json",
            "email address removed for privacy reasons": "#Collection(String)",
            "sources": [
              "listItemId"
            ]
          },
          "iconUrl": {
            "@odata.type": "#graph.Json",
            "email address removed for privacy reasons": "#Collection(String)",
            "sources": [
              "IconUrl"
            ]
          },
          "activity": {
            "@odata.type": "#graph.Json",
            "email address removed for privacy reasons": "#Collection(String)",
            "sources": [
              "ModifiedDate"
            ]
          },
          "spWebUrl": {
            "@odata.type": "#graph.Json",
            "email address removed for privacy reasons": "#Collection(String)",
            "sources": [
              "SPWebUrl"
            ]
          },
          "uniqueId": {
            "@odata.type": "#graph.Json",
            "email address removed for privacy reasons": "#Collection(String)",
            "sources": [
              "UniqueID"
            ]
          },
          "imageOverlapText": {
            "@odata.type": "#graph.Json",
            "email address removed for privacy reasons": "#Collection(String)",
            "sources": [
              "ImageOverlapText"
            ]
          },
          "fileExt": {
            "@odata.type": "#graph.Json",
            "email address removed for privacy reasons": "#Collection(String)",
            "sources": [
              "FileType"
            ]
          },
          "tipActionButtonIcon": {
            "@odata.type": "#graph.Json",
            "email address removed for privacy reasons": "#Collection(String)",
            "sources": [
              "TipActionButtonIcon"
            ]
          },
          "className": {
            "@odata.type": "#graph.Json",
            "email address removed for privacy reasons": "#Collection(String)",
            "sources": [
              "ClassName"
            ]
          },
          "tipActionLabel": {
            "@odata.type": "#graph.Json",
            "email address removed for privacy reasons": "#Collection(String)",
            "sources": [
              "TipActionLabel"
            ]
          },
          "imageOverlapTextAriaLabel": {
            "@odata.type": "#graph.Json",
            "email address removed for privacy reasons": "#Collection(String)",
            "sources": [
              "ImageOverlapTextAriaLabel"
            ]
          },
          "name": {
            "@odata.type": "#graph.Json",
            "email address removed for privacy reasons": "#Collection(String)",
            "sources": [
              "Name"
            ]
          },
          "personImageUrl": {
            "@odata.type": "#graph.Json",
            "email address removed for privacy reasons": "#Collection(String)",
            "sources": [
              "ProfileImageSrc"
            ]
          },
          "title": {
            "@odata.type": "#graph.Json",
            "email address removed for privacy reasons": "#Collection(String)",
            "sources": [
              "UserName",
              "Title"
            ]
          }
        },
        "@odata.type": "#graph.Json"
      }
    },
    "serverProcessedContent": {
      "htmlStrings": [],
      "searchablePlainTexts": [
        {
          "key": "title",
          "value": "example_value"
        }
      ],
      "links": [
        {
          "key": "baseUrl",
          "value": "/sites/SiteExample"
        }
      ],
      "imageSources": []
    }
  }
}

From the response, I parse out file metadata that’s attached to the page. For each file, I extract the following fields from data.properties:

 - uniqueId
   
 - listId
   
 - siteId

Then I attempt to retrieve detailed information about the file using the request:

    GET https://graph.microsoft.com/v1.0/sites/${siteId}/lists/${listId}/items/${uniqueId}/driveItem?select=id,size,parentReference,name,webUrl,file,createdBy,folder

This request works for most files. However, for some files—despite having the correct uniqueId, listId, and siteId and even when I can manually verify that the file exists—the request returns a 404 error. I need the detailed JSON response mainly to obtain the webUrl to download the file.

My questions are:

 1. Why might some files return a 404 even though their metadata appears
    correct?
           
 2. What alternative approach (e.g., using a different endpoint) can I  
    use to reliably obtain the full JSON details for these file attachments?

Any insights or suggestions would be appreciated.

1 Reply

  • AtticusGrove's avatar
    AtticusGrove
    Iron Contributor

    1. Check if the resource exists 
    Confirm site/list/file ID 
    Check the URL in the SharePoint interface to make sure siteId, listId, fileId are correct 
    Test if the site exists using GET /sites/{site-id} 
    Check if the file has been deleted/moved 
    Find it in the SharePoint Recycle Bin 
    2. Verify permissions 
    Check for API permissions 
    Ensure application registration (Azure AD) is authorized Sites.Read.All or Sites.ReadWrite.All 
    Administrator needs to agree to permissions (https://admin.consent.microsoft.com) 
    Check user permissions 
    Ensure user has read permissions to target files/lists 
    3. Check API request format 
    Correct format: 
    GET /sites/{site-id}/lists/{list-id}/items/{item-id}/driveItem 
    Common error: 
    using list-title instead of list-id (need to be converted) 
    Incorrect API version (should use v1.0 or beta) 
    4. Solution 
     Fix API request 
    http 
    GET https://graph.microsoft.com/v1.0/sites/{site-id}/drives/{drive-id}/items/{item-id} 
    drive-id = Document Library ID (can be used with GET /sites/{site-id}/drives/{drive-id}/driveItem}) drive-id = Document Library ID (available as GET /sites/{site-id}/drives) 
    item-id = Document ID (available as GET /sites/{site-id}/drives/root/children) 
    5. Check SharePoint Online status 
    Access Microsoft 365 service status 
    Verify that the SharePoint Online service is OK 
    6. Test with Graph Browser 
    Open Graph Browser 
    Test API requests after login 
    7. Advanced Debugging 
    Check HTTP response header (x-msrequest-id) 
    Grab packets using Fiddler/Postman 
    View Azure AD Audit Logs (SignInLogs)

Resources