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

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.