Query parameters for V7 News API doesn't work

newbie_user 21 Reputation points
2021-01-03T04:43:59.793+00:00

Hi,
I am trying these two commands:

  1. curl -H "Ocp-Apim-Subscription-Key: <subscription_key>" https://api.bing.microsoft.com/v7.0/news/search?q=sailing&count=5&offset=40&mkt=en-us
  2. curl -H "Ocp-Apim-Subscription-Key: <subscription_key>" https://api.bing.microsoft.com/v7.0/news/search?q=sailing&count=100&offset=40&mkt=en-us

You can see that count is different in both of the commands. However, I get the exact same result back (total count = 10) in case of both queries.

In a similar way, if I try to provide category, it doesn't take into account:
Sample query: curl -H "Ocp-Apim-Subscription-Key: <subscription_key>" https://api.bing.microsoft.com/v7.0/news?mkt=en-us&category=sports

(This category query also returns the latest news from all the categories rather than just sports).

Bing News Search
Bing News Search
A Bing service that supports searching for news and get comprehensive results.
43 questions
0 comments No comments
{count} votes

Accepted answer
  1. romungi-MSFT 42,286 Reputation points Microsoft Employee
    2021-01-04T12:58:11.967+00:00

    @newbie_user The behavior indicates that your query is not picking up count query parameter. Instead, it is returning the default of 10 results every time you query. You can verify this by using a more detailed curl command with option "-v". If you use the below command with the URI in quotes the query should return the required count as the complete list of parameters will be used.

    curl -v -X GET "https://api.bing.microsoft.com/v7.0/news/search?q=sailing&count=2&offset=40&mkt=en-us" -H "Ocp-Apim-Subscription-Key: <subscription_key>"  
    

    From the output:

    > GET /v7.0/news/search?q=sailing&count=2&offset=40&mkt=en-us HTTP/1.1  
    > Host: api.bing.microsoft.com  
    > User-Agent: curl/7.55.1  
    > Accept: */*  
    > Ocp-Apim-Subscription-Key: <subscription_key>  
    

    In the second scenario also i believe this is the case where your first parameter is only considered i.e mkt. Please try to use the query in the above format or just use the query parameter category and you should see the results.

     https://api.bing.microsoft.com/v7.0/news?category=sports  
    

    I have also tried to use the sub categories for sports for en-US and it works fine. Here is a sample query URI.

     https://api.bing.microsoft.com/v7.0/news?category=sports_NBA&mkt=en-US  
    

0 additional answers

Sort by: Most helpful