Legacy Dev Forum Posts

 View Only

Sign Up

Get second page of search result

  • 1.  Get second page of search result

    Posted 06-05-2025 18:04

    vrvoice1 | 2016-07-19 08:27:45 UTC | #1

    Hi, I want to get the second page of my search result. I'm trying this code:

    ` UserSearchRequest body = new UserSearchRequest();

    body.PageSize = 5; body.Query = new List<UserSearchCriteria>(); body.Query.Add(new UserSearchCriteria(Type: UserSearchCriteria.TypeEnum.RequiredFields) { Fields = new List<string>() { "name" } });

    UsersApi userApi = new UsersApi();

    var result1 = userApi.PostSearch(body);

    string q64 = result1.NextPage.Split('=').Last();

    var result2 = userApi.GetSearch(q64);`

    The PostSearch is working. I got the first page and the total count is 11. But if I try to get the next page with the q64 string, I get the following error:

    ` Error calling GetSearch: { "status":400, "code":"bad.request", "message":"The requested operation failed with status 400", "contextId":"84f4bee9-dec1-494f-9603-98f1e370c1b9", "details":[], "errors":[]} ` I have tried the q64 string with Postman and there it's working fine.

    Regards,

    Sven


    tim.smith | 2016-07-19 14:24:07 UTC | #2

    Can you make sure you're using the latest version of the SDK and try again? I tried this with the code below and it worked correctly. Can you grab the correlation ID from the response header when you retry?

    var body = new UserSearchRequest(); body.PageSize = 2; body.Query = new List<UserSearchCriteria>(); body.Query.Add((new UserSearchCriteria(Type: UserSearchCriteria.TypeEnum.RequiredFields) { Fields = new List<string> {"name"} }));

    var usersApi = new UsersApi(); var result1 = usersApi.PostSearch(body); var q64 = result1.NextPage.Split('=').Last(); var result2 = usersApi.GetSearch(q64);


    vrvoice1 | 2016-07-20 07:15:33 UTC | #3

    Hi Tim,

    yes the Api version is 0.64.0.318. I have try your one and it's working. I have try my one again and it's not. But the only different between is the page size. If I set the size in my one to 2 it's working too. Are there any requirements for that?

    This are the counts from result one <img src="//inin-prod-use1-developerforum.s3.amazonaws.com/original/1X/e5c2b986b79777487c6a89a2aa0c5075b8cc915f.PNG" width="355" height="166">

    This is the contextId if the error ocurred

    "contextId":"9609b373-ed85-4bcf-9dda-6dcee9c21bd6"


    tim.smith | 2016-07-20 23:13:43 UTC | #4

    EDITED

    I was able to reproduce the 400 error by finding and using q64 values that contained %3D at the end. This is because the API provides the first/previous/current/next/last page URIs as ready-for-use URIs complete with encoded querystring parameters. When you parse it out, you have an encoded parameter value. When you pass that into the GET method as a value, the SDK encodes the value before sending it. This causes an issue because the q64 value was double encoded (once by the API and once by the SDK). I've logged SRCH-773 to add the q64 values as stand-alone parameters on the responses. Once this makes it into the API, the next build of the SDK will contain the properties for it.

    I did find a workaround though. If you decode just the %3D part, the query works: query = query.Replace("%3D", "=");

    Here's my full sample code to print out all of the users, page by page:

    private static void TestUserSearch() { var body = new UserSearchRequest(); body.PageSize = 2; body.Query = new List<UserSearchCriteria>(); body.Query.Add((new UserSearchCriteria(Type: UserSearchCriteria.TypeEnum.RequiredFields) { Fields = new List<string> {"name"} }));

    _usersApi = new UsersApi(); var result1 = _usersApi.PostSearch(body); var query = result1.CurrentPage.Split('=').Last();

    while (true) { query = query.Replace("%3D", "="); var result = _usersApi.GetSearch(query); if (result.Results != null) { result.Results.ForEach(user => Console.WriteLine(user.Name)); var nextQuery = result.NextPage.Split('=').Last(); if (!string.Equals(query, nextQuery)) { query = nextQuery; continue; } } Console.WriteLine("Processed all results"); break; } }


    system | 2017-08-28 19:25:20 UTC | #5


    This post was migrated from the old Developer Forum.

    ref: 142