Required field not present, even though it is defined (AdGroupCriteria create)

824 views
Skip to first unread message

Thomas D'heer

unread,
Feb 2, 2022, 4:53:36 AM2/2/22
to Google Ads API and AdWords API Forum
Hi,

I'm experiencing difficulties with the creation of ad group criteria.
After creating ad groups, I want to create an ad group criterion for each (see object below), but I keep getting the FieldError "The required field was not present",
caused by the parent_ad_group_criterion property
(under listing_group). This is weird, because I am specifying it as null, which is allowed according to the documentation,
which states: "Resource name of ad group criterion which is the parent listing group subdivision. Null for the root group."

I am working in a Node.js environment and I have tried the result in two ways, with the same result each time:
  • Through the REST API, POST-request with axios (see request details below)
  • Through the Opteo library for Node.js
It works without auth errors, just doesn't execute the creations.
I tried various things like replacing null with an empty string (''), leaving it out altogether, nothing worked.

POST REQUEST

POST /v9/customers/${accountId}/adGroupCriteria:mutate HTTP/1.1

Body:
{
    operations: [
        {
              create: {
                  ad_group: 'customers/${customerId}/adGroups/${adGroupId}',
                  cpc_bid_micros: 200000,
                  listing_group: {
                      parent_ad_group_criterion: null,
                      case_value: {
                          product_item_id: { 
                              value: `${offerId}`,
                         },
                     },
                      type: 2
                 },
                  status: 2
            },
        },
    ],
}

Headers:
{
    "Authorization": 'Bearer ' + ${access_token},
    "developer-token": ${GOOGLE_ADS_DEVELOPER_TOKEN},
    "login-customer-id": ${manager_account_id},
}
RESPONSE
{
  code: 400,
  message: 'Request contains an invalid argument.',
  status: 'INVALID_ARGUMENT',
  details: [
    {
      '@type': 'type.googleapis.com/google.ads.googleads.v9.errors.GoogleAdsFailure',
      errors: [Array],
      requestId: ' **removed** '
    }
  ]
}

Error in errors array:

[
  {
    errorCode: { fieldError: 'REQUIRED' },
    message: 'The required field was not present.',
    location: { fieldPathElements: [Array] }
  }
]

Location object:

{
  fieldPathElements: [
    { fieldName: 'operations', index: 0 },
    { fieldName: 'create' },
    { fieldName: 'listing_group' },
    { fieldName: 'parent_ad_group_criterion' }
  ]
}

Doing the same through Opteo looks like this, which yields the same error:
await customer.adGroupCriteria.create(
    [
        {
            ad_group: 'customers/${customerId}/adGroups/${adGroupId}',
            cpc_bid_micros: 200000,
            listing_group: {
                parent_ad_group_criterion: null,
                case_value: {
                    product_item_id: { 
                        value: `${offerId}`,
                    },
                },
                type: 2
            },
            status: 2
        }
    ],
    {
          partial_failure: true,
    },
);

I thought at first it was a problem with Opteo (e.g. a workaround was posted to fix the problem with their update_mask, which removed properties if they were set to null),
but the fact that the same error occurs through the REST API seems to disprove this.

Does anyone have any idea what's going wrong?
Thanks,
Thomas

Google Ads API Forum Advisor

unread,
Feb 2, 2022, 4:11:23 PM2/2/22
to dheer....@gmail.com, adwor...@googlegroups.com
Hi Thomas,

Could you try creating a root subdivision node and an 'other' node that is a unit node to place your product Id in? I am under the impression that a root node is a subdivision node.

Regards,

Google Logo
Aryeh Baker
Google Ads API Team
 


ref:_00D1U1174p._5004Q2W3ZvG:ref

Thomas D'heer

unread,
Feb 3, 2022, 3:02:04 AM2/3/22
to Google Ads API and AdWords API Forum
Hi,

I managed to make it figure it out in the end. It worked by creating three criteria for every product: a subdivision node as the root, one unit node to determine the product_item_id, and one other unit node. In case anyone wonders, the three nodes look like this (you have to convert them to a 'create' operation before sending the request).

const root_node = {
    resource_name: ad_group_criterion_resource_name,
    listing_group: {
        type: enums.ListingGroupType.SUBDIVISION,
    },
    status: enums.AdGroupCriterionStatus.ENABLED,
};

const child_product_item = {
    ad_group: parent.ad_group_resource_name,
    cpc_bid_micros: cpc_bid_micros,
    listing_group: {
        parent_ad_group_criterion: ad_group_criterion_resource_name,
        case_value: {
            product_item_id: {
                value: `${parent.offerId}`,
            },
        },
        type: enums.ListingGroupType.UNIT,
    },
    status: enums.AdGroupCriterionStatus.ENABLED,
};

const child_node_other = {
    ad_group: parent.ad_group_resource_name,
    cpc_bid_micros: cpc_bid_micros,
    listing_group: {
        parent_ad_group_criterion: ad_group_criterion_resource_name,
        case_value: {
            product_item_id: {},
        },
        type: enums.ListingGroupType.UNIT,
    },
    status: enums.AdGroupCriterionStatus.ENABLED,
};

const triplet = [root_node, child_product_item, child_node_other];

Thanks for the help. Let me know please if you still see anything wrong with this.

Google Ads API Forum Advisor

unread,
Feb 3, 2022, 12:07:00 PM2/3/22
to dheer....@gmail.com, adwor...@googlegroups.com
Hi Thomas,

For us to check if this is correct, could you privately send us a request and response log of API communication that creates your tree? 

The request and response appears similar to the JSON Mappings in our REST documentation. Our client libraries have loggers with logging instructions, to see these instructions you can click on the client library you use in the sidebar of our client library guide and click on "Logging". Setting the log level to 'DEBUG' will get the desired log.
Reply all
Reply to author
Forward
0 new messages