Bing News Search API is returning 5xx error when passing "freshness" parameter

Ajit Kumar 0 Reputation points
2023-09-08T12:40:18.9966667+00:00

I'm trying to fetch the top 10 news based on a query and a specific date range using the code below. However, querying freshness for a specific date is causing a 5xx error to occur:

endpoint = "https://api.bing.microsoft.com/v7.0/news/search"

headers = { 'Ocp-Apim-Subscription-Key': subscription_key }

def get_news(query, date_range, mkt="en-IN",count=10):

    # Query term(s) to search for. 

    # Construct a request

    params = { 
        'q': query, 
        'mkt': mkt,
        "count": 1,
        "freshness": "2023-08-01", ## error
        "setLang": "en-US",
        "safeSearch": "Off",
        "category": "Business",
        
    }

    # Call the API
    response = requests.get(endpoint, headers=headers, params=params)
    return response
Bing News Search
Bing News Search
A Bing service that supports searching for news and get comprehensive results.
50 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. romungi-MSFT 47,016 Reputation points Microsoft Employee
    2023-09-12T07:48:30.1866667+00:00

    @Ajit Kumar The parameter freshness takes the values of Day, Week and Month. In this case you are using the date instead of these three parameters. Please see reference page. Try using any of these and check if it works. I used the same code with these parameters and printed the response JSON. Thanks!!

    User's image

    If this answers your query, do click Accept Answer and Yes for was this answer helpful. And, if you have any further query do let us know.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.