Getting Google Ads API keyword_plan_idea_error: The input has an invalid value
$requestOptionalArgs = []; $requestOptionalArgs['keywordSeed'] = new KeywordSeed(['keywords' => $keywords]); $keywordPlanIdeaServiceClient->generateKeywordIdeas([ 'language' => ResourceNames::forLanguageConstant(1000), // English 'customerId' => $customerId, 'geoTargetConstants' => $geoTargetConstants, 'keywordPlanNetwork' => KeywordPlanNetwork::GOOGLE_SEARCH ] + $requestOptionalArgs);
The above code is working fine if the $keywords array size is not more than 20. If I add the 21st keyword to the $keywords array then it's throwing the below error. keyword_plan_idea_error: The input has an invalid value.
Google Ads API has a limit of 20 keywords per request. You'll need to separate your keywords into chunks and loop through them.
Something like this:
<?php $keywords = []; // Create multiple arrays to pass through Google Ads API $chunk = array_chunk($keywords, 20, true); foreach ($chunk as $piece) { $requestOptionalArgs = []; $requestOptionalArgs['keywordSeed'] = new KeywordSeed(['keywords' => $piece]); $keywordPlanIdeaServiceClient->generateKeywordIdeas([ 'language' => ResourceNames::forLanguageConstant(1000), // English 'customerId' => $customerId, 'geoTargetConstants' => $geoTargetConstants, 'keywordPlanNetwork' => KeywordPlanNetwork::GOOGLE_SEARCH ] + $requestOptionalArgs); }