AnsweredAssumed Answered

REST API sort bug or future implementation?

Question asked by mb23565 on Jun 6, 2017
Latest reply on Jun 6, 2017 by mb23565

So I was playing around with query parameters and decided to see what the API would accept.... I came across a 400 error when trying add a sort query parameter to the url.

 

/users?sort=asc|desc

 

Unhandled rejection StatusCodeError: 400 - {"status":400,"message":": 1 errors\nField error in object 'usersSortCriteriaPubV1' on field 'sort': rejected value [asc]; codes [methodInvocation.usersSortCriteriaPubV1.sort,methodInvocation.sort,,methodInvocation]; arguments [: codes [usersSortCriteriaPubV1.sort,sort]; arguments []; default message [sort]]; default message [Property 'sort' threw exception; nested exception is : Cannot sort using specified field : asc]","extraInfo":"2788a5503e6f4230a552776c7dcbd41b"}
    at new StatusCodeError (/home/elmiguel/CodeProjects/irsc-projects/mean-cm-instructors-3/node_modules/request-promise-core/lib/errors.js:32:15)
    at Request.plumbing.callback (/home/elmiguel/CodeProjects/irsc-projects/mean-cm-instructors-3/node_modules/request-promise-core/lib/plumbing.js:104:33)
    at Request.RP$callback [as _callback] (/home/elmiguel/CodeProjects/irsc-projects/mean-cm-instructors-3/node_modules/request-promise-core/lib/plumbing.js:46:31)
    at Request.self.callback (/home/elmiguel/CodeProjects/irsc-projects/mean-cm-instructors-3/node_modules/request/request.js:188:22)
    at emitTwo (events.js:106:13)
    at Request.emit (events.js:194:7)
    at Request.<anonymous> (/home/elmiguel/CodeProjects/irsc-projects/mean-cm-instructors-3/node_modules/request/request.js:1171:10)
    at emitOne (events.js:96:13)
    at Request.emit (events.js:191:7)
    at IncomingMessage.<anonymous> (/home/elmiguel/CodeProjects/irsc-projects/mean-cm-instructors-3/node_modules/request/request.js:1091:12)
    at Object.onceWrapper (events.js:293:19)
    at emitNone (events.js:91:20)
    at IncomingMessage.emit (events.js:188:7)
    at endReadableNT (_stream_readable.js:975:12)
    at _combinedTickCallback (internal/process/next_tick.js:80:11)
    at process._tickDomainCallback (internal/process/next_tick.js:128:9)

 

So is this something that is coming down the pipeline? Or is this bug in sorting the results of the request?

 

 

Edit: I see that it is trying to sort by a field: so by doing /users?limit=4&sort=userName, this produces a list of 4 sorted by the userName in ascending order.

So maybe not a bug, but limited sorting feature...expansion in the future?

 

Edit: I see that there some documentation on it in the API docs. What would be nice if there was a more robust method to allow searching based on more fields then just externalId,userName,dataSourceId. Meaning what it someone needed to lookup a user based on email? or First Name and Last Name groups? There is no functionality that I see that would allow someone to do this with the current API endpoints and query parameters.

 

So something like:

 

/users?sort=userName(desc)&email=user@xyz.edu

 

or

 

/users?sort=externalId,name.family(asc,'smith'),name.given(asc,'Jo*')

 

or (better yet)

 

/users/email:user@xyz.edu

/users/nameFamily:Smith

/users/nameGiven:John

/users/name:{given:'John', family:'Smith'}

/users?email=*@xzy.edu

etc, etc etc.

 

Where one could not only sort the results by an 'order by' structure, but also by limiting the query down to a specific subset of results.

Outcomes