Calling Google DFP API with SSIS – DoubleClick

 Introduction

Google DoubleClick is one of the most popular platforms for Advertisers. Many times you have need for custom integration or Automation for many operations. In this article we will learn how to Call Google DFP API (i.e. DoubleClick for Publishers) without coding using SSIS (Microsoft SQL Server Integration Services). In our previous article we discussed how to Integrate Google AdWords API using SSIS (Click here).

If you are new to SSIS then no worry there are plenty of tutorials for ssis

To achieve Custom integration for DoubleClick (DFP) API we will use SSIS XML Source. XML Source is part of SSIS PowerPack which has 45+ connectors and Tasks.

Prerequisite

Before you can finish tasks explained in this article you have to finish below steps. This article assumes you have basic knowledge of SSIS (SQL Server Integration Services)

  1. Make sure you SSIS designer installed. Sometimes its referred as BIDS or SSDT (Get from here)
  2. Download SSIS PowerPack

Download DFP API Example SSIS Package

Click here to DFP API download Sample for SSIS SSIS Package (SSIS 2012, 2014, 2016)

Screenshot of Sample Package:

Example SSIS Package - Google DFP API Integration (Read / Write data in Google Double Click for Publisher) - No Coding required

Example SSIS Package – Google DFP API Integration (Read / Write data in Google Double Click for Publisher) – No Coding required

Making your first DFP API Call using SSIS

Once you install PowerPack you are ready to execute your very first Google DFP API Call.

NOTE: If you don’t have any DFP network for test then see next section (Explains how to create test network for testing).

Lets look at how to call Google DFP API step-by-step.

  1. Create new SSIS Project and open package designer
  2. Drag ZS REST API Task from SSIS control flow toolbox and drop it on designer.
    REST API Task is useful when you want to call SOAP/REST API but not necessarily parse response into rows and columns. We will look at JSON Source later in this article which can actually parse response into rows and columns (Useful to load Google DFP data into SQL Server or other RDBMS / flatfile )
  3. Double click REST API Task to configure. Select Access mode to [Url from Connection]
  4. Enter following URL in the URL Textbox
  5. From the connection dialogbox select ZS-OAUTH to create new OAuth Connection for DFP API
  6. On OAuth Connection dialogbox select Google from Provider dropdown. In this demo we will use Default OAuth App but you can register your own google OAuth app if you wish to use Custom OAuth option from UI.
  7. Enter following Scope in the Scopes textbox (or select manually by clicking Select Scopes button). Scope is nothing but permission for API (In our case View/Manage DFP data).
  8. Click Generate Token button. You will see browser popup for login and then Accept option to confirm permissions like below. Once you don’t it will populate tokens and prompt to save tokens to backup file. Secure token backup to safe place.
    SSIS OAuth Connection - Connect to Google DFP API (DoubleClick SOAP Web Service)

    SSIS OAuth Connection – Connect to Google DFP API (DoubleClick SOAP Web Service)

  9. Once done Click Test Connection and if its green then Click OK to save connection
  10. Once you are back to REST API Task UI then select Method to POST
  11. Select Request Body Content Type to XML (i.e. text/xml)
  12. Click edit button next to Request Body and enter following XML.

    If you are wondering how did we get above XML fragment then read next section about using 3rd party tool called SoapUI. Also we have detail article for calling SOAP request. Check this article on how to use SoapUI (free 3rd party tool) to create SOAP request Bodyfrom WSDL. DFP has many API endpoints for different actions (e.g. NetworkService , InventoryService , …). For each service you have different Api URL and different WSDL. In the next section you can learn how to create correct SOAP Body (for POST) using SoapUI tool.

    For example if you using DFP NetworkService API for version v201702 then your help page URL would be like this
    https://developers.google.com/doubleclick-publishers/docs/reference/v201702/NetworkService
    And on the same page you will see WSDL link below
    https://adwords.google.com/api/adwords/mcm/v201609/ManagedCustomerService?wsdl
    (Just download that WSDL XML and save to local disk then use with SoapUI to generate XML body to submit for any DFP API call.)

  13. Once you done with above steps, your Task Configuration will look like below.
    SSIS Rest API Task - Call Google DoubleClick API - Get all DFP Networks

    SSIS Rest API Task – Call Google DoubleClick API – Get all DFP Networks

  14. Now click Test Request button. You will see Response popup with below content if its successful (Scroll at the bottom on response form and you will see XML data) .. see below
     

How to generate SOAP Request Body using SoapUI tool

