box / box-windows-sdk-v2

Windows SDK for v2 of the Box API. The SDK is built upon .NET Framework 4.5

Home Page:https://developer.box.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

SearchManager.QueryAsync throwing error C# SDK

jkyadav opened this issue · comments

When calling below method it is giving error.
"The API returned an error [BadRequest | pidgc8gv4igelb3i.0973aae7b72f661c48bff8d457adb46a0] bad_request - Bad Request"

var task = Task.Run(async () =>
{
var fields = new List<string>
{
BoxItem.FieldParent,
BoxItem.FieldName,
BoxItem.FieldSize,
BoxItem.FieldCreatedBy,
BoxItem.FieldCreatedBy,
BoxItem.FieldPathCollection,
BoxFolder.FieldCreatedBy,
BoxFolder.FieldPathCollection,
BoxFolder.FieldItemCollection,
BoxFolder.FieldSyncState
};

return await userClient.SearchManager.QueryAsync(query: searchKeyword, fields: fields, type: "folder");
});

return task.Result.Entries ?? new List<BoxItem>();

Rest all methods working good.

Hi @jkyadav,

I'm trying to replicate your error. I can get 400 error when searchKeyword is null or an empty string. Can you tell me if this is your case?

@antusus Passing the query param like below.

return await u.Data.SearchManager.QueryAsync(query: "612162", type: "folder");

@jkyadav I cannot find the log with the request id you have put. Can you give me a recent one?

Also which version of the SDK you are using and what is you authentication method?

Request: "The API returned an error [BadRequest | 6ogkjjgvbkipu8za.1f61cc0bafff56ed1b98199958fb9ae39] bad_request - Bad Request
"
This is the code used:

var boxConfig = new BoxConfig("Client-ID", client-secret", "", privateKey, "", "");
            var boxJWT = new BoxJWTAuth(boxConfig);
            var adminToken = boxJWT.AdminTokenAsync().Result;
            var adminClient = boxJWT.AdminClient(adminToken);
            var userRequest = new BoxUserRequest() { Name = "test appuser", IsPlatformAccessOnly = true };
            //var appUser = adminClient.UsersManager.CreateEnterpriseUserAsync(userRequest).Result;

            //get a user client
            var appUserID = "123456789";
            var userToken = boxJWT.UserTokenAsync(appUserID).Result; //valid for 60 minutes so should be cached and re-used
            var u = boxJWT.UserClient(userToken, appUserID);

<package id="Box.V2" version="3.26.0" targetFramework="net462" />

I downloaded your repo and tried with that that also giving same error.

Let me know if you need anymore details

Thanks

I've tried that with both the admin and user client. And it works. Maybe we could verify that you are authenticating correctly. I can see you are using JWT:

var boxConfig = new BoxConfig(
    "client id from json file",
    "client secret from json file",
    "enterprise id from json file",
    "private key from json file",
    "private key password from json file",
    "public key id from json file");
var jwt = new BoxJWTAuth(boxConfig);
string token = await jwt.AdminTokenAsync();
var adminClient = jwt.AdminClient(token);
var rootFolder = await adminClient.FoldersManager.GetInformationAsync("0");
Console.WriteLine(rootFolder.Id + " " + rootFolder.Name);

This should print your root folder name.

@antusus This is what I'm getting.

image

JFYI rest of our enterprise's are working fine with same code, only one of that causing this problem. And even with this enterprise every other methods are working only Search not working.

Hi @antusus,

Any update on this? It is affecting one of very large customer.

Thanks

Not yet, I'm contacting API team to figure out what is wrong.

Hi @antusus,

Have you got any update from API team?

Thanks

Hi @jkyadav,

as far as I know they were able to narrow it down to analytics client configuration. We just have to wait for a US based team to came online and they should be able to make progress with that.

Thank you for the update @antusus

Hi @antusus Any update on this?

Hi @jkyadav ,

as far as I know there is a Zendesk ticket opened and our support will be reaching out for additional details.

@antusus yes, I replied them, they were just asking if I'm able to hit any other method or not. So I'm able to hit other method I shared you image of that too.

Thanks

@antusus Any update on this?

Hi,
we are waiting for a solution from a team that works on search. It looks that in a folder from which search originates there are lot of folders with collaborations. Search has a limit of 10000 collaborators and maybe this is reaching the limit. But we are still waiting for a response from a dedicated team.

Hi @antusus ,

Any update on this?

Thanks

Hi @jkyadav ,
team rolled out some tweaks to allow doing search when number having lot's collaborators. We saw some successful queries originating from your client. It this is the case then let me know. If not please update the Zendesk ticket with more details.

@antusus This seems to be working fine, but still keep it open will update you by tomorrow.

Hi @jkyadav I can see that support ticked is marked as solved. I hope API now works as it should. If everything is fine maybe you can close the issue?

@antusus This seems still happening in some cases, here is the new request log id for you to check, I have updated the ticket as well.

The API returned an error [InternalServerError | 79xp3xgvwgr947j1.0b6c7b4e8538858c0bc59f65d1d641a4c] internal_server_error - Internal Server Error

Thanks

@jkyadav could you share a query that you were using?

This is happening on below query and happening always.

userClient.SearchManager.QueryAsync(query: searchKeyword, fields: fields, type: "folder");

The API returned an error [InternalServerError | n2vce4gvyrut4t8m.0e216a9a4021dd1791d3372cb56a09df9] internal_server_error - Internal Server Error

Thanks

Not able to query on any folder. what different query you want me to search? we only passing search string that's all.

@antusus We have made some permission changes at our end per Box's suggestion. but now we getting this error when doing search. Would you be able to check it out ,why it's timing out.?

image

Hello @jkyadav,
The SDK has a timeout set to 100 seconds and you cannot override it.

@antusus I get that but why it is timing out? I'm just passing one string to search that's all.

Question is in what structure are you searching in. Maybe you have extended folder structure with lots of other metadata and this search is taking longer than 100 seconds.
You could verify that with cURL request: https://developer.box.com/reference/get-search/
I would continue talking with support over this. If the API team will say they cannot speed this up than maybe adding possibility to change timeout in SDK will be the next step.

@antusus This is the search query that we are using. It is getting worse day by day, that not getting resolution it's been almost 2 months now. could we we do something to speed up this?

They given permission to the top folder now earlier it was on each folder.

var task = Task.Run(async () =>
{
var fields = new List<string>
{
BoxItem.FieldParent,
BoxItem.FieldName,
BoxItem.FieldSize,
BoxItem.FieldCreatedBy,
BoxItem.FieldCreatedBy,
BoxItem.FieldPathCollection,
BoxFolder.FieldCreatedBy,
BoxFolder.FieldPathCollection,
BoxFolder.FieldItemCollection,
BoxFolder.FieldSyncState
};

return await userClient.SearchManager.QueryAsync(query: "60650075", fields: fields, type: "folder");
});

return task.Result.Entries ?? new List<BoxItem>();

I'm not able to help you with the API performance. The best way is to use support and talk with them directly as I think you are already doing so. Please bear in mind that today is a Day after Thanks Giving and you might get some answers on Tuesday.
You might want to add another enhancement ticket to add support for setting up timeout in Windows SDK.

I emailed them yesterday no response that must be because of holiday, will wait for them to reply.

Hi @jkyadav,
I hope the issue is being resolved. I would like that you would continue talking with support through your Support ticket. Your support ticket should be the only source of truth

Next SDK release will introduce setting timeout which will allow you to set it for longer time than 100s.

I'm closing this ticket as this issue is not related to SDK itself.