Is it possible to perform an enterprise-wide search by FileId to find OwnedBy.Id?
ewilansky opened this issue · comments
- [ x ] I have checked that the SDK documentation doesn't solve my issue.
- [ x ] I have checked that the API documentation doesn't solve my issue.
- [ x ] I have searched the Box Developer Forums and my issue isn't already reported
- [ x ] I have searched Issues in this repo and my issue isn't already reported.
Description of the Issue
Given a FileId, I am unable to return the associated file because it doesn't appear your API supports searching by core metadata (not metadata template search) when using SearchManager.QueryAsync. I'm using a JWT and can impersonate a user assigned the enterprise_content scope, if necessary.
Steps to Reproduce
I'm able to perform this kind of file name search in the context of user (userid: 12345). Here, I'm searching by file name (file01.docx) using a JWT and impersonating user 12345. This is just the canonical example to be clear that this works:
var userId = "12345";
var boxAuth = new BoxJWTAuth(boxConfig);
var boxClient = new BoxClient(boxConfig, boxAuth.Session(boxAuth.AdminToken()), userId, suppressNotifications: true);
var response = await boxClient.SearchManager.QueryAsync(
query: "file01",
fileExtensions: new [] { "docx" },
limit: 1,
scope: "user_content",
type: "file",
contentTypes: new [] { "name" }
);
Console.WriteLine(response.Entries.SingleOrDefault()); \\ returns the one entry I want
Expected Behavior
I believe I can do the same using scope: "enterprise_content" with a UserId who has been granted enterprise_content scope, as explained here: Enterprise-wide Search. This approach should then let me get the file and retrieve the OwnedBy.Id value. I have not specifically requested the enterprise_content scope since this common example is not specifically what I'm trying to achieve, but is an important step.
Before I request enterprise_content scope be assigned to a user, can you explain if it's possible to return a file by BoxFile.Id using JWT and impersonating a user granted enterprise_content scope?
Second, I can see that contentTypes are limited to name (file prefix), description, file_content, comments or tags. If it also supported a small subset of core metadata, it would be great if I could do something like this:
// given a BoxFile.Id (56789) and a JWT, return the associated BoxFile w/out having to impersonate a user (using enterprise_content scope):
var boxAuth = new BoxJWTAuth(boxConfig);
var boxClient = new BoxClient(boxConfig, boxAuth.Session(boxAuth.AdminToken()), null, suppressNotifications: true);
var response = await boxClient.SearchManager.QueryAsync(
query: "Id = 56789",
limit: 1,
scope: "enterprise_content",
type: "file",
contentTypes: new [] { "meta" }
);
Console.WriteLine(response.Entries.SingleOrDefault());
If absolutely necessary, it would be okay to impersonate a user assigned enterprise_content scope (say, userid: 12345) so initializing the boxClient could be changed to:
var boxClient = new BoxClient(boxConfig, boxAuth.Session(boxAuth.AdminToken()), "12345", suppressNotifications: true);
Versions Used
.Net SDK: .Net Core 3.1 and now .Net 5.0
OS X Catalina (10.15.7)
I can submit this to pulse.box.com, but want to make sure I'm not missing anything first. It seems to me that searching by core metadata (not metadata template search) and, in particular, a BoxFile.Id is fundamental search operation.
This issue has been automatically marked as stale because it has not been updated in the last 30 days. It will be closed if no further activity occurs within the next 7 days. Feel free to reach out or mention Box SDK team member for further help and resources if they are needed.
This issue has been automatically closed due to maximum period of being stale. Thank you for your contribution to Box .NET SDK and feel free to open another PR/issue at any time.