使用Microsoft Graph API复制Teams团队SharePoint文件后,ResourceId查询提示‘Item not found’问题求助
Hey Oskar, let's work through why you're seeing that frustrating "Item not found" error even though the file clearly exists in SharePoint. Here are some actionable steps to diagnose and fix the issue:
Double-check the ResourceId context
Sometimes theresourceIdreturned by the long-running copy operation isn't meant to be used directly with the group or drive ID you initially specified. Teams' SharePoint sites are tied to an underlying Site resource, not just the Group's default drive. Try fetching the site associated with your group first:GET /groups/{groupId}/sites/rootThen use the resulting
id(site ID) to query the file:GET /sites/{siteId}/drive/items/{resourceId}This ensures you're targeting the exact site context where the file was copied.
Verify you're using the correct drive
If you specified a non-default drive in your copy request'sparentReference.driveId, make sure that drive belongs to the site (not just the group). You can confirm the drive's association by querying:GET /sites/{siteId}/drives/{driveId}If this returns a valid drive, use this site-drive combination to fetch your item instead of the group's drive.
Check for index propagation delays
Even though the copy operation reports "Completed", there can be a short lag between SharePoint finishing the copy and Graph API indexing the new item. Wait 5-10 minutes and try your query again—this is especially common with larger files.Use the
resourceLocationdirectly (if available)
When the long-running operation completes, check if the monitor response includes aresourceLocationfield. This is a direct Graph API URL pointing to your copied file, so using this URL instead of manually constructing the path avoids any context mismatches.Validate permissions and token scope
Sometimes a "Item not found" error can mask a permission issue. Ensure your access token has scopes likeFiles.Read.AllorSites.Read.All(depending on your use case). Test the same query in Graph Explorer with the same token to rule out permission-related problems.Confirm no ID formatting issues
Make sure you're copying the fullresourceIdvalue from the monitor response—no extra spaces, truncated characters, or URL encoding mismatches. If the ID contains special characters, ensure they're properly URL-encoded in your query.
If none of these steps resolve the issue, double-check your original copy request's parentReference parameters to ensure you're targeting the correct folder and drive in the SharePoint site.
内容的提问来源于stack exchange,提问作者Oskar Jensson Fjeld

