Error while location targeting

103 views
Skip to first unread message

Usama Shaikh

unread,
Jan 20, 2025, 11:13:20 AMJan 20
to Google Ads API and AdWords API Forum
Hi,

I have followed your location targeting documentation reference, but I am facing issue.
https://developers.google.com/google-ads/api/docs/targeting/location-targeting

Remember: I'm using v18.

Below is my code:

def set_campaign_locations(client, customer_id, campaign_resource_name, countries):
    campaign_criterion_service = client.get_service("CampaignCriterionService")
    operations = []

    for country in countries:
        try:
            campaign_criterion_operation = client.get_type("CampaignCriterionOperation")
            campaign_criterion = campaign_criterion_operation.create
            campaign_criterion.campaign = campaign_resource_name
            campaign_criterion.location.geo_target_constant = client.get_service("GeoTargetConstantService").geo_target_constant_path(country['location_id'])
            operations.append(campaign_criterion_operation)
        except Exception as e:
            print(f"Skipping location ID {country['location_id']}: {str(e)}")

    # Send the mutate request.
    try:
        response = campaign_criterion_service.mutate_campaign_criteria(
            customer_id=customer_id, operations=operations
        )
        print(f"Added location criteria: {[res.resource_name for res in response.results]}")
    except GoogleAdsException as ex:
        handle_google_ads_exception(ex)

Below is the error:

Response

Fault: errors {
  error_code {
    request_error: UNKNOWN
  }
  message: "The error code is not in this version."
  trigger {
    string_value: "OWNED_AND_OPERATED"
  }
  location {
    field_path_elements {
      field_name: "operations"
      index: 0
    }
    field_path_elements {
      field_name: "create"
    }
    field_path_elements {
      field_name: "location"
    }
  }
}

Also, please provide the solution for targeting keywords (Content) as well.

Google Ads API Forum Advisor

unread,
Jan 20, 2025, 2:00:30 PMJan 20
to smu31...@gmail.com, adwor...@googlegroups.com

Hi,

Thank you for reaching out to Google Ads API Support.

Kindly note that we are aware of this issue, and the team is working on the fix. One of my team members will reach out to you once we have an update. Meanwhile, your patience is highly appreciated. 

 

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

Thanks,
 
Google Logo Google Ads API Team

Feedback
How was our support today?

rating1    rating2    rating3    rating4    rating5

 


Google Ads API Forum Advisor

unread,
Jan 27, 2025, 5:16:34 PMJan 27
to smu31...@gmail.com, adwor...@googlegroups.com
Hi,

Please ignore our previous response. 

Kindly note that when you set the upgraded_targeting field to 'true' for the demand gen campaign then the location and language targeting are managed at the ad group level rather than the campaign level. If you don't set this field then it will be defaulted to true. Since location and language targeting are applied at the ad group level, you will need to use the adGroupCriteria method to target the locations, rather than the campaignCriteria method. When you try to use the campaignCriteria method you will encounter an 'OWNED_AND_OPERATED' error.  Also, upgraded_targeting is immutable, meaning it cannot be modified once set. The only possible way to avoid the error is you would need to create a new campaign with upgraded_targeting set to 'false', allowing you to use the campaignCriteria method to target the location at the campaign level or to use the adGroupCriteria method and target the locations. 

You can check your Demand Gen campaign to see if the location and language settings are configured at the ad group level or campaign level within the campaign settings page. For reference, I have attached two sample screenshots. In one campaign, the location and language settings are applied at the ad group level, and location exclusions are targeted using the campaignCriteria method, which results in receiving 'OWNED_AND_OPERATED' error. In the other campaign, where location and language settings are applied at the campaign level, no errors are encountered when targeting location exclusions using the campaignCriteria method.

Regarding targeting keywords, you can only exclude keywords at the campaign level, so you must specify 'negative=true' on a keyword's CampaignCriterion. At the ad group level, you can either target or exclude keywords using the adGroupCriteria method.

If you still face any issues, then share us the Google Ads account ID, campaign ID and complete API logs (request and response logs with request-id and request header) so that we can check and confirm if your campaign criteria is created at the campaign level or the ad group level.  

You can send the details via Reply privately to the author option, or direct private reply to this email.
Screenshot 2025-01-28 3.32.59 AM.png
Screenshot 2025-01-28 3.32.46 AM.png
Reply all
Reply to author
Forward
0 new messages