2016 has arrived and everyone is busy in knowing the poll results. These polls have their shortcomings however they are widely used to make predictions on most of the things that are related to elections or public policy.

With the Adwords Scripts, there are several things that one must do but where one falls is not sure. Let’s develop a way to boost political polling data in the Adwords Campaign. Here, we will see some more generic techniques and pitfalls of developing wrappers for external API calls.

These will keep the code clean just to mention that it will be easy to share and use. So, if you never manage to utilize political data in your campaigns then you will easily be able to apply these techniques to external data API which is necessary for business.

The API that we will use here to find the data is Huffpost Pollster API. The set of free web services will offer the latest political polling data so that it can be incorporated in our scripts.

Know about the Candidates:

One of the main advantages of Adwords Scripts is the ability to make calls to external data sources with the use of URLFetchApp. This feature is to be used to get the data from various APIs like as Weather underground, SalesForce and Twilio.

Each of these offers API in the form of a definite set of URLs that can be called to request the data or perform actions. At times, these URLs are referred to as endpoints. When you visit Google or Amazon, this means you are making request to those URLs and then sending back the page for the browser to display.

Adwords Campaigns to Call APIs

In case of such APIs, the same thing is done i.e. data is being returned in a complete format in such a way that our Adwords Scripts can easily work with. Here, API Wrapper plays an important role.

This Wrapper is simply a piece of reusable code that one can write to interact with an API that is easier on you than others. One perfect way to think about this is to imagine handling your wrapper code to someone else to use.

How to Create an API Wrapper?

The process begins with a set of separate functions that relate to the same API. This Pollster API is very straightforward and hence it contains one endpoint with three methods viz. Charts, chart and Polls method.

First of all, a request URL is to be developed based on the parameters accepted by the method. Then a request is made to that URL with the use of URLFetchApp.fetch() and then the parsed response is available.

Irrespective of the error checking, the function does its job for the Charts method. Once the Charts method is finished then comes the Chart method with the similar steps. It’s a good place to start with by copying the first method and make some updates which will then be as follows:

// Call the Pollster API Chart Method

// http://elections.huffingtonpost.com/pollster/api#chart

function getChart(slug) {

var url = "http://elections.huffingtonpost.com/pollster/api/charts/"+slug+".json";

var resp = UrlFetchApp.fetch(url);

The main purpose of this wrapper is to make the application code easy so that it becomes simple to call the data from the API. We all know that all the parameters are optional and it is not easy to call the getPolls API.

Now, to ease this issue; one can pass the configuration object which contains original arguments as its properties. This sounds really confusing and once has probably seen it before realizing it.

The config objects will be sent to getCharts and getPolls function. The processing of these objects in a separate function is called buildQuery String which makes the code a little cleaner.

The multipliers are to be developed by Popularity:

The new wrapper allows to get current polling data for each candidate as soon as it is available on Pollster API. Once the API is explored then there are few things that one must think about before using the data in a campaign.

The first one is the data source. Various sources have various polling methods, biases and questions. One can make sure of the most recent data. It takes time for Polls to run and hence they are not as frequent as other data sources.

Take Away:

So, following this complete process; one can develop a complete API wrapper which can be reused in different scripts and then it can be shared with anyone. One can learn about it when group code is available and one knows how to re-factor the code to make it easier to use.

Hope this blog post will be useful for you. For more such details and updates stay connected with Platinum SEO ; a well known Melbourne Adwords management company offering affordable Google Adwords services.