Search code examples
bingbing-searchbing-news-search-api

400 error with bing news search api


I'm having a couple of problems with the bing news search api, the strangest one is searching by category, according to the documentation, the category must be a string, I found multiple resources for which values it accepts so i decided to go with console (https://dev.cognitive.microsoft.com/docs/services/56b43f72cf5ff8098cef380a/operations/56b449fbcf5ff81038d15cdf/console). Once you select a category and put it your key, it works fine. The problem is when i copy the exact same URL from the console to postman, i use the same key and i get "400 Bad Request" header with this body:

{
  "_type": "ErrorResponse",
  "errors": [
    {
      "code": "RequestParameterInvalidValue",
      "message": "Parameter has invalid value.The category parameter is invalid.",
      "parameter": "category",
      "value": "Entertainment"
    }
  ]
}

any idea what i'm doing wrong here?


Solution

  • Here's a very Hacky workaround: since the request works fine via the developer console, i inspected the request and tried to repeate it thought curl, seems to work fine, the command is as follows:

    curl 'https://dev.cognitive.microsoft.com/console/query'  -H 'Content-Type: application/json' --data-binary '{"httpMethod":"GET","host":"api.cognitive.microsoft.com","scheme":"https","path":"bing/v5.0/news/?Category=Entertainment","headers":[{"name":"Host","value":"api.cognitive.microsoft.com","inputTypeValue":"text","revealed":false,"options":null,"required":true,"readonly":true,"custom":false},{"name":"Ocp-Apim-Subscription-Key","value":"<your key value>","inputTypeValue":"password","revealed":false,"options":[],"required":true,"readonly":false,"custom":true,"secret":true}],"parameters":[{"name":"Category","value":"Entertainment","inputType":"text","required":false,"options":["Business","Entertainment","Health","Politics","ScienceAndTechnology","Sports","US/UK","World"],"custom":false,"description":"<p>Specifies which category of news articles the caller wants returned.</p>\n","typeName":"string"}],"body":""}'
    

    The json data I'm sending is this (copied from the command above)

    { "httpMethod": "GET", "host": "api.cognitive.microsoft.com", "scheme": "https", "path": "bing/v5.0/news/?Category=Entertainment", "headers": [{ "name": "Host", "value": "api.cognitive.microsoft.com", "inputTypeValue": "text", "revealed": false, "options": null, "required": true, "readonly": true, "custom": false }, { "name": "Ocp-Apim-Subscription-Key", "value": "", "inputTypeValue": "password", "revealed": false, "options": [], "required": true, "readonly": false, "custom": true, "secret": true }], "parameters": [{ "name": "Category", "value": "Entertainment", "inputType": "text", "required": false, "options": ["Business", "Entertainment", "Health", "Politics", "ScienceAndTechnology", "Sports", "US/UK", "World"], "custom": false, "description": "

    Specifies which category of news articles the caller wants returned.

    \n", "typeName": "string" }], "body": "" }

    I'll mark this as correct for now since i can't find any other solution