Hello Readers,

In Today’s Blog post we’ll talk about the Bing API and how Bing Search Auto complete data can be fetched using PowerShell.

I was playing around with Web Debugger Tool (Fiddler) and while doing a Bing search I noticed my Browser making HTTP request to Bing API URL.

Well API’s are always fun, so why not try and explore it with PowerShell 😉

HOW IT WORKS :

Before we proceed further time for some definitions 🙂 so that all have same understanding –

API – Application Programming Interface is a set of functions and procedures that allow the creation of applications which access the features or data of an operating system, application, or other service.

REST – REST stands for Representational State Transfer. (It is sometimes spelled “ReST“.) It relies on a stateless, client-server, cacheable communications protocol and in virtually all cases, the HTTP protocol is used. REST is an architecture style for designing networked applications.

API’s which return Richly Structured data are called RESTFull API’s.

So, making it work is 3 step process :

Make your Custom Query URL – Like Fiddler Logs in the above screenshot, we’ll create a URL with a Custom Query string, something like below –URL : http://api.bing.com/qsml.aspx?query=WordWhen you type this URL in a browser address bar and hit enter, you’ll see a structured data returned (XML Data).





Send HTTP request to Bing API –

Using the PoweShell Invoke-RestMethod Cmdlet sending an HTTP request on URL mentioned in Step 1. Function Auto-Complete() { Return (Invoke-RestMethod -Uri "http://api.bing.com/qsml.aspx?query=$($TextBox1.text)").searchsuggestion.section.item.text } Data Mine the Structured Data returned – Capture the useful information from the Structured data returned from the API and feed it to your GUI.

GRAB THE SCRIPT :

https://gist.github.com/PrateekKumarSingh/cbcac3a41450811044f9#file-auto-complete-ps1

HOW TO USE IT :

Run the Script and type in your query in the TextBox. Form is intelligent enough to give you suggestions the moment you stop typing, like in the below animation



Hoping you find it fun.

Happy Reading 🙂

Prateek Singh

Follow @SinghPrateik