0

I was tried many times, I am not able to calling rest Api call, when i was tried with ajax call then it's work fine, but when i tried with rest api then it's not working.

so can you help me to find solution for that.

I have attached image of ajax call and rest api's error.

enter image description here (AJAX call Image)

enter image description here (Rest Call Image)

enter image description here (Error Image)

I have tried to found many sites, but not getting proper answer.

1 Answer 1

0

SharePoint Online allows you to perform searches using the SharePoint Search REST API. You can use the REST API to execute search queries and retrieve search results programmatically. Here's how you can call the SharePoint Search API using the REST API:

// Replace these with your actual values
var siteUrl = "https://your-sharepoint-site-url";
var searchQuery = "your search query";
var accessToken = "your-access-token";

$.ajax({
  url: siteUrl + "/_api/search/query?querytext='" + searchQuery + "'",
  type: "GET",
  headers: {
    "Authorization": "Bearer " + accessToken
  },
  success: function (data) {
    // Process the search results (data.d.query.PrimaryQueryResult.RelevantResults)
  },
  error: function (error) {
    // Handle errors
  }
});
1
  • Thanks, It's working. Commented Jul 31, 2023 at 8:59

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.