How to change MatchType of an existing keyword

25 views
Skip to first unread message

Lukas Rilling

unread,
Jul 11, 2019, 7:26:17 PM7/11/19
to AdWords API and Google Ads API Forum
Hey there,

I'm trying to change the MatchType of an existing keyword using the following code:

$adWordsServices = new AdWordsServices();
$adGroupCriterionService = $adWordsServices->get($this->session->get("adwordsSession"), AdGroupCriterionService::class);
$criterion = new Keyword();
$criterion->setId($keywordId);

if ($matchType == 'broad') {
$criterion->setMatchType(KeywordMatchType::BROAD);
} else if ($matchType == 'exact') {
$criterion->setMatchType(KeywordMatchType::EXACT);
} else {
$criterion->setMatchType(KeywordMatchType::PHRASE);
}
$criterion->setText($text);

// Create an ad group criterion.
$adGroupCriterion = new BiddableAdGroupCriterion();
$adGroupCriterion->setCriterion($criterion);
$adGroupCriterion->setAdGroupId($adGroupId);
// Create an ad group criterion operation and add it the operations list.
$operation = new AdGroupCriterionOperation();
$operation->setOperand($adGroupCriterion);
$operation->setOperator(Operator::SET);
$operations = [$operation];

$result = $adGroupCriterionService->mutate($operations);

But when I execute this, nothing changes. The keywords matchType just stays the same, without any error or exception.

Does anyone know how to do this right, or where my mistake is?

Thanks so much in advance!
Lukas

Google Ads API Forum Advisor Prod

unread,
Jul 11, 2019, 11:43:28 PM7/11/19
to adwor...@googlegroups.com

Hi Lukas,

Thanks for posting your concern.

Upon checking the code, I observed 2 things in your code. Please see the following:
1.) The return values for the matchType field is capital letters. You may try to change the values you've set in the condition by changing the text cases into capital case.
2.) Assuming that one of the condition is satisfied. However, you are setting the same match type to a certain keyword. For example, the condition for keyword with broad match type is satisfied, however, the code will still set BROAD value to the keyword.

Please modify the code based on the provided observation and let me know if the issue persists.

Regards,
Ejay
Google Ads API Team



ref:_00D1U1174p._5001U8KsUa:ref
Reply all
Reply to author
Forward
0 new messages