How to get ads Campaign Inactive Status?

60 views
Skip to first unread message

Phuong Nguyen

unread,
Sep 13, 2024, 8:38:48 PM9/13/24
to Google Ads API and AdWords API Forum
how to get with api inactive status for this campaigns? 

Oi01B92.pngnLUXD1T.png


from google.ads.googleads.client import GoogleAdsClient
from google.ads.googleads.errors import GoogleAdsException
import os

def main():
    # Get the path to the google-ads.yaml file
    script_dir = os.path.dirname(os.path.abspath(__file__))
    yaml_path = os.path.join(script_dir, "google-ads.yaml")

    # Load Google Ads client from the specified configuration file
    client = GoogleAdsClient.load_from_storage(yaml_path)

    # Retrieve the customer_id from the YAML configuration
    customer_id = client.login_customer_id

    # Get the service for querying campaigns
    google_ads_service = client.get_service("GoogleAdsService")

    # Campaign ID to search for
    campaign_id = 21694145989

    # Create a query to get the campaign details including specific status fields
    query = f"""
        SELECT
            campaign.id,
            campaign.name,
            campaign.status,
            campaign.primary_status,
            campaign.primary_status_reasons,
            campaign.serving_status
        FROM
            campaign
        WHERE
            campaign.id = {campaign_id}
    """

    try:
        # Execute the query and retrieve the results
        response = google_ads_service.search(customer_id=customer_id, query=query)

        # Initialize a flag to check if any results were found
        results_found = False

        # Output campaign details
        print(f"Campaign Status Details for ID {campaign_id}:")
        for row in response:
            results_found = True
            campaign = row.campaign

            print(f"Campaign Name: {campaign.name}")
            print(f"Campaign ID: {campaign.id}")
            print(f"Campaign Status: {campaign.status.name}")
            print(f"Campaign Primary Status: {campaign.primary_status}")
            print(f"Campaign Serving Status: {campaign.serving_status.name}")
           
            if campaign.primary_status_reasons:
                print("Campaign Primary Status Reasons:")
                for reason in campaign.primary_status_reasons:
                    print(f"  - {reason}")
            else:
                print("Campaign Primary Status Reasons: None")

        if not results_found:
            print(f"No campaign found with ID {campaign_id}")

    except GoogleAdsException as ex:
        print(f"Google Ads API Error: {ex}")
        for error in ex.failure.errors:
            print(f"\tError with message \"{error.message}\".")
            if error.location:
                for field_path_element in error.location.field_path_elements:
                    print(f"\t\tOn field: {field_path_element.field_name}")

if __name__ == "__main__":
    main()

Google Ads API Forum Advisor

unread,
Sep 16, 2024, 2:37:00 AM9/16/24
to phuong...@fastboy.net, adwor...@googlegroups.com
Hi,

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

You can use the below sample query to retrieve the status of the campaign. Please note that the status of the campaign (21694145989) is "ENABLED". 
SELECT campaign.status, campaign.name, campaign.resource_name, campaign.id, campaign.primary_status, campaign.serving_status, campaign.primary_status_reasons FROM campaign WHERE campaign.id = 21694145989
You can use the search or searchStream methods in making the API calls while retrieving the data. Additionally, you can utilize the Google Ads Query Builder and Query Validator to build and validate the queries in the Google Ads API.

I would recommend you refer to this guide on 'campaign' for more information regarding the fields/metrics/segments that can be used with the campaign resource.

I hope this helps.

 
This message is in relation to case "ref:!00D1U01174p.!5004Q02vG8cy:ref" (ADR-00268177)

Thanks,
 
Google Logo Google Ads API Team

 

Phuong Nguyen

unread,
Sep 16, 2024, 8:32:38 PM9/16/24
to Google Ads API and AdWords API Forum
  Hi, yes. I call the api and it return Enabled and stuff, but I need to call api for a status like inactive like image, or something indicated the ads is stop. I need it for my script so it will notify me when it happen.

Phuong Nguyen

unread,
Sep 16, 2024, 8:32:38 PM9/16/24
to Google Ads API and AdWords API Forum
Hi, I mean is like the attached image The ads is "ENABLED" but it is Inactive which wont use any money nor run ads. I am finding a way to call API to get something indicate that the ads is Inactive or other error status, so the script able to notify me.


On Monday, September 16, 2024 at 1:37:00 AM UTC-5 Google Ads API Forum Advisor wrote:

Google Ads API Forum Advisor

unread,
Sep 17, 2024, 5:14:10 AM9/17/24
to phuong...@fastboy.net, adwor...@googlegroups.com
Hi,

It is not possible to fetch the 'Inactive' status of the campaigns via the Google Ads API. I hope this clarifies.
Reply all
Reply to author
Forward
0 new messages