Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to get drive item by path #2213

Closed
susanYYT opened this issue Nov 4, 2024 · 7 comments
Closed

How to get drive item by path #2213

susanYYT opened this issue Nov 4, 2024 · 7 comments
Assignees
Labels
Needs: Attention 👋 type:question An issue that's a question

Comments

@susanYYT
Copy link

susanYYT commented Nov 4, 2024

Hi,

I'm using Graph v6, and I want to get DriveItem by path.

In v5, I use:
DriveItem item = graphClient.sites(site.id).drives(d.id).root().itemWithPath(itemPath).buildRequest().get();
Now I use
DriveItem item = graphClient.drives().byDriveId(d.getId()).items().byDriveItemId(itemPath).get();
But I received error:
com.microsoft.graph.models.odataerrors.ODataError: Item not found

Does the input itemPath has something special in format?

For example, if my siteUrl is myshare.sharepoint.com/sites/test1, then if I get site by path, I can use myshare.sharepoint.com:/sites/test1: as input. While for drive item, the sheet relative path is /test1/AdapterOffice365/DPtest.xls/int. Could you please give me an example?

Best regards,
Susan

@susanYYT susanYYT added the status:waiting-for-triage An issue that is yet to be reviewed or assigned label Nov 4, 2024
@Ndiritu
Copy link
Contributor

Ndiritu commented Nov 7, 2024

Hi @susanYYT
Thank you for reaching out.
Please see a similar issue here
The relative path for your drive item should be root:/test1/AdapterOffice365/DPtest.xls/int:

Please let me know if this helps

@Ndiritu Ndiritu added status:waiting-for-author-feedback Issue that we've responded but needs author feedback to close type:question An issue that's a question and removed status:waiting-for-triage An issue that is yet to be reviewed or assigned labels Nov 7, 2024
@susanYYT
Copy link
Author

susanYYT commented Nov 7, 2024

Could the relative path contains _ ? I actually try root:/A_test1/AdapterOffice365/DPtest.xls/int: , but it doesn't work.

@microsoft-github-policy-service microsoft-github-policy-service bot added Needs: Attention 👋 and removed status:waiting-for-author-feedback Issue that we've responded but needs author feedback to close labels Nov 7, 2024
@susanYYT
Copy link
Author

@Ndiritu Could you give some suggestions?

@Ndiritu
Copy link
Contributor

Ndiritu commented Nov 12, 2024

Sorry for the delay @susanYYT.

Yes, based on the guidance here, underscores are allowed.

I'm wondering if your path is correct, is the /int at the end of the URL valid?

You can test your request path using https://developer.microsoft.com/en-us/graph/graph-explorer to double-check.

If you still have trouble, you can pass a custom URL using withUrl() to override the entire request URL:

graphClient.drives().byDriveId("").items().byDriveItemId("").withUrl(
    "https://graph.microsoft.com/v1.0/..."
).get();

@Ndiritu Ndiritu added status:waiting-for-author-feedback Issue that we've responded but needs author feedback to close and removed Needs: Attention 👋 labels Nov 12, 2024
@susanYYT
Copy link
Author

Dear @Ndiritu,

Thanks for your reply. Maybe I have some misunderstanding about the root:/path/to/file. int is a sheet in the DPtest.xls. I've changed the path to /root:/A_test1/AdapterOffice365/DPtest.xls: . But still have some trouble. Could you correct me?

The site url is: https://test.sharepoint.com/sites/A_test1
So I can download the file if I visit weburl https://test.sharepoint.com/sites/A_test1/AdapterOffice365/DPtest.xls

I tried the graph explorer, https://graph.microsoft.com/v1.0/drive/root:/A_test1/AdapterOffice365/DPtest.xls: , but it reports assess denied.
image

I want to consent to permissions but it shows "Retry again". Any suggestions?

@microsoft-github-policy-service microsoft-github-policy-service bot added Needs: Attention 👋 and removed status:waiting-for-author-feedback Issue that we've responded but needs author feedback to close labels Nov 14, 2024
@susanYYT
Copy link
Author

Since I've found the drive AdapterOffice365, I actually need to use root:/DPtest.xls:. I can get the drive item now. Thanks very much for your help.

@Ndiritu Ndiritu self-assigned this Nov 22, 2024
@Ndiritu
Copy link
Contributor

Ndiritu commented Nov 22, 2024

Glad you were able to resolve this @susanYYT . My apologies for the delayed response.

@Ndiritu Ndiritu closed this as completed Nov 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Needs: Attention 👋 type:question An issue that's a question
Projects
None yet
Development

No branches or pull requests

2 participants