Google Ads API . Unable to pull Campaign Information

31 views
Skip to first unread message

Arun Nair

unread,
Mar 21, 2025, 11:18:45 PMMar 21
to Google Ads API and AdWords API Forum
Hello  - I am using Python script to pull Campaign Information . I generated the refresh token via Google Oauth2 Playground and use that in the script to generate access token when the script is run.  Below is the code , I use to hit the api .

import requests

def fetch_campaigns(customer_id, access_token, developer_token):
    url = f"https://googleads.googleapis.com/v18/customers/{customer_id}/googleAds:search"
    headers = {
        "Authorization": f"Bearer {access_token}",
        "developer-token": developer_token,
        "Content-Type": "application/json"
    }
    query = {
        "query": """
            SELECT
                customer.id,
                customer.manager,
                customer.resource_name,
                customer.status,
                customer.test_account,
                campaign.name,
                campaign.id
            FROM
                campaign
        """
    }

    try:
        response = requests.post(url, json=query, headers=headers)
        print("Status Code:", response.status_code)
        print("Headers:", response.headers)
        print("Response Body:", response.json())

        # Raise an error for bad status codes
        response.raise_for_status()

        # Return the JSON response
        return response.json()

    except requests.exceptions.RequestException as e:
        print("Error making request:", e)
        return None

# Example usage
customer_id = "INSERT_CUSTOMER_ID_HERE"
access_token = "INSERT_ACCESS_TOKEN_HERE"
developer_token = "INSERT_DEVELOPER_TOKEN_HERE"

result = fetch_campaigns(customer_id, access_token, developer_token)
if result:
    print("Campaigns:", result).

I get the status code '200'  . But the response is missing the "results" field.   We have a master customer account  and  under we have multiple accounts  for each department. So do I need to provide the account id as well to get the results ?  If yes , the how ?  I am not seeing any resources mentioning that step. Kindly  help me out on this.

Thanks,
Arun 

Google Ads API Forum Advisor

unread,
Mar 24, 2025, 3:05:45 AMMar 24
to arun.n...@gmail.com, adwor...@googlegroups.com
Hi,

Thank you for reaching out to the Google Ads API support team.

As per the provided information, I understand that you're trying to retrieve the campaign information from the campaign resource and you have received a successful response with an empty result. To verify further, could you please provide us with the customer id and the login customer id that helps to assist you further.
 

Thanks,
 
Google Logo Google Ads API Team

Feedback
How was our support today?

rating1    rating2    rating3    rating4    rating5
[2025-03-24 03:04:25Z GMT] This message is in relation to case "ref:!00D1U01174p.!5004Q02vHBtf:ref" (ADR-00295975)



Reply all
Reply to author
Forward
0 new messages