Google Ads Connector for C#

In this article you will learn how to quickly and efficiently integrate Google Ads data in C#. We will use high-performance Google Ads Connector to easily connect to Google Ads and then access the data inside C#.

Read / write Google Ads data inside your app (e.g. Campaigns, Ad Groups, Keywords, Spending, Performance); perform many Google Ads operations without coding, just using easy to use high performance API Connector for Google Ads

Let's follow the steps below to see how we can accomplish that!

Download Documentation

Create ODBC Data Source (DSN) based on ZappySys API Driver

Step-by-step instructions

To get data from Google Ads using C# we first need to create a DSN (Data Source) which will access data from Google Ads. We will later be able to read data using C#. Perform these steps:

  1. Install ZappySys ODBC PowerPack.

  2. Open ODBC Data Sources (x64):

    Open ODBC Data Source
  3. Create a User data source (User DSN) based on ZappySys API Driver

    ZappySys API Driver
    Create new User DSN for ZappySys API Driver
    • Create and use User DSN if the client application is run under a User Account. This is an ideal option in design-time, when developing a solution, e.g. in Visual Studio 2019. Use it for both type of applications - 64-bit and 32-bit.
    • Create and use System DSN if the client application is launched under a System Account, e.g. as a Windows Service. Usually, this is an ideal option to use in a production environment. Use ODBC Data Source Administrator (32-bit), instead of 64-bit version, if Windows Service is a 32-bit application.
  4. When the Configuration window appears give your data source a name if you haven't done that already, then select "Google Ads" from the list of Popular Connectors. If "Google Ads" is not present in the list, then click "Search Online" and download it. Then set the path to the location where you downloaded it. Finally, click Continue >> to proceed with configuring the DSN:

    GoogleAdsDSN
    Google Ads
    ODBC DSN Template Selection

  5. Now it's time to configure the Connection Manager. Select Authentication Type, e.g. Token Authentication. Then select API Base URL (in most cases, the default one is the right one). More info is available in the Authentication section.

    User accounts represent a developer, administrator, or any other person who interacts with Google APIs and services. User accounts are managed as Google Accounts, either with Google Workspace or Cloud Identity. They can also be user accounts that are managed by a third-party identity provider and federated with Workforce Identity Federation. [API reference]

    Steps how to get and use Google Ads credentials

    Follow these steps on how to create Client Credentials (User Account principle) to authenticate and access Google Ads API in SSIS package or ODBC data source:

    WARNING: If you are planning to automate processes, we recommend that you use a Service Account authentication method. In case, you still need to use User Account, then make sure you use a system/generic account (e.g. automation@my-company.com). When you use a personal account which is tied to a specific employee profile and that employee leaves the company, the token may become invalid and any automated processes using that token will start to fail.

    Manager Account Setup - Obtain Developer Token

    To access Google Ads API (your data or someone else data) you must perform the following steps (high level). Detailed steps listed in the next sections.

    1. Create a Google Ads Manager account (formally known as MCC).
    2. Apply for Production data access (Upgrade Developer Token access Level to Basic).
    3. Link manager account with Google Ads Account.
    4. Create a new Project and obtain Client Id and Client Secret

    Step-1: Create a Google Ads Manager account (formally known as MCC)

    Very first step to access Google Ads API for your own account or someone else account, you will need something called Google Manager Account (formally known as MCC). It will look like a Normal Google Ads Account with some difference so dont get confused if you see similar interface as Ads account.
    Click here to see detailed instructions on how to create a manager account. Once you created a manager account, you can login or switch between Ads account and Manager account like below. You can identify manager account using "Manager" word next to the account id when you click Profile dropdown. Login as Google Ads Account Manager (formally known as MCC)

    Step-2: Obtain Developer Token

    Once you have created and logged in to your Google Ads Manager Account (formally known as MCC) we are ready for the next step which is obtain Developer Token. To access Google Ads API you need to pass developer token in each API call. By default Developer Token is only allowed to access Sandbox (Test) account. If you like to access Production data (Live Ads Account) then you must apply for Basic Access by clicking link under Access Level (See next section for information).
    Here is how to can obtain your Developer Token.

    • Log in as Manager account (Or change Top-Right Profile > Choose Manager account ID
    • Click on Admin icon
    • Click on API Center (This option will be missing if you are logged in to Regular Ads account as Client and not using Manager Account (MMC)
    • Expand Access Level, Click Apply for Basic Access if it says "Test". By default Developer Token is created with Test Account access only. To access Production Ads account you must apply for higher access level. Must be Basic or Standard (not Test). After click the link you will see form with few questions, please fill out that and submit the form. Apploval process may take 3-5 days (or longer in some cases if you did not provide enough information).
    • If your token is already approved for the basic access then copy the token and paste on the Google Ads Connector - Connection UI (For Developer Token property)
    Click here to see detailed instructions on obtaining a developer token
    Developer Token for Google Ads API Access in API Center (Visible when logged in as Manager Account)

    Link Manager Account to Google Ads Account

    After you have manager account ready, next step is to link manager account with Google Ads Account. You have to send invitation from Manager account to access Google Ads account (it can be your own account or someone else). Here is how to send invite to link Google Ads account.
    • Log in as Manager account (Or change Top-Right Profile > Choose Manager account ID
    • Click on Accounts icon > Sub-account settings > Send Link Request
    • Click on Add Sign (+) and select + Link existing account option
    • When prompted enter Account Id(s) you like to link with this Manager Account. Link Google Manager Account with Ads Account
    • Click Send Request. You can find Ad Account Id usually at the Top-Right corner after you login to the Google Ads account. Send Invitation to link Google Manager Account with Ads Account
    • Now ask Google Ads Account owner to check email. Click Accept Invitation link in the email (If prompted login as Google Ads Account owner).
      -OR-
      Another way to see Invitation, Login to Google Ads account (Or Switch from the Top-Right corner by clicking Profile icon). Go to Admin icon > Access and security > Managers Tab. Find the pending invitation and click ACCEPT. Accept Manager account to Google Ads Account link invitation
    • That's it. Now your Manager account is linked to the Google Ads account

    Obtain ClientId and ClientSecret

    Step-1: Create project

    This step is optional, if you already have a project in Google Cloud and can use it. However, if you don't, proceed with these simple steps to create one:

    1. First of all, go to Google API Console.

    2. Then click Select a project button and then click NEW PROJECT button:

      Start creating a new project in Google Cloud
    3. Name your project and click CREATE button:

      Create a new project in Google Cloud
    4. Wait until the project is created:

      Wait until project is created in Google Cloud
    5. Done! Let's proceed to the next step.

    Step-2: Enable Google Ads API

    In this step we will enable Google Ads API:

    1. Select your project on the top bar:

      Select project in Google Cloud
    2. Then click the "hamburger" icon on the top left and access APIs & Services:

      Access APIs and services in Google Cloud
    3. Now let's enable several APIs by clicking ENABLE APIS AND SERVICES button:

      Enable API for project in Google Cloud
    4. In the search bar search for Ads and then locate and select Google Ads API:

      Search for API in Google Cloud
    5. Enable Google Ads API:

      Enable Google Ads API
    6. Done! Let's proceed to the next step.

    Step-3: Create OAuth application

    1. First of all, click the "hamburger" icon on the top left and then hit VIEW ALL PRODUCTS:

      View all products in Google Cloud
    2. Then access Google Auth Platform to start creating an OAuth application:

      Open Google Auth Platform in Google Cloud
    3. Start by pressing GET STARTED button:

      Start creating an app in Google Cloud
    4. Next, continue by filling in App name and User support email fields:

      Fill app info in Google Cloud
    5. Choose Internal option, if it's enabled, otherwise select External:

      Choose app audience in Google Cloud
    6. Optional step if you used Internal option in the previous step. Nevertheless, if you had to use External option, then click ADD USERS to add a user:

      Add test user in Google Cloud app
    7. Then add your contact Email address:

      Enter app contact info in Google Cloud
    8. Finally, check the checkbox and click CREATE button:

      Create app in Google Cloud
    9. Done! Let's create Client Credentials in the next step.

    Step-4: Create Client Credentials

    1. In Google Auth Platform, select Clients menu item and click CREATE CLIENT button:

      Start creating app client in Google Cloud
    2. Choose Desktop app as Application type and name your credentials:

      Create OAuth app client in Google Cloud
    3. Continue by opening the created credentials:

      View app client credentials in Google Cloud
    4. Finally, copy Client ID and Client secret for the later step:

      Use client ID and secret to read Google REST API data
    5. Done! We have all the data needed for authentication, let's proceed to the last step!

    Step-5: Configure connection

    1. Now go to SSIS package or ODBC data source and use previously copied values in User Account authentication configuration:

      • In the ClientId field paste the Client ID value.
      • In the ClientSecret field paste the Client secret value.
      • In the DeveloperToken field paste the Developer Token value.
    2. Press Generate Token button to generate Access and Refresh Tokens.

    3. Finally, click Test Connection to confirm the connection is working.

    4. Done! Now you are ready to use Google Ads Connector!

    Fill in all required parameters and set optional parameters if needed:

    GoogleAdsDSN
    Google Ads
    User Account [OAuth]
    https://googleads.googleapis.com/[$ApiVersion$]
    Required Parameters
    UseCustomApp Fill-in the parameter...
    CustomerId (without dash e.g. 2125557752) Fill-in the parameter...
    DeveloperToken Fill-in the parameter...
    Optional Parameters
    ClientId
    ClientSecret
    Scope https://www.googleapis.com/auth/adwords
    Login CustomerId (without dash e.g. 2125557752)
    Linked CustomerId (without dash e.g. 2125557752)
    API Version v19
    RetryMode RetryWhenStatusCodeMatch
    RetryStatusCodeList 429
    RetryCountMax 5
    RetryMultiplyWaitTime True
    Redirect URL (Only for Web App)
    ODBC DSN Oauth Connection Configuration

    Service accounts are accounts that do not represent a human user. They provide a way to manage authentication and authorization when a human is not directly involved, such as when an application needs to access Google Cloud resources. Service accounts are managed by IAM. [API reference]

    Steps how to get and use Google Ads credentials

    To access Google Ads API (your data or someone else data) you must perform the following steps (high level). Detailed steps listed in the next sections.

    1. Create a Manager account.
    2. Apply for Production data access (Upgrade Developer Token access Level to Basic).
    3. Link manager account with Google Ads Account.
    4. Inside Manager account apply for Basic API Access level so you can use Developer Token to access Live data (Production Ads account). Without Basic access level Developer Token can be only used for Test / Sandbox Ads account.
    5. Create a new Project and obtain Client Id and Client Secret

    Manager Account Setup - Obtain Developer Token

    To access Google Ads API (your data or someone else data) you must perform the following steps (high level). Detailed steps listed in the next sections.

    1. Create a Google Ads Manager account (formally known as MCC).
    2. Apply for Production data access (Upgrade Developer Token access Level to Basic).
    3. Link manager account with Google Ads Account.
    4. Create a new Project and obtain Service Account details

    Step-1: Create a Google Ads Manager account (formally known as MCC)

    Very first step to access Google Ads API for your own account or someone else account, you will need something called Google Manager Account (formally known as MCC). It will look like a Normal Google Ads Account with some difference so dont get confused if you see similar interface as Ads account.
    Click here to see detailed instructions on how to create a manager account. Once you created a manager account, you can login or switch between Ads account and Manager account like below. You can identify manager account using "Manager" word next to the account id when you click Profile dropdown. Login as Google Ads Account Manager (formally known as MCC)

    Step-2: Obtain Developer Token

    Once you have created and logged in to your Google Ads Manager Account (formally known as MCC) we are ready for the next step which is obtain Developer Token. To access Google Ads API you need to pass developer token in each API call. By default Developer Token is only allowed to access Sandbox (Test) account. If you like to access Production data (Live Ads Account) then you must apply for Basic Access by clicking link under Access Level (See next section for information).
    Here is how to can obtain your Developer Token.

    • Log in as Manager account (Or change Top-Right Profile > Choose Manager account ID
    • Click on Admin icon
    • Click on API Center (This option will be missing if you are logged in to Regular Ads account as Client and not using Manager Account (MMC)
    • Expand Access Level, Click Apply for Basic Access if it says "Test". By default Developer Token is created with Test Account access only. To access Production Ads account you must apply for higher access level. Must be Basic or Standard (not Test). After click the link you will see form with few questions, please fill out that and submit the form. Apploval process may take 3-5 days (or longer in some cases if you did not provide enough information).
    • If your token is already approved for the basic access then copy the token and paste on the Google Ads Connector - Connection UI (For Developer Token property)
    Click here to see detailed instructions on obtaining a developer token
    Developer Token for Google Ads API Access in API Center (Visible when logged in as Manager Account)

    Link Manager Account to Google Ads Account

    After you have manager account ready, next step is to link manager account with Google Ads Account. You have to send invitation from Manager account to access Google Ads account (it can be your own account or someone else). Here is how to send invite to link Google Ads account.
    • Log in as Manager account (Or change Top-Right Profile > Choose Manager account ID
    • Click on Accounts icon > Sub-account settings > Send Link Request
    • Click on Add Sign (+) and select + Link existing account option
    • When prompted enter Account Id(s) you like to link with this Manager Account. Link Google Manager Account with Ads Account
    • Click Send Request. You can find Ad Account Id usually at the Top-Right corner after you login to the Google Ads account. Send Invitation to link Google Manager Account with Ads Account
    • Now ask Google Ads Account owner to check email. Click Accept Invitation link in the email (If prompted login as Google Ads Account owner).
      -OR-
      Another way to see Invitation, Login to Google Ads account (Or Switch from the Top-Right corner by clicking Profile icon). Go to Admin icon > Access and security > Managers Tab. Find the pending invitation and click ACCEPT. Accept Manager account to Google Ads Account link invitation
    • That's it. Now your Manager account is linked to the Google Ads account

    Obtain ClientId and ClientSecret

    Step-1: Create project

    This step is optional, if you already have a project in Google Cloud and can use it. However, if you don't, proceed with these simple steps to create one:

    1. First of all, go to Google API Console.

    2. Then click Select a project button and then click NEW PROJECT button:

      Start creating a new project in Google Cloud
    3. Name your project and click CREATE button:

      Create a new project in Google Cloud
    4. Wait until the project is created:

      Wait until project is created in Google Cloud
    5. Done! Let's proceed to the next step.

    Step-2: Enable Google Ads API

    In this step we will enable Google Ads API:

    1. Select your project on the top bar:

      Select project in Google Cloud
    2. Then click the "hamburger" icon on the top left and access APIs & Services:

      Access APIs and services in Google Cloud
    3. Now let's enable several APIs by clicking ENABLE APIS AND SERVICES button:

      Enable API for project in Google Cloud
    4. In the search bar search for ads and then locate and select Google Ads API:

      Search for API in Google Cloud
    5. Enable Google Ads API:

      Enable Google Ads API
    6. Done! Let's proceed to the next step.

    Step-3: Create Service Account

    Use the steps below to create a Service Account in Google Cloud:

    1. First of all, go to IAM & Admin in Google Cloud console:

      Access IAM & Admin in Google Cloud
    2. Once you do that, click Service Accounts on the left side and click CREATE SERVICE ACCOUNT button:

      Start creating service account in Google Cloud
    3. Then name your service account and click CREATE AND CONTINUE button:

      Create service account in Google Cloud
    4. Continue by clicking Select a role dropdown and start granting service account Project Viewer roles:

      Start granting service account project roles in Google Cloud
    5. Find Project group and select Viewer role:

      Grant service account project viewer role
    6. Finish adding roles by clicking CONTINUE button:

      Finish granting service account project roles in Google Cloud
      You can always add or modify permissions later in IAM & Admin.
    7. Finally, in the last step, just click button DONE:

      Finish configuring service account in Google Cloud
    8. Done! We are ready to add a Key to this service account in the next step.

    Step-4: Add Key to Service Account

    We are ready to add a Key (JSON or P12 key file) to the created Service Account:

    1. In Service Accounts open newly created service account:

      Open service account in Google Cloud
    2. Next, copy email address of your service account for the later step:

      Copy service account email address in Google Cloud
    3. Continue by selecting KEYS tab, then press ADD KEY dropdown, and click Create new key menu item:

      Start creating key for service account in Google Cloud
    4. Finally, select JSON (Engine v19+) or P12 option and hit CREATE button:

      Create JSON or P12 key for service account in Google Cloud
    5. Key file downloads into your machine. We have all the data needed for authentication, let's proceed to the last step!

    Step-5: Give Permissions to Service Account

    Now it's time to grant permission to Service Account we just created:

    1. Login to https://ads.google.com/aw/settings/account with Google Ads account credentials (If propmpted choose your Ads account).
    2. Go to Admin section, Access and security, Click on Users tab.

    3. Click on Add Icon (+) and enter service account email address which you like to use for data access and choose permissions.
    4. That's it! Let's proceed to the configuration!

    Step-6: Configure connection

    1. Now go to SSIS package or ODBC data source and configure these fields in Service Account authentication configuration:

      • In the Service Account Email field paste the service account Email address value you copied in the previous step.
      • In the Service Account Private Key Path (i.e. *.json OR *.p12) field use downloaded key file path.
    2. Done! Now you are ready to use Google Ads Connector!
    If you received an error saying DEVELOPER_TOKEN_PROHIBITED then read the following workaround.
    Each Google API Console project can be associated with the developer token from only one manager account. Once you make a Google Ads API request, the developer token is permanently paired to the Google API Console project. If you don't use a new Google API Console project, you'll get a DEVELOPER_TOKEN_PROHIBITED error when making a request. Unfortunatly there is no other way to Unlink old Developer Token from the API Project, so for now just create a new Project as a workaround to fix this error.

    Fill in all required parameters and set optional parameters if needed:

    GoogleAdsDSN
    Google Ads
    Service Account [OAuth]
    https://googleads.googleapis.com/[$ApiVersion$]
    Required Parameters
    Service Account Email Fill-in the parameter...
    Service Account Private Key Path (i.e. *.json OR *.p12) Fill-in the parameter...
    CustomerId (without dash e.g. 2125557752) Fill-in the parameter...
    DeveloperToken Fill-in the parameter...
    Optional Parameters
    Scope https://www.googleapis.com/auth/adwords
    Login CustomerId (without dash e.g. 2125557752)
    Linked CustomerId (without dash e.g. 2125557752)
    API Version v19
    RetryMode RetryWhenStatusCodeMatch
    RetryStatusCodeList 429
    RetryCountMax 5
    RetryMultiplyWaitTime True
    Impersonate As (Google account email address)
    ODBC DSN Oauth Connection Configuration

  6. Once the data source has been configured, you can preview data. Select the Preview tab and use settings similar to the following to preview data:
    ODBC ZappySys Data Source Preview

  7. Click OK to finish creating the data source.

Video instructions

Read data in C#

Using ODBC DSN

  1. Create a new Console project and use this code to read the data:

    "GoogleAdsDSN";
    Make ZappySys Driver call in c#

  2. Press F5 to run the code and read the data:
    ZappySys Driver Output in c#

  3. Here is the code in text format:

    using System;
    using System.Data.Odbc;
    
    namespace ConsoleApp {
        class Program {
            static void Main() {
                var dsn = "GoogleAdsDSN";
                using (var conn = new OdbcConnection(String.Format("DSN={0}", dsn)))
                {
                    conn.Open();
                    var cmd = new OdbcCommand("SELECT * FROM Products", conn);
                    
                    //Increase the timeout duration from the default 30 seconds, which may be insufficient in certain scenarios
                    cmd.CommandTimeout=600; // 600-Seconds
                    
                    var rdr = cmd.ExecuteReader();
                    while (rdr.Read())
                    {
                        for (int i = 0; i < rdr.FieldCount; i++)
                        {
                                Console.Write("{0}\t", rdr[i]);
                        }
                        Console.WriteLine();
                    }
                }
                Console.ReadKey();
            }
        }
    }
    

Using a full ODBC connection string

If you want to avoid being dependent on a DSN and creating multiple DSNs for each platform (x86, x64), then you can use a fully qualified connection string. Simply go to your DSN and copy the Connection String:

  1. Open ODBC data source configuration and click Copy settings:
    ZappySys API Driver - Google Ads
    Read / write Google Ads data inside your app (e.g. Campaigns, Ad Groups, Keywords, Spending, Performance); perform many Google Ads operations without coding, just using easy to use high performance API Connector for Google Ads
    GoogleAdsDSN
    Copy connection string for ODBC application
  2. The window opens, telling us the connection string was successfully copied to the clipboard: Successful connection string copying for ODBC application
  3. Then in your C# code, pass the connection string as an argument when calling the OdbcConnection object's constructor, for example:

    var connectionString = @"DRIVER={ZappySys API Driver};ServiceUrl=https://googleads.googleapis.com/[$ApiVersion$];Provider=GoogleAdWords;ScopeSeparator={space};RetryMode=[$RetryMode$];RetryStatusCodeList=[$RetryStatusCodeList$]";
    
    using (var conn = new OdbcConnection(connectionString))
    {
        // your code goes here
    }

Limitations of using a full connection string

Despite using a full ODBC connection string may be very convenient it comes with a limitation: it's length is limited to 1024 symbols (or sometimes more). It usually happens when API provider generates a very long Refresh Token when OAuth is at play. If you are using such a long ODBC connection string, you may get this error:

"Connection string exceeds maximum allowed length of 1024"

But there is a solution to this by storing the full connection string in a file. Follow the steps below to achieve this:

  1. Open your ODBC data source.
  2. Click Copy settings button to copy a full connection string (see the previous section on how to accomplish that).
  3. Then create a new file, let's say, in C:\temp\odbc-connection-string.txt.
  4. Continue by pasting the copied connection string into a newly created file and save it.
  5. Finally, the last step! Just construct a shorter ODBC connection string using this format:
    DRIVER={ZappySys API Driver};SettingsFile=C:\temp\odbc-connection-string.txt
  6. Our troubles are over! Now you should be able to use this connection string in C# with no problems.
This feature requires ODBC PowerPack v1.9.0 or later.

Advanced topics

Create Custom Stored Procedure in ZappySys Driver

You can create procedures to encapsulate custom logic and then only pass handful parameters rather than long SQL to execute your API call.

Steps to create Custom Stored Procedure in ZappySys Driver. You can insert Placeholders anywhere inside Procedure Body. Read more about placeholders here

  1. Go to Custom Objects Tab and Click on Add button and Select Add Procedure:
    ZappySys Driver - Add Stored Procedure

  2. Enter the desired Procedure name and click on OK:
    ZappySys Driver - Add Stored Procedure Name

  3. Select the created Stored Procedure and write the your desired stored procedure and Save it and it will create the custom stored procedure in the ZappySys Driver:
    Here is an example stored procedure for ZappySys Driver. You can insert Placeholders anywhere inside Procedure Body. Read more about placeholders here

    CREATE PROCEDURE [usp_get_orders]
        @fromdate = '<<yyyy-MM-dd,FUN_TODAY>>'
     AS
        SELECT * FROM Orders where OrderDate >= '<@fromdate>';
    

    ZappySys Driver - Create Custom Stored Procedure

  4. That's it now go to Preview Tab and Execute your Stored Procedure using Exec Command. In this example it will extract the orders from the date 1996-01-01:

    Exec usp_get_orders '1996-01-01';

    ZappySys Driver - Execute Custom Stored Procedure

  5. Let's generate the SQL Server Query Code to make the API call using stored procedure. Go to Code Generator Tab, select language as SQL Server and click on Generate button the generate the code.
    As we already created the linked server for this Data Source, in that you just need to copy the Select Query and need to use the linked server name which we have apply on the place of [MY_API_SERVICE] placeholder.

    SELECT * FROM OPENQUERY([LINKED_SERVER_TO_GOOGLE_ADS_IN_DATA_GATEWAY], 'EXEC usp_get_orders @fromdate=''1996-07-30''')

    ZappySys Driver - Generate SQL Server Query

  6. Now go to SQL served and execute that query and it will make the API call using stored procedure and provide you the response.
    ZappySys Driver - Generate SQL Server Query

Create Custom Virtual Table in ZappySys Driver

ZappySys API Drivers support flexible Query language so you can override Default Properties you configured on Data Source such as URL, Body. This way you don't have to create multiple Data Sources if you like to read data from multiple EndPoints. However not every application support supplying custom SQL to driver so you can only select Table from list returned from driver.

If you're dealing with Microsoft Access and need to import data from an SQL query, it's important to note that Access doesn't allow direct import of SQL queries. Instead, you can create custom objects (Virtual Tables) to handle the import process.

Many applications like MS Access, Informatica Designer wont give you option to specify custom SQL when you import Objects. In such case Virtual Table is very useful. You can create many Virtual Tables on the same Data Source (e.g. If you have 50 URLs with slight variations you can create virtual tables with just URL as Parameter setting.

  1. Go to Custom Objects Tab and Click on Add button and Select Add Table:
    ZappySys Driver - Add Table

  2. Enter the desired Table name and click on OK:
    ZappySys Driver - Add Table Name

  3. And it will open the New Query Window Click on Cancel to close that window and go to Custom Objects Tab.

  4. Select the created table, Select Text Type AS SQL and write the your desired SQL Query and Save it and it will create the custom table in the ZappySys Driver:
    Here is an example SQL query for ZappySys Driver. You can insert Placeholders also. Read more about placeholders here

    SELECT
      "ShipCountry",
      "OrderID",
      "CustomerID",
      "EmployeeID",
      "OrderDate",
      "RequiredDate",
      "ShippedDate",
      "ShipVia",
      "Freight",
      "ShipName",
      "ShipAddress",
      "ShipCity",
      "ShipRegion",
      "ShipPostalCode"
    FROM "Orders"
    Where "ShipCountry"='USA'

    ZappySys Driver - Create Custom Table

  5. That's it now go to Preview Tab and Execute your custom virtual table query. In this example it will extract the orders for the USA Shipping Country only:

    SELECT * FROM "vt__usa_orders_only"

    ZappySys Driver - Execute Custom Virtual Table Query

  6. Let's generate the SQL Server Query Code to make the API call using stored procedure. Go to Code Generator Tab, select language as SQL Server and click on Generate button the generate the code.
    As we already created the linked server for this Data Source, in that you just need to copy the Select Query and need to use the linked server name which we have apply on the place of [MY_API_SERVICE] placeholder.

    SELECT * FROM OPENQUERY([LINKED_SERVER_TO_GOOGLE_ADS_IN_DATA_GATEWAY], 'EXEC [usp_get_orders] ''1996-01-01''')

    ZappySys Driver - Generate SQL Server Query

  7. Now go to SQL served and execute that query and it will make the API call using stored procedure and provide you the response.
    ZappySys Driver - Generate SQL Server Query

Actions supported by Google Ads Connector

Google Ads Connector support following actions for REST API integration. If some actions are not listed below then you can easily edit Connector file and enhance out of the box functionality.
 Get Report: Campaign Performance (By Date)
Get campaign performance data by date. If you like to customize this report then use get_query_result endpoint.    [ Read more... ]
 Get Report: Campaign Performance (By Year and Month)
Get campaign performance data by year and month. If you like to customize this report then use get_query_result endpoint.    [ Read more... ]
 Query Google Ads data (Using GAQL - Google Ads Query Language)
Get Google Ads report data using GAQL (Google Ads Query Language) SQL query. Use Query builder from this link to select fields, segments, and metrics https://developers.google.com/google-ads/api/fields/v18/overview_query_builder (Click on Resource type you like to query) for SELECT, FROM and ORDER BY    [ Read more... ]
Parameter Description
Filter
Option Value
$.results[*] $.results[*]
$.results[*].campaign $.results[*].campaign
$.results[*].customer $.results[*].customer
$.results[*].anything_here $.results[*].anything_here
Enter Query (i.e. GAQL sql)
 Get Resources (For GAQL)
Get resources you can query for GAQL    [ Read more... ]
 Get Resource Segments (For GAQL)
Get segments (Group By Fields) for all or selected resource using GAQL    [ Read more... ]
Parameter Description
Resource
 Get Resource Metrics (For GAQL)
Get metrics you can query (for all or selected resource) using GAQL, Numeric fields which can be aggregated (e.g. clicks, impressions)    [ Read more... ]
Parameter Description
Resource
 Get Resource Attributes (For GAQL)
Get attributes you can query (for all or selected resource) using GAQL    [ Read more... ]
Parameter Description
Resource
 Get Resource Data (Query Attributes, Segments, Metrics)
Get Google Ads resource data without supplying GAQL, easy to use Query Builder to fetch data from any object by its Resource name.    [ Read more... ]
Parameter Description
Filter
Option Value
$.results[*] $.results[*]
$.results[*].campaign $.results[*].campaign
$.results[*].customer $.results[*].customer
$.results[*].anything_here $.results[*].anything_here
Resource
Attributes (Leave blank to select all)
Segments (Group By)
Metrics (Aggregate Fields)
Where Clause
Option Value
Example1 segments.date DURING LAST_30_DAYS
Example2 segments.date > '<>' AND segments.date < '<>'
Example3 metrics.impressions > 10 AND segments.date > '<>' AND segments.date < '<>'
Example4 campaign.status='ENABLED' AND metrics.impressions > 10 AND segments.date > '<>' AND segments.date < '<>'
OrderBy Clause
Option Value
Example1 segments.date
Example2 segments.date DESC
Example3 segments.year DESC,segments.month ASC
Limit Clause (i.e. Max Rows) - Blank means all rows
Option Value
Example1 (All Rows - Keep Blank)
Example2 1000
 Get Linked Customers (For Manager Account)
Get Linked Customers (Must be using Manager Account)    [ Read more... ]
 Get Customers
Get Google Ads customer data    [ Read more... ]
 Get Campaigns
Get Google Ads campaign data    [ Read more... ]
 Get Campaign Keywords
Get Campaign Keywords (For all AdGroup)    [ Read more... ]
 Generic Request
This is generic endpoint. Use this endpoint when some actions are not implemented by connector. Just enter partial URL (Required), Body, Method, Header etc. Most parameters are optional except URL.    [ Read more... ]
Parameter Description
Url API URL goes here. You can enter full URL or Partial URL relative to Base URL. If it is full URL then domain name must be part of ServiceURL or part of TrustedDomains
Body Request Body content goes here
IsMultiPart Set this option if you want to upload file(s) (i.e. POST RAW file data) or send data using Multi-Part encoding method (i.e. Content-Type: multipart/form-data). Multi-Part request allows you to mix key/value and upload files in same request. On the other hand raw upload allows only single file upload (without any key/value) ==== Raw Upload (Content-Type: application/octet-stream) ===== To upload single file in raw mode check this option and specify full file path starting with @ sign in the Body (e.g. @c:\data\myfile.zip ) ==== Form-Data / Multipart Upload (Content-Type: multipart/form-data) ===== To treat your Request data as multi part fields you must specify key/value pairs separated by new lines into RequestData field (i.e. Body). Each key value pair is entered on new-line and key/value are separated using equal sign (=). Preceding and trailing spaces are ignored also blank lines are ignored. If field value has some any special character(s) then use escape sequence (e.g. For NewLine: \r\n, For Tab: \t, For at (@): \@). When value of any field starts with at sign (@) its automatically treated as File you want to upload. By default file content type is determined based on extension however you can supply content type manually for any field using this way [ YourFileFieldName.Content-Type=some-content-type ]. By default File Upload Field always includes Content-Type in the request (non file fields do not have content-type by default unless you supply manually). For some reason if you dont want to use Content-Type header in your request then supply blank Content-Type to exclude this header altogather [e.g. SomeFieldName.Content-Type= ]. In below example we have supplied Content-Type for file2 and SomeField1, all other fields are using default content-type. See below Example of uploading multiple files along with additional fields. If some API requires you to pass Content-Type: multipart/form-data rather than multipart/form-data then manually set Request Header => Content-Type: multipart/mixed (it must starts with multipart/ else will be ignored). file1=@c:\data\Myfile1.txt file2=@c:\data\Myfile2.json file2.Content-Type=application/json SomeField1=aaaaaaa SomeField1.Content-Type=text/plain SomeField2=12345 SomeFieldWithNewLineAndTab=This is line1\r\nThis is line2\r\nThis is \ttab \ttab \ttab SomeFieldStartingWithAtSign=\@MyTwitterHandle
Filter Enter filter to extract array from response. Example: $.rows[*] --OR-- $.customers[*].orders[*]. Check your response document and find out hierarchy you like to extract
Option Value
No filter
Example1 $.store.books[*]
Example2 (Sections Under Books) $.store.books[*].sections[*]
Example3 (Equals) $.store.books[?(@author=='sam')]
Example4 (Equals - Any Section) $..[?(@author=='sam')]
Example5 (Not Equals - Any Section) $..[?(@author!='sam')]
Example6 (Number less than) $.store.books[?(@.price<10)] Example7 (Regular Expression - Contains Pattern)=$.store.books[?(@author=~ /sam|bob/ )]
Example8 (Regular Expression - Does Not Contain Pattern) $.store.books[?(@author=~ /^((?!sam|bob).)*$/ )]
Example9 (Regular Expression - Exact Pattern Match) $.store.books[?(@author=~ /^sam|bob$/ )]
Example10 (Regular Expression - Starts With) $.store.books[?(@author=~ /^sam/ )]
Example11 (Regular Expression - Ends With) $.store.books[?(@author=~ /sam$/ )]
Example12 (Between) $.store.employees[?( @.hiredate>'2015-01-01' && @.hiredate<'2015-01-04' )]
Headers Headers for Request. To enter multiple headers use double pipe or new line after each {header-name}:{value} pair
 Generic Request (Bulk Write)
This is a generic endpoint for bulk write purpose. Use this endpoint when some actions are not implemented by connector. Just enter partial URL (Required), Body, Method, Header etc. Most parameters are optional except URL.    [ Read more... ]
Parameter Description
Url API URL goes here. You can enter full URL or Partial URL relative to Base URL. If it is full URL then domain name must be part of ServiceURL or part of TrustedDomains
IsMultiPart Set this option if you want to upload file(s) (i.e. POST RAW file data) or send data using Multi-Part encoding method (i.e. Content-Type: multipart/form-data). Multi-Part request allows you to mix key/value and upload files in same request. On the other hand raw upload allows only single file upload (without any key/value) ==== Raw Upload (Content-Type: application/octet-stream) ===== To upload single file in raw mode check this option and specify full file path starting with @ sign in the Body (e.g. @c:\data\myfile.zip ) ==== Form-Data / Multipart Upload (Content-Type: multipart/form-data) ===== To treat your Request data as multi part fields you must specify key/value pairs separated by new lines into RequestData field (i.e. Body). Each key value pair is entered on new-line and key/value are separated using equal sign (=). Preceding and trailing spaces are ignored also blank lines are ignored. If field value has some any special character(s) then use escape sequence (e.g. For NewLine: \r\n, For Tab: \t, For at (@): \@). When value of any field starts with at sign (@) its automatically treated as File you want to upload. By default file content type is determined based on extension however you can supply content type manually for any field using this way [ YourFileFieldName.Content-Type=some-content-type ]. By default File Upload Field always includes Content-Type in the request (non file fields do not have content-type by default unless you supply manually). For some reason if you dont want to use Content-Type header in your request then supply blank Content-Type to exclude this header altogather [e.g. SomeFieldName.Content-Type= ]. In below example we have supplied Content-Type for file2 and SomeField1, all other fields are using default content-type. See below Example of uploading multiple files along with additional fields. If some API requires you to pass Content-Type: multipart/form-data rather than multipart/form-data then manually set Request Header => Content-Type: multipart/mixed (it must starts with multipart/ else will be ignored). file1=@c:\data\Myfile1.txt file2=@c:\data\Myfile2.json file2.Content-Type=application/json SomeField1=aaaaaaa SomeField1.Content-Type=text/plain SomeField2=12345 SomeFieldWithNewLineAndTab=This is line1\r\nThis is line2\r\nThis is \ttab \ttab \ttab SomeFieldStartingWithAtSign=\@MyTwitterHandle
Filter Enter filter to extract array from response. Example: $.rows[*] --OR-- $.customers[*].orders[*]. Check your response document and find out hierarchy you like to extract
Headers Headers for Request. To enter multiple headers use double pipe (||) or new line after each {header-name}:{value} pair

Google Ads Connector Examples for C# Connection

This page offers a collection of SQL examples designed for seamless integration with the ZappySys API ODBC Driver under ODBC Data Source (36/64) or ZappySys Data Gateway, enhancing your ability to connect and interact with Prebuilt Connectors effectively.

Get Campaigns    [ Read more... ]

Get all Campaigns for Google Ads account

SELECT * FROM get_campaigns

Get Customers    [ Read more... ]

Get all customers you can query in your account

SELECT * FROM get_customers

Get campaign performance report by date    [ Read more... ]

Get campaign performance data, group by date and campaign

SELECT * FROM get_report_campaign_performance_by_date WITH(ReportStartDate='monthstart', ReportEndDate='today-1d')

Get campaign performance report by month    [ Read more... ]

Get campaign performance data, group by year, month and campaign

SELECT * FROM get_report_campaign_performance_by_month WITH(ReportStartDate='monthstart', ReportEndDate='today-1d')

Get keywords information (all campaigns / ad groups)    [ Read more... ]

Get keywords for all campaigns and all ad groups (criterion_id is basically keyword_id)

select * from get_campaign_keywords

Get resource data (e.g. ad_group, ad_group_ad, keyword_view    [ Read more... ]

Get data for any resource

SELECT * FROM get_resource_data
WITH (
Resource='Campaign'

--//Optional Parameters 
--, Attributes='' --Keep blank to output all attributes
--OR--
--, Attributes='campaign.id~campaign.name~campaign.end_date' 

--, Metrics='metrics.clicks~metrics.impressions'
--, Segments='segments.year~segments.month'
--//must supply where clause if certain segments used (e.g. date, year, month)
--, Where='segments.date between ''<<yearstart,FUN_TO_DATE>>'' AND ''<<today-1d,FUN_TO_DATE>>'' '
--, OrderBy='segments.year DESC, segments.month ASC'
)

/*
--OR-- Simple Mode (Query by Resource Name in FROM clause).

Step-1: Findout all resource you can query using  
select * from get_resources

Step-2: Use resource name like below (in FROM)
Example resources (If data is missing it may throw error)

select * from ad_group
select * from ad_group_ad
select * from ad_group_ad_asset_combination_view
select * from ad_group_ad_asset_view
select * from ad_group_asset
select * from ad_group_audience_view
select * from ad_schedule_view
select * from age_range_view
select * from android_privacy_shared_key_google_ad_group
select * from android_privacy_shared_key_google_campaign
select * from android_privacy_shared_key_google_network_type
select * from asset
select * from asset_field_type_view
select * from asset_group
select * from asset_group_asset
select * from asset_group_product_group_view
select * from asset_group_top_combination_view
select * from asset_set_asset
select * from asset_set_type_view
select * from bidding_strategy
select * from campaign
select * from campaign_aggregate_asset_view
select * from campaign_asset
select * from campaign_audience_view
select * from campaign_budget
select * from campaign_group
select * from campaign_search_term_insight
select * from channel_aggregate_asset_view
select * from click_view
select * from content_criterion_view
select * from conversion_action
select * from customer
select * from customer_asset
select * from customer_search_term_insight
select * from detail_placement_view
select * from display_keyword_view
select * from distance_view
select * from dynamic_search_ads_search_term_view
select * from expanded_landing_page_view
select * from gender_view
select * from geographic_view
select * from group_placement_view
select * from hotel_group_view
select * from hotel_performance_view
select * from hotel_reconciliation
select * from income_range_view
select * from keyword_view
select * from landing_page_view
select * from location_view
select * from managed_placement_view
select * from paid_organic_search_term_view
select * from parental_status_view
select * from per_store_view
select * from performance_max_placement_view
select * from product_group_view
select * from search_term_view
select * from shared_set
select * from shopping_performance_view
select * from shopping_product
select * from smart_campaign_search_term_view
select * from topic_view
select * from travel_activity_group_view
select * from travel_activity_performance_view
select * from user_location_view
select * from video
select * from webpage_view
*/

Query Google Ads data using GAQL (Google Ads Query Language)    [ Read more... ]

Get Google Ads report data using GAQL (Google Ads Query Language) SQL query. Use Query builder from this link to select fields, segments, and metrics https://developers.google.com/google-ads/api/fields/v18/overview_query_builder (Click on Resource type you like to query) for SELECT, FROM and ORDER BY

--Use Query Builder here https://developers.google.com/google-ads/api/fields/v18/overview_query_builder
--Paste Generated query in Query='here'				

SELECT 
	[campaign.id] as id, 
	[campaign.name] as name, 
	[metrics.impressions] as impressions, 
	[metrics.clicks] as clicks, 
	[metrics.costMicros] / 1000000 as cost --//API returns Unit in Micro so to get actual value divide by 1000000
FROM get_query_result
WITH(
	  Filter='$.results[*]'
	, Query='SELECT  campaign.id, campaign.name, metrics.impressions, metrics.clicks, metrics.cost_micros 
FROM campaign 
WHERE campaign.status = ''ENABLED''
 AND metrics.impressions > 10
ORDER BY campaign.id
--LIMIT 1000
'
	--Set different Customer Id here if not supplied in connection settings
	--, CustomerId='1112223333'
)

Query Google Ads data (Simple Mode) - using #DirectSQL prefix    [ Read more... ]

Get Google Ads report data using GAQL (Google Ads Query Language) - SQL query using simple mode. This example passes GAQL query to get_query_result endpoint with specifying endpoint details. You must prefix query with special tag #DirectSQL

#DirectSQL 

--Use Query Builder here https://developers.google.com/google-ads/api/fields/v18/overview_query_builder
--Paste Generated query below
				
SELECT  campaign.id, campaign.name, metrics.impressions, metrics.clicks, metrics.cost_micros
FROM campaign 
--WHERE campaign.status = 'ENABLED'
--ORDER BY campaign.id
--LIMIT 1000

Query Google Ads Campaign Performance Data (Metrics / Segments) - using #DirectSQL prefix    [ Read more... ]

Get Google Ads report data using GAQL (Google Ads Query Language) group by Date and Campaign. You must prefix query with special tag #DirectSQL

#DirectSQL 

--Use Query Builder here https://developers.google.com/google-ads/api/fields/v18/overview_query_builder
--Paste Generated query below

SELECT 
  segments.date 
, campaign.id
, campaign.name
, metrics.all_conversions
, metrics.average_cpc
, metrics.average_cost
, metrics.average_cpv
, metrics.average_cpm
, metrics.average_cpe
, metrics.average_impression_frequency_per_user
, metrics.average_page_views
, metrics.bounce_rate
, metrics.clicks
, metrics.conversions
, metrics.content_impression_share
, metrics.content_budget_lost_impression_share
, metrics.cost_micros
, metrics.cost_per_all_conversions
, metrics.cost_per_conversion
, metrics.ctr
, metrics.engagement_rate
, metrics.engagements
--, metrics.general_invalid_click_rate
--, metrics.general_invalid_clicks
, metrics.impressions
, metrics.interaction_rate
, metrics.interactions
, metrics.invalid_clicks
, metrics.search_absolute_top_impression_share
, metrics.search_budget_lost_absolute_top_impression_share
, metrics.search_budget_lost_impression_share
, metrics.search_budget_lost_top_impression_share
, metrics.search_click_share
, metrics.search_impression_share
, metrics.video_view_rate
, metrics.video_quartile_p75_rate
, metrics.video_quartile_p50_rate
, metrics.video_quartile_p25_rate
, metrics.video_quartile_p100_rate
, metrics.video_views
, metrics.view_through_conversions
, metrics.unique_users
, metrics.top_impression_percentage
, metrics.search_rank_lost_top_impression_share
, metrics.search_rank_lost_impression_share
, metrics.search_rank_lost_absolute_top_impression_share
, metrics.search_top_impression_share
, metrics.search_exact_match_impression_share
, metrics.absolute_top_impression_percentage
, metrics.active_view_cpm
, metrics.active_view_ctr
, metrics.active_view_impressions
FROM campaign 
WHERE segments.date BETWEEN '<<monthstart,FUN_TO_DATE>>' and '<<today-1d,FUN_TO_DATE>>'

--WHERE segments.date BETWEEN '2025-01-25' and '2025-02-25'
--AND WHERE campaign.status = 'ENABLED'
--ORDER BY segments.date,campaign.id
--LIMIT 1000

Conclusion

In this article we showed you how to connect to Google Ads in C# and integrate data without any coding, saving you time and effort. We encourage you to download Google Ads Connector for C# and see how easy it is to use it for yourself or your team.

If you have any questions, feel free to contact ZappySys support team. You can also open a live chat immediately by clicking on the chat icon below.

Download Google Ads Connector for C# Documentation

More integrations

Other connectors for C#

Other application integration scenarios for Google Ads

  • How to connect Google Ads in C#?

  • How to get Google Ads data in C#?

  • How to read Google Ads data in C#?

  • How to load Google Ads data in C#?

  • How to import Google Ads data in C#?

  • How to pull Google Ads data in C#?

  • How to push data to Google Ads in C#?

  • How to write data to Google Ads in C#?

  • How to POST data to Google Ads in C#?

  • Call Google Ads API in C#

  • Consume Google Ads API in C#

  • Google Ads C# Automate

  • Google Ads C# Integration

  • Integration Google Ads in C#

  • Consume real-time Google Ads data in C#

  • Consume real-time Google Ads API data in C#

  • Google Ads ODBC Driver | ODBC Driver for Google Ads | ODBC Google Ads Driver | SSIS Google Ads Source | SSIS Google Ads Destination

  • Connect Google Ads in C#

  • Load Google Ads in C#

  • Load Google Ads data in C#

  • Read Google Ads data in C#

  • Google Ads API Call in C#