0

I can't believe this is so difficult. Here is what I need and I just seem to be chasing my tail and not getting anywhere.

  1. In my local database I have stored the path and the file id of files that are in SharePoint, along with some other meta-data.
  2. Pulling the path and file ID, I can use the _api/web/lists/getbyTitle('')/items() to find this file object. I can see the return results in Postman.

This works fine.

Second 1. I can search for a file in SharePoint using the _api/search/query?queryText='' This return a list of search results with data that I need to diplay to the user. Namely, the Path, ServerRedirectedURL, ServerRedirectedEmbedURL, and ServerRedirectedPreviewURL.

Upon suggestions from other great folks here, I put /?$expand=file to the end of the first search but still do not see these attributes for the file. So:

  1. Is there a way to pull these attributes using the _api/web/lists/getbyTitle/item api call? If not, then:
  2. can I pull an attribute from the file object and use that in the search object? For example, the "GUID" field?

I would even make two calls to the API if needed to get this done, I just can't believe that there isn't a way to do a search with an ID or GUID through the API to pull back a file, or a way to get the full attribute data of a file that is returned by the search.

Any help to this end would be much, much appreciated.

Thanks.

2
  • Are you displaying the results outside SharePoint? If not I would choose a CSOM search based approach with custom display templates and so on. Jul 25, 2018 at 22:39
  • These results are all displayed outside of SharePoint, but we need to use the REST API since many applications will be using this search not just .NET applications. So the CSOM is not a valid option in this case because we need to use the REST from Angular, JavaScript, Python, .NET, Java, etc.
    – john
    Jul 25, 2018 at 22:44

1 Answer 1

0

Even i was struggling with a similar kind of requirement because the search rest api does not return the ID or the GUID field of the document. So I made a custom column for the GUID field and was storing the GUID of the document after it is uploaded. Then make the managed property of this field and include the column in the search api like.

var url = "http://mycompany.sharepoint.com/site1/_api/search/query?querytext='SearchTerm+AND+IsDocument=True'&selectproperties='DocGUID'";

This will return the GUID of all the documents appeared in the search result. And make an another rest call to the corresponding list to get the rest of the attributes like this.

var url = "http://mycompany.sharepoint.com/site1/_api/Web/Lists/GetByTitle('Lib1')/Items?$select=File/Name,FileRef,ID&$expand=File&$filter=ParentGUID eq '" + DocGUID+ "'";

Hope this helps..

1
  • 1
    This isn't quite what I am after. I can get the ID and GUID of the file using the getbyID api call. What i need is a way to get some properties from a search or search for this item to get these properties--Path, ServerRedirectedURL ServerRedirectedEmbedURL, and ServerRedirectedPreviewURL. So this is the opposite of what is shown. I need to get search details for a specific file and need to know how to search for this specific file.
    – john
    Jul 26, 2018 at 14:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.