Check if keyword exists, how to

123 views
Skip to first unread message

Simon Thomsen

unread,
Jan 12, 2017, 1:04:40 AM1/12/17
to AdWords API Forum
Hello,
Is there a way to check if a specific keyword exists across the whole account, without looping through all keywords on the account?

Joyce Lava

unread,
Jan 12, 2017, 1:37:54 AM1/12/17
to AdWords API Forum
Hi Simon,

Since keywords are at campaign/adGroup level, and these are specific to each account, there is no way to get the keywords at account level.

However, you can identify if a keyword exists in campaign level by using CampaignCriterionService.get with criterion as Keyword.

Regards,
Joyce, AdWords API Team

Simon Thomsen

unread,
Jan 14, 2017, 11:09:15 AM1/14/17
to AdWords API Forum
Do you have some kind of simple working sample for this.
I've tried to receive true/false if a keyword exists, but the API seems a little bit hard to figured out.

Hope you can help.

Joyce Lava

unread,
Jan 16, 2017, 1:06:28 AM1/16/17
to AdWords API Forum
Hi Simon,

Apologies if I was not so clear in my previous response. Campaign-level keywords (CampaignCriterionService) means NegativeCampaignCriterion. That is, the keyword at campaign level are negative keywords. You may check the allowable negative criteria and targeting criteria at campaign level in the link provided. If you need to check if negative keywords exist in campaign level, you may refer to the below SOAP logs example:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <soapenv:Header>
        <ns1:RequestHeader xmlns:ns1="https://adwords.google.com/api/adwords/cm/v201609" soapenv:mustUnderstand="0">
            <ns1:clientCustomerId>YOUR_CLIENT_CUSTOMER_ID</ns1:clientCustomerId>
            <ns1:developerToken>YOUR_DEVELOPER_TOKEN</ns1:developerToken>
            <ns1:userAgent>YOUR_USER_AGENT</ns1:userAgent>
            <ns1:validateOnly>false</ns1:validateOnly>
            <ns1:partialFailure>false</ns1:partialFailure>
        </ns1:RequestHeader>
    </soapenv:Header>
    <soapenv:Body>
        <get xmlns="https://adwords.google.com/api/adwords/cm/v201609">
            <serviceSelector>
                <fields>Id</fields>
                <fields>CriteriaType</fields>
                <fields>KeywordMatchType</fields>
                <fields>KeywordText</fields>
                <predicates>
                    <field>CampaignId</field>
                    <operator>IN</operator>
                    <values>YOUR_CAMPAIGN_ID</values>
                </predicates>
                <predicates>
                    <field>CriteriaType</field>
                    <operator>IN</operator>
                    <values>KEYWORD</values>
                </predicates>
                <predicates>
                    <field>KeywordText</field>
                    <operator>EQUALS</operator>
                    <values>YOUR_KEYWORD_TEXT</values>
                </predicates>
                <ordering>
                    <field>KeywordText</field>
                    <sortOrder>ASCENDING</sortOrder>
                </ordering>
                <paging>
                    <startIndex>0</startIndex>
                    <numberResults>100</numberResults>
                </paging>
            </serviceSelector>
        </get>
    </soapenv:Body>
</soapenv:Envelope>

[main] INFO com.google.api.ads.adwords.lib.client.AdWordsServiceClient.soapXmlLogger - SOAP Response:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
    <soap:Header>
        <ResponseHeader xmlns="https://adwords.google.com/api/adwords/cm/v201609">
            <requestId>REQUEST_ID</requestId>
            <serviceName>CampaignCriterionService</serviceName>
            <methodName>get</methodName>
            <operations>1</operations>
            <responseTime>287</responseTime>
        </ResponseHeader>
    </soap:Header>
    <soap:Body>
        <getResponse xmlns="https://adwords.google.com/api/adwords/cm/v201609">
            <rval>
                <totalNumEntries>1</totalNumEntries>
                <Page.Type>CampaignCriterionPage</Page.Type>
                <entries xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="NegativeCampaignCriterion">
                    <campaignId>YOUR_CAMPAIGN_ID</campaignId>
                    <isNegative>true</isNegative>
                    <criterion xsi:type="Keyword">
                        <id>ID</id>
                        <type>KEYWORD</type>
                        <Criterion.Type>Keyword</Criterion.Type>
                        <text>YOUR_KEYWORD_TEXT</text>
                        <matchType>BROAD</matchType>
                    </criterion>
                    <CampaignCriterion.Type>NegativeCampaignCriterion</CampaignCriterion.Type>
                </entries>
            </rval>
        </getResponse>
    </soap:Body>
</soap:Envelope>

Additionally, biddable and negative keywords criteria are both at adGroup level (AdGroupCriterionService). You may refer to the sample code GetKeywords that shows how to get the keywords in an adGroupId. You may add a filter (e.g. KeywordText, as shown in the above SOAP logs).
Reply all
Reply to author
Forward
0 new messages