SOLVED
Home

Search REST query - filtering ModifiedBy by Current User

%3CLINGO-SUB%20id%3D%22lingo-sub-59148%22%20slang%3D%22en-US%22%3ESearch%20REST%20query%20-%20filtering%20ModifiedBy%20by%20Current%20User%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-59148%22%20slang%3D%22en-US%22%3E%3CP%3EHi%2C%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ETrying%20to%20show%20the%2010%20most%20recent%20documents%20edited%20by%20the%20current%20user%20by%20calling%20the%20search%20REST%20api%2C%20but%20I%20am%20struggling%20with%20filtering%20the%20results%20by%20the%20current%20user.%20Using%20this%20call%20gives%200%20results%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%2F_api%2Fsearch%2Fquery%3Fquerytext%3D'(*)%2BAND%2B(path%3A%22https%3A%252f%252fscentregroup.sharepoint.com%252fsites%252fcorplegal_dev%22)%2BAND%2B(FileExtension%3Adoc%2BOR%2BFileExtension%3Adocx%2BOR%2BFileExtension%3Appt%2BOR%2BFileExtension%3Apptx%2BOR%2BFileExtension%3Axls%2BOR%2BFileExtension%3Axlsx%2BOR%2BFileExtension%3Axlsm%2BOR%2BFileExtension%3Apdf)'%26amp%3Btrimduplicates%3Dfalse%26amp%3Brefinementfilters%3D'ModifiedBy%3A%7BUser.Name%7D'%26amp%3Bclienttype%3D'ContentSearchRegular'%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EHowever%20if%20I%20use%20my%20actual%20name%2C%20I%20get%20the%20expected%20set%20of%20results%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%3E%2F_api%2Fsearch%2Fquery%3Fquerytext%3D'(*)%2BAND%2B(path%3A%22https%3A%252f%252fscentregroup.sharepoint.com%252fsites%252fcorplegal_dev%22)%2BAND%2B(FileExtension%3Adoc%2BOR%2BFileExtension%3Adocx%2BOR%2BFileExtension%3Appt%2BOR%2BFileExtension%3Apptx%2BOR%2BFileExtension%3Axls%2BOR%2BFileExtension%3Axlsx%2BOR%2BFileExtension%3Axlsm%2BOR%2BFileExtension%3Apdf)'%26amp%3Btrimduplicates%3Dfalse%26amp%3Brefinementfilters%3D'ModifiedBy%3ANigel%20Witherdin'%26amp%3Bclienttype%3D'ContentSearchRegular'%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%3EIs%20there%20a%20token%20value%20I%20can%20use%20in%20this%20REST%20call%2C%20or%20should%20I%20be%20determining%20the%20current%20user's%20display%20name%20in%20the%20script%20myself%20and%20insert%20it%20into%20the%20REST%20call%3F%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%3EThanks%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%3ENigell%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-59406%22%20slang%3D%22en-US%22%3ERe%3A%20Search%20REST%20query%20-%20filtering%20ModifiedBy%20by%20Current%20User%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-59406%22%20slang%3D%22en-US%22%3E%3CP%3EThanks%20Paul%20-%20you're%20a%20machine!%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-59158%22%20slang%3D%22en-US%22%3ERe%3A%20Search%20REST%20query%20-%20filtering%20ModifiedBy%20by%20Current%20User%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-59158%22%20slang%3D%22en-US%22%3E%3CP%3EAs%20described%20in%20this%20blog%20by%20%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F34%22%20target%3D%22_blank%22%3E%40Mikael%20Svenson%3C%2FA%3E%26nbsp%3Byou%20can%20use%20Query%20Variables%20together%20with%20the%20REST%20api%3C%2FP%3E%3CP%3E%3CA%20href%3D%22http%3A%2F%2Fwww.techmikael.com%2F2015%2F07%2Fsharepoint-rest-do-support-query.html%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttp%3A%2F%2Fwww.techmikael.com%2F2015%2F07%2Fsharepoint-rest-do-support-query.html%3C%2FA%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EKey%20here%20is%20to%20make%20use%20of%20QueryTemplate%20instead%20of%20QueryText.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E
Nigel Witherdin
Contributor

Hi,

 

Trying to show the 10 most recent documents edited by the current user by calling the search REST api, but I am struggling with filtering the results by the current user. Using this call gives 0 results:

 

/_api/search/query?querytext='(*)+AND+(path:"https:%2f%2fscentregroup.sharepoint.com%2fsites%2fcorplegal_dev")+AND+(FileExtension:doc+OR+FileExtension:docx+OR+FileExtension:ppt+OR+FileExtension:pptx+OR+FileExtension:xls+OR+FileExtension:xlsx+OR+FileExtension:xlsm+OR+FileExtension:pdf)'&trimduplicates=false&refinementfilters='ModifiedBy:{User.Name}'&clienttype='ContentSearchRegular'

 

However if I use my actual name, I get the expected set of results:

 

/_api/search/query?querytext='(*)+AND+(path:"https:%2f%2fscentregroup.sharepoint.com%2fsites%2fcorplegal_dev")+AND+(FileExtension:doc+OR+FileExtension:docx+OR+FileExtension:ppt+OR+FileExtension:pptx+OR+FileExtension:xls+OR+FileExtension:xlsx+OR+FileExtension:xlsm+OR+FileExtension:pdf)'&trimduplicates=false&refinementfilters='ModifiedBy:Nigel Witherdin'&clienttype='ContentSearchRegular'

 

Is there a token value I can use in this REST call, or should I be determining the current user's display name in the script myself and insert it into the REST call?

 

Thanks

 

Nigell

 

 

 

2 Replies
Highlighted
Solution

As described in this blog by @Mikael Svenson you can use Query Variables together with the REST api

http://www.techmikael.com/2015/07/sharepoint-rest-do-support-query.html

 

Key here is to make use of QueryTemplate instead of QueryText.

 

Thanks Paul - you're a machine!

Related Conversations
Tabs and Dark Mode
cjc2112 in Discussions on
48 Replies
Extentions Synchronization
Deleted in Discussions on
3 Replies
Stable version of Edge insider browser
HotCakeX in Discussions on
35 Replies
How to Prevent Teams from Auto-Launch
chenrylee in Microsoft Teams on
30 Replies
flashing a white screen while open new tab
Deleted in Discussions on
14 Replies
Security Community Webinars
Valon_Kolica in Security, Privacy & Compliance on
13 Replies