This section describes how to create DoubleClick SOAP API Request Body (XML fragment) for any DFP SOAP API call described anywhere in this article.

  1. Download SoapUI (Its free third party tool to test SOAP API). SoapUI can help you to generate XML Request BODY easily from WSDL file provided by API Vendor. You can also test your service by supplying parameters.
  2. Now download WDSL xml for appropriate API calls you want to make. Assume that you want to call  getAllNetworksResponse API found under NetworkService. For that first navigate to help file page and open help page. Make sure you select correct version from help navigation. Copy WSDL link and open in new browser window. Save XML to local disk (e.g. c:\api\dfp_networkservice_wsdl.xml (See below screenshot how to find DFP API WSDL link)
    How to get Google DFP API WSDL URL (Used to generate POST Body)

    How to get Google DFP API WSDL URL (Used to generate POST Body)

  3. Once SoapUI is downloaded and installed click File menu > Create New SOAP Project option
  4. Name your project (e.g. DFP API) and specify WSDL URL or File Path if it was saved locally (e.g. c:\api\dfp_networkservice_wsdl.xml) and click OK
  5. Now navigate to API Action for which you would like to get Body. Click Request node (If missing create new) and edit request. You may see XML like below (If some optional parameters not visible in XML then click Re-create request with optional parameters button from toolbar)
    Call Google DFP API - Generate SOAP Request Body XML using SoapUI (Google DoubleClick Web Service)

    Call Google DFP API – Generate SOAP Request Body XML using SoapUI (Google DoubleClick Web Service)

  6. Edit necessary parameters from above XML code and copy to Body of SSIS REST API Task.

Creating test network – DFP Sandbox

Very first step we recommend before testing DFP API call is create test network. You can call DFP API against LIVE network but not recommended if you are calling create/update API.

To create test network you can follow exact same steps described in the previous section except the Body step (Step#12). Use following Request body to call makeTestNetwork command.

API makeTestNetwork – Request

URL: https://ads.google.com/apis/ads/publisher/v201702/NetworkService
Body (see below):

Once you click Test you may receive following response. Note your network code (e.g. 1122334455 from below). This network code is used in pretty much all DFP API to view or manage ad network related items or properties.

API makeTestNetwork – Response

Above response contains test networkcode copy that code becuase you will need in almost every API call you make later. You can only have one test network. If test network is already created and you try to execute above code then you may receive error  AuthenticationError.GOOGLE_ACCOUNT_ALREADY_ASSOCIATED_WITH_NETWORK

You can also get network code using two different ways.

  • Visit your DFP console homepage by visiting https://www.google.com/dfp/ and you will see network name and code in the top potion. Also its listed in the URL (e.g. https://www.google.com/dfp/1234567)
  • Another way to get available networks for your login is to visit DFP API Play ground here https://dfp-playground.appspot.com/ and you will see network list in the dropdown ( name and network code)

How to Create new Ad Units

Now lets look at an example which will create few Ad Units by calling createAdUnits API. If you are creating Ad Unit at the root level then you will need to specify correct Parent ID (i.e  effectiveRootAdUnitId). To obtain that Parent ID you may have to call  getCurrentNetwork API. In the response you will see effectiveRootAdUnitId.

There is another way to know effectiveRootAdUnitId or Id of any Ad Units which can be Parent for new AdUnit. Goto google.com/dfp > Click Inventory Tab > Click Ad Units Side menu > Click Download ad units hyper link. You can also download AdUnits as CSV file from DFP Portal and look for Ad Units which are created at the root. Parent ID column for Root level Ad Units is basically called effectiveRootAdUnitId.

Now lets look at how to get EffectiveRootID by calling getCurrentNetwork.

API getCurrentNetwork – Request

URL: https://ads.google.com/apis/ads/publisher/v201702/NetworkService
Body (see below):

 

API getCurrentNetwork – Response

 

If you want to save single Element Value from Response into SSIS Variable then perform following steps (example of how to get just effectiveRootAdUnitId from above response)

  1. On REST API Task > Go to Response Tab > Select Response Content Type = XML
  2. Enter following expression in the XPath filter
  3. Check Save response content option
  4. Select Variable from Dropdown – Click New Variable > Name it RootAdUnitId.
  5. Click Test Request Button to test…. In the content textbox you will now see only Numeric value extracted by Filter
SSIS REST Api Task - How to extract single vale from response and save to SSIS variable

SSIS REST Api Task – How to extract single vale from response and save to SSIS variable

Once you know Parent ID for your AdUnit now lets look at how to create Ad Units by calling createAdUnits

API createAdUnits – Request

URL: https://ads.google.com/apis/ads/publisher/v201702/InventoryService
Body (see below):

API createAdUnits – Response

Loading Google DoubleClick data into SQL Server Table

So far we saw how to make simple DFP API calls without doing any parsing. Now lets look at how to use SSIS XML Source which not only make API calls but it will parse XML Response into rows and columns which can be loaded into target database such as SQL Server, Oracle, MySQL or even Flat File. XML Source also supports pagination so if you have many records it will automatically loop through all response untill all records are fetched.

Step-By-Step – Using XML Source to read Google DFP data (Parse into rows and columns)

  1. Assuming you have tested your first DFP API Call (Explianed in the beginning of this article). You must have OAuth connection tested for API call.
  2. Drag new Data flow task from SSIS Toolbox
  3. Inside Data flow designer drag and drop ZS XML Source from toolbox
  4. Double click XML Source to configure.
  5. Set URL as below
    https://ads.google.com/apis/ads/publisher/v201702/InventoryService
  6. Check Use credentials option and from Drop down select OAuth connection manager (created in previous section)
  7. Select Method = POST,
  8. Select Request Content Type = XML (text/xml)
  9. Enter Body as below (Click edit button).
    Notice that in above we calling getAdUnitsByStatement API to fetch all Ad Units which are Active. Here is more information about Query Syntax for any API call getXXXXXXByStaement
  10. Now click on Select Filter button and select results node and click OK. If prompted add array to list.
    SSIS XML Source - Get data from Google DFP API   using OAuth (Configure URL, Body and Filter)

    SSIS XML Source – Get data from Google DFP API using OAuth (Configure URL, Body and Filter)

  11. Click Preview to see data. Click Columns tab to review data types (Auto detected). If you wish to change length or datatype then edit there and check Lock option (Last column)
    SSIS XML Source - Preview Response for Google DoubleClick API Call - Parse into Rows/Columns

    SSIS XML Source – Preview Response for Google DoubleClick API Call – Parse into Rows/Columns

  12. Click OK to save UI
  13. Connect XML Source to same target (e.g. OLEDB Destination – SQL Server Connection)
  14. Run data flow
    SSIS Execution - Read from Google DFP and load into SQL Server Table

    SSIS Execution – Read from Google DFP and load into SQL Server Table

Configure Pagination for Google DFP API / PQL Query result

If you have large dataset to read from DoubleClick API ( when calling API such as getxxxxxxByStatement) then we recommend to supply LIMIT and OFFSET clause in your PQL query.

For example if you have 2000 ad units and you want to limit response size by maximum 300 rows then your query can be like below

This looping logic can be complex to implement if you do manually. But no worry if you are using SSIS XML Source. It comes with many pagination options (Click here to read more about pagination)

See below screenshot how to configure Pagination options for Google DoubleClick API. Basically two places you have to change. Inside body you have to set placeholder and change few settings on Pagination Tab.

SSIS XML Source - Configure Pagination for Google DoubleClick API data fetch - PQL LIMIT and OFFSET clause for Google DFP API

SSIS XML Source – Configure Pagination for Google DoubleClick API data fetch – PQL LIMIT and OFFSET clause for Google DFP API

SSIS XML Source - Configure Pagination for Google DoubleClick API data fetch - Set Pagination Mode

SSIS XML Source – Configure Pagination for Google DoubleClick API data fetch – Set Pagination Mode

Making things dynamic

If you want to supply certain parameters at runtime (e.g. from SSIS Variable) rather than hard code then you can use Variable Placeholders any where in Request Body, URL or Headers. Click Insert Variable option found in Edit screen

Here is an example of dynamic URL (API Version stored in SSIS Variable)

Deploy to Production

When you ready to deploy your SSIS Package to production make sure to change Test NetworkCode supplied inside Request Body to your Production Ad Network. Also Set RefreshToken Property of OAuth Connection Manager (Get it from Backup file saved when you created OAuth connection first time). Once you set RefreshToken of connection manager you wont have to Login again to get new token.

Conclusion

Traditionally if you wanted to integrate Google DFP API (DoubleClick API) calls inside your ETL workflow then it required some sort of coding effort (e.g. Use C# SDK, JAVA SDK or Python SDK). Coding effort is not only time consuming and expensive but also hard to maintain for any non-coder (e.g. ETL Developer or DBA).
Thanks to SSIS PowerPack which changed the way developers do API integration. Now you can reduce time to implement and total cost of you API integration project significantly by using drag and drop approach. This approach is not only easy to maintain but also fast and high quality. You can use ZappySys REST/SOAP SSIS Connectors and SSIS Tasks for any API integration project such as Google DFP API. Try SSIS PowerPack for free to explore possibilities. If you have any issue with your integration Contact Support

Posted in Google API and tagged , , , , , , , , , , , .