Gender & Age Criterion

136 views
Skip to first unread message

Maxime Heurtevent

unread,
Feb 7, 2024, 4:28:30 AM2/7/24
to Google Ads API and AdWords API Forum
Hello,

I need to use the Gender and Age criteria, but I can't create them without setting the negative value to true.

What's more, when I try to update the criterion to negative false, I always get an error.

I can provide you with more detailed functions if required.

Creation: 
        operations [
            create: {
                negative: true, // mandatory param with true value
                campaign: campaignResourceName,
                type: 'GENDER',
                gender: {
                    type: gender
                }
            }
        ]

Update:
                operations: [
                    {
                        updateMask: 'gender.type, negative',
                        update: {
                            negative: false, // Doesn't work if trying to update the negative param
                            resourceName: genderCriterionResourceName,
                        }
                    }
                ]

Google Ads API Forum Advisor

unread,
Feb 7, 2024, 8:20:00 AM2/7/24
to m.77.heurtev...@gmail.com, adwor...@googlegroups.com
Hi,

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

By reviewing your query, I understand that you are getting an error when trying to update the criterion to negative false. In order to investigate the issue, provide us with the updated complete API logs (request and response with request-id and request header) generated at your end.

If you are using a client library and haven't enabled the logging yet, I would request you to enable logging for the specific client library that you are using. You can refer to the guides Java.NetPHPPythonRuby or Perl to enable logging at your end. For REST interface requests, you can enable logging via the curl command by using the -i flag.
 
This message is in relation to case "ref:!00D1U01174p.!5004Q02rytfz:ref"

Thanks,
 
Google Logo Google Ads API Team


Maxime Heurtevent

unread,
Feb 7, 2024, 12:30:15 PM2/7/24
to Google Ads API and AdWords API Forum
Here are example of curl command: 

Campaign creation:
curl -X POST \
  'https://googleads.googleapis.com/v15/<CUSTOMER_RESSOURCE_NAME>/campaignCriteria:mutate' \
  -H 'Content-Type: application/json' \
  -H 'developer-token: <DEVELOPER_TOKEN>' \
  -H 'Authorization: Bearer <ACCESS_TOKEN>' \
  -H 'login-customer-id: <MANAGER_ID>' \
  -d '{
    "operations": [
      {
        "create": {
          "negative": false,
          "campaign": "<CUSTOMER_RESSOURCE_NAME>/campaigns/21005342630",
          "type": "GENDER",
          "gender": {
            "type": "FEMALE"
          }
        }
      }
    ]
  }'
{
  "error": {
    "code": 400,
    "message": "Request contains an invalid argument.",
    "status": "INVALID_ARGUMENT",
    "details": [
      {
        "@type": "type.googleapis.com/google.ads.googleads.v15.errors.GoogleAdsFailure",
        "errors": [
          {
            "errorCode": {
              "criterionError": "FIELD_INCOMPATIBLE_WITH_NEGATIVE_TARGETING"
            },
            "message": "The field is not allowed to be set when the negative field is set to true, for example, we don't allow bids in negative ad group or campaign criteria.",
            "location": {
              "fieldPathElements": [
                {
                  "fieldName": "operations",
                  "index": 0
                },
                {
                  "fieldName": "create"
                },
                {
                  "fieldName": "gender"
                }
              ]
            }
          }
        ],
        "requestId": "jex36XGZqBA5l1VJ6X2mgA"
      }
    ]
  }
}


Update Criteria (when created with negative define true):
curl -X POST \
  'https://googleads.googleapis.com/v15/<CUSTOMER_RESSOURCE_NAME>/campaignCriteria:mutate' \
  -H 'Content-Type: application/json' \
  -H 'developer-token: <DEVELOPER_TOKEN>' \
  -H 'Authorization: Bearer <ACCESS_TOKEN>' \
  -H 'login-customer-id: <MANAGER_ID>' \
  -d '{
    "operations": [
      {
        "updateMask": "gender.type",
        "update": {
          "negative": false,
          "resourceName": "<CUSTOMER_RESSOURCE_NAME>/campaignCriteria/21005342630~10",
          "gender": {
             "type": "FEMALE"
          }
        }
      }
    ]
  }'
{
  "results": [
    {
      "resourceName": "<CUSTOMER_RESSOURCE_NAME>/campaignCriteria/21005342630~10"
    }
  ]
}

The response is positive but when i want to get the campaign criteria info using a GAQL, the criteria isn't update. Moreover negative isn't available in the updateMask field

Campaign data (Criteria):
"campaignCriterion":[{"campaignCriterion":{"resourceName":"<CUSTOMER_RESSOURCE_NAME>/campaignCriteria/21005342630~10","type":"GENDER","gender":{"type":"MALE"},"campaign":"<CUSTOMER_RESSOURCE_NAME>/campaigns/21005342630","criterionId":"10","negative":true}}, ... ],

Tell me if you need more information

Google Ads API Forum Advisor

unread,
Feb 7, 2024, 5:40:24 PM2/7/24
to m.77.heurtev...@gmail.com, adwor...@googlegroups.com

Hi,

Thank you for getting back to us.

Kindly note that the negative field is immutable by nature. This means we cannot modify this field through the Google Ads API.The reason for the negative field not being available in the updateMask field is that in the request, you are not provided with the responseContentType field. Please note that we have to set the response content type in the request before hitting the API. The responseContentType field determines whether the mutable resource or just the resource name should be returned post-mutation. 

Reply all
Reply to author
Forward
0 new messages