1

I have a term store which has some terms "Defender", "Forward", etc. I then have a document library which uses those terms as meta data on the documents.

I want to use the sharepoint search api to retrieve any documents that have used the "Defender" meta data, like in the images below.

I have a function to grab the documents:

  public getDocuments() {
    axios 
    .get("https://bpk.sharepoint.com/_api/SEARCH DOCUMENTS VIA TERMS FROM THE TERM STORE",
            { params:{},
              headers: { 'accept': 'application/json;odata=verbose' }
            })
    .then(response => {
      this.setState({
        documents: response.data.d.results
      });
    })
    .catch(error => {
      console.log(error);
    });
  }

Can anybody please point me in the right direction for what the search api end point should be? <3

enter image description here

enter image description here

EDIT - This is how I achieved this!:

  public getDocuments() {

    axios
      .get("https://bpk.sharepoint.com/_api/search/query?querytext='owstaxIdPOsitionsx0020COlour:defender'&trimduplicates=true&rowsperpage=100&rowlimit=1000",
        { params:{},
          headers: { 'accept': 'application/json;odata=verbose' }
        })
      .then(response => {
        this.setState({
          documents: response.data.d.query.PrimaryQueryResult.RelevantResults.Table.Rows.results
        });
      })
      .catch(error => {
        console.log(error);
      });

  }

1 Answer 1

2

Your starting point is /_api/search/query.

A simple query would be: /_api/search/query?querytext='sharepoint'

You need to learn to use the Keyword Query Language to construct your query.

If you are using a customer metadata field you'll need to create a Managed Property for example Position. Then you can use it in your queries.

Specifically for Taxonomy fields you can use taxonomy ID or Term depending on how you want your query to work: owstaxIdPosition:'Defender'

The documentation you seek begins here: https://docs.microsoft.com/en-us/sharepoint/dev/general-development/sharepoint-search-rest-api-overview

3
  • Thanks dude, I have sorted this now :D
    – BennKingy
    Commented Dec 3, 2019 at 15:12
  • I have updated my answer to show my solution
    – BennKingy
    Commented Dec 4, 2019 at 10:10
  • 1
    Excellent! Glad it worked. Commented Dec 4, 2019 at 14:03

Your Answer

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

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