Unable to figure out how to request the Bing API / Azure Marketplace

How the hell are you using the Bing API (now the Azure Marketplace API)? Does it only support support? Can anyone show me an example on how to authenticate? The documentation is silent and after an hour of frustration I am posting a question here.

Here is the end point I'm trying to push:

https://api.datamarket.azure.com/Bing/Search/v1/Composite?query=sushi&sources=web

This throws up Basic Auth; if i cancel i get an error saying only Basic and oAuth are supported.

However, no combination of username and password known to my account works for Basic, and I cannot find an example using oAuth. I have an account, I signed up for the free tier.

+3


source to share


1 answer


After doing more research and experimentation, I was able to figure it out. The examples confused me (I think they contain a lot of context about Azure SOAPy over REST conventions, such as case sensitivity and quoted strings). Perhaps they will confuse others, so I am posting my answer here:



function searchBing() {
    var request=require('request');
    var url="https://api.datamarket.azure.com/Bing/Search/v1/Web?Query='sushi'&$format=JSON";
    var key="[your account key]";
    request.get(url, {auth: { user: key, password: key} }, function (error, result) {
        console.log(error, result.body);
    })
}

      

+2


source







All Articles