Azure Custom Search gives error 404

Bill Oxbury 6 Reputation points
2022-04-05T08:52:23.77+00:00

I'm having trouble getting custom search (CS) to work (previously been using Google's CS with no problem).
What I did (following the documentation which generally is excellent on Azure):

  1. created Bing CS resource and got key (2 provided)
  2. created Bing instance with a few domains my search aims to cover, published, copied custom config ID
  3. went back to the CS resource page and copied the sample code (for Python) as below.
  4. Ran this code in a local Jupyter notebook, using the subscription key and custom cofig ID above.

I get error 404 'resource not found', and haven't been able to figure out what needs to change in the url string...

Any help much appreciated!!

/******************************************************************************/
PYTHON CODE

import json
import os
from pprint import pprint
import requests

subscriptionKey = 'BING_CUSTOM_SEARCH_SUBSCRIPTION_KEY'
endpoint = https://api.bing.microsoft.com # as specified for me on CS resource page
customConfigId = "BING_CUSTOM_CONFIG"
searchTerm = "microsoft"

url = endpoint + "/bingcustomsearch/v7.0/search?q=" + searchTerm + "&customconfig=" + customConfigId

r = requests.get(url, headers={'Ocp-Apim-Subscription-Key': subscriptionKey})
pprint(json.loads(r.text))

Bing Custom Search
Bing Custom Search
An easy-to-use, ad-free, commercial-grade search tool that lets you deliver the results you want.
78 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Bill Oxbury 6 Reputation points
    2022-04-05T09:50:30.56+00:00

    Resolved :)

    The tutorial code appears to have an error:

    url = endpoint + "/bingcustomsearch/v7.0/search?q=" + searchTerm + "&customconfig=" + customConfigId

    should be replaced by:

    url = endpoint + "/v7.0/custom/search?" + "q=" + searchTerm + "&customconfig=" + customConfigId

    1 person found this answer helpful.
    0 comments No comments

  2. Littlestar Gao 0 Reputation points Microsoft Employee
    2024-01-30T07:52:24.43+00:00

    customConfigId should be 2 not 1. I found that

    0 comments No comments