Search code examples
javascriptazurecorsazure-cognitive-search

Get Index Azure Search Fails 'Response for preflight has invalid HTTP status code 403'


I previously posted this question on how to pull the index schema from azure search.

I was able to pull an index schema by using the GET Index REST API using Postman with no problems, but when running my code in a browser I get the error:

XMLHttpRequest cannot load https://[service name].search.windows.net/indexes/[index name]?api-version=[api-version] Response for preflight has invalid HTTP status code 403

I'm just running the following code in the console:

$.ajax({ url: 'https://[service name].search.windows.net/indexes/[index name]?api-version=[api-version]', type: 'GET', datatype: 'json', headers: {'api-key': [api-key]}})

However, this code works fine (returns all data-- the only difference is /docs):

$.ajax({ url: 'https://[service name].search.windows.net/indexes/[index name]/docs?api-version=[api-version]', type: 'GET', datatype: 'json', headers: {'api-key': [api-key]}})

The other weird thing is that the request headers for the GET Index Request doesn't show the API key.

It seems like CORS (which is setup on Azure Search to '*'), doesn't like the request from a browser for the GET Index?

Any help would be welcome.


Solution

  • Azure Search does not support admin-level operations like Get Index in CORS requests. See this related answer.