TargetingIdeaService - pythonlib example code not working correctly - INVALID_SEARCH_PARAMETERS

772 views
Skip to first unread message

Cameron Warren

unread,
Sep 21, 2018, 3:12:28 PM9/21/18
to AdWords API and Google Ads API Forum
Running code to pull data from the TargetingIdeaService SOAP api. I'm using the example exactly as written of the google github repository (see code below).

Oauth and everything else working fine. Here is the error:

suds.WebFault: Server raised fault: '[TargetingIdeaError.INVALID_SEARCH_PARAMETERS @ selector.searchParameters.searchParameters[0]; trigger:'RelatedToQuerySearchParameter']'




If anyone know's what's going on here - you're help is greatly appreciated!




AD_GROUP_ID = None
PAGE_SIZE = 100

def main(client, ad_group_id=None):
  # Initialize appropriate service.
  targeting_idea_service = client.GetService(
      'TargetingIdeaService', version='v201802')

  # Construct selector object and retrieve related keywords.
  selector = {
      'ideaType': 'KEYWORD',
      'requestType': 'IDEAS'
  }

  selector['requestedAttributeTypes'] = [
      'KEYWORD_TEXT', 'SEARCH_VOLUME', 'CATEGORY_PRODUCTS_AND_SERVICES']

  offset = 0
  selector['paging'] = {
      'startIndex': str(offset),
      'numberResults': str(PAGE_SIZE)
  }

  selector['searchParameters'] = [{
      'xsi_type': 'RelatedToQuerySearchParameter',
      'queries': ['baseball']
  }]

  # # Language setting (optional).
  # selector['searchParameters'].append({
  #     # The ID can be found in the documentation:
  #     'xsi_type': 'LanguageSearchParameter',
  #     'languages': [{'id': '1000'}]
  # })

  # # Network search parameter (optional)
  # selector['searchParameters'].append({
  #     'xsi_type': 'NetworkSearchParameter',
  #     'networkSetting': {
  #         'targetGoogleSearch': True,
  #         'targetSearchNetwork': False,
  #         'targetContentNetwork': False,
  #         'targetPartnerSearchNetwork': False
  #     }
  # })

  # # Use an existing ad group to generate ideas (optional)
  # if ad_group_id is not None:
  #   selector['searchParameters'].append({
  #       'xsi_type': 'SeedAdGroupIdSearchParameter',
  #       'adGroupId': ad_group_id
  #   })

  more_pages = True
  while more_pages:
    page = targeting_idea_service.get(selector)

    # Display results.
    if 'entries' in page:
      for result in page['entries']:
        attributes = {}
        for attribute in result['data']:
          attribute_value = attribute['value']
          if 'value' in attribute_value:
            attributes[attribute['key']] = attribute_value['value']
          else:
            attributes[attribute['key']] = []
        print ('Keyword with "%s" text and average monthly search volume '
               '"%s" was found with Products and Services categories: %s.'
               % (attributes['KEYWORD_TEXT'],
                  attributes['SEARCH_VOLUME'],
                  attributes['CATEGORY_PRODUCTS_AND_SERVICES']))
      print
    else:
      print 'No related keywords were found.'
    offset += PAGE_SIZE
    selector['paging']['startIndex'] = str(offset)
    more_pages = offset < int(page['totalNumEntries'])


if __name__ == '__main__':
  # Initialize client object.
  adwords_client = adwords.AdWordsClient.LoadFromStorage()

  main(adwords_client)


Teja Makani

unread,
Sep 21, 2018, 4:54:03 PM9/21/18
to AdWords API and Google Ads API Forum
Hello Cameron, 

The TargetingIdeaError.INVALID_SEARCH_PARAMETERS error occurs when a SearchParameter does not match the IdeaType specified in the TargetingIdeaSelector or is otherwise invalid. Looks like you are trying to run get_keyword_ideas.py. I ran the same example commenting out the optional lines and able to fetch the results for keyword ideas. Even I ran your code and it works fine. If the problem persists could you please share the SOAP logs(request and response) without redacting any information. Please follow the instruction shown in this README.md file to enable logging. 

Regards,
Sai Teja, AdWords API Team.

Cameron Warren

unread,
Sep 24, 2018, 4:41:15 PM9/24/18
to adwor...@googlegroups.com
Here is the SOAP log:










[2018-09-24 09:59:58,399 - googleads.soap - INFO] Request made: Service: "TargetingIdeaService" Method: "get" URL: "https://adwords.google.com/api/adwords/o/v201802/TargetingIdeaService"


[2018-09-24 09:59:58,399 - googleads.soap - DEBUG] Outgoing request: {'SOAPAction': '""', 'Content-Type': 'text/xml; charset=utf-8', 'authorization': 'REDACTED'}


<soap-env:Envelope xmlns:soap-env="http://schemas.xmlsoap.org/soap/envelope/">


  <soap-env:Header>


    <ns0:RequestHeader xmlns:ns0="https://adwords.google.com/api/adwords/o/v201802">


      <ns1:developerToken xmlns:ns1="https://adwords.google.com/api/adwords/cm/v201802">xxxxxxxxxxxxxxxx</ns1:developerToken>


      <ns2:userAgent xmlns:ns2="https://adwords.google.com/api/adwords/cm/v201802">unknown (AwApi-Python, googleads/14.1.0, Python/3.6.3, zeep)</ns2:userAgent>


      <ns3:validateOnly xmlns:ns3="https://adwords.google.com/api/adwords/cm/v201802">false</ns3:validateOnly>


      <ns4:partialFailure xmlns:ns4="https://adwords.google.com/api/adwords/cm/v201802">false</ns4:partialFailure>


    </ns0:RequestHeader>


  </soap-env:Header>


  <soap-env:Body>


    <ns0:get xmlns:ns0="https://adwords.google.com/api/adwords/o/v201802">


      <ns0:selector>


        <ns0:searchParameters xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ns0:RelatedToQuerySearchParameter">


          <ns0:queries>space cruise</ns0:queries>


        </ns0:searchParameters>


        <ns0:ideaType>KEYWORD</ns0:ideaType>


        <ns0:requestType>IDEAS</ns0:requestType>


        <ns0:requestedAttributeTypes>KEYWORD_TEXT</ns0:requestedAttributeTypes>


        <ns0:requestedAttributeTypes>SEARCH_VOLUME</ns0:requestedAttributeTypes>


        <ns0:requestedAttributeTypes>CATEGORY_PRODUCTS_AND_SERVICES</ns0:requestedAttributeTypes>


        <ns0:paging>


          <ns1:startIndex xmlns:ns1="https://adwords.google.com/api/adwords/cm/v201802">0</ns1:startIndex>


          <ns2:numberResults xmlns:ns2="https://adwords.google.com/api/adwords/cm/v201802">100</ns2:numberResults>


        </ns0:paging>


      </ns0:selector>


    </ns0:get>


  </soap-env:Body>


</soap-env:Envelope>




[2018-09-24 09:59:58,927 - googleads.soap - DEBUG] Incoming response:


b'<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">\n  <soap:Header>\n    <ResponseHeader xmlns:ns2="https://adwords.google.com/api/adwords/cm/v201802" xmlns="https://adwords.google.com/api/adwords/o/v201802">\n      <ns2:requestId>000576a014c2e8600aa35c0a9b05e67e</ns2:requestId>\n      <ns2:serviceName>TargetingIdeaService</ns2:serviceName>\n      <ns2:methodName>get</ns2:methodName>\n      <ns2:operations>1</ns2:operations>\n      <ns2:responseTime>147</ns2:responseTime>\n    </ResponseHeader>\n  </soap:Header>\n  <soap:Body>\n    <soap:Fault>\n      <faultcode>soap:Server</faultcode>\n      <faultstring>[TargetingIdeaError.INVALID_SEARCH_PARAMETERS @ selector.searchParameters.searchParameters[0]; trigger:\'RelatedToQuerySearchParameter\']</faultstring>\n      <detail>\n        <ApiExceptionFault xmlns="https://adwords.google.com/api/adwords/o/v201802" xmlns:ns2="https://adwords.google.com/api/adwords/cm/v201802">\n          <ns2:message>[TargetingIdeaError.INVALID_SEARCH_PARAMETERS @ selector.searchParameters.searchParameters[0]; trigger:\'RelatedToQuerySearchParameter\']</ns2:message>\n          <ns2:ApplicationException.Type>ApiException</ns2:ApplicationException.Type>\n          <ns2:errors xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="TargetingIdeaError">\n            <ns2:fieldPath>selector.searchParameters.searchParameters[0]</ns2:fieldPath>\n            <ns2:fieldPathElements>\n              <ns2:field>selector</ns2:field>\n            </ns2:fieldPathElements>\n            <ns2:fieldPathElements>\n              <ns2:field>searchParameters</ns2:field>\n            </ns2:fieldPathElements>\n            <ns2:fieldPathElements>\n              <ns2:field>searchParameters</ns2:field>\n              <ns2:index>0</ns2:index>\n            </ns2:fieldPathElements>\n            <ns2:trigger>RelatedToQuerySearchParameter</ns2:trigger>\n            <ns2:errorString>TargetingIdeaError.INVALID_SEARCH_PARAMETERS</ns2:errorString>\n            <ns2:ApiError.Type>TargetingIdeaError</ns2:ApiError.Type>\n            <reason>INVALID_SEARCH_PARAMETERS</reason>\n          </ns2:errors>\n        </ApiExceptionFault>\n      </detail>\n    </soap:Fault>\n  </soap:Body>\n</soap:Envelope>\n'


[2018-09-24 09:59:58,928 - googleads.soap - WARNING] Error summary: {'faultMessage': "[TargetingIdeaError.INVALID_SEARCH_PARAMETERS @ selector.searchParameters.searchParameters[0]; trigger:'RelatedToQuerySearchParameter']", 'requestId': '000576a014c2e8600aa35c0a9b05e67e', 'serviceName': 'TargetingIdeaService', 'methodName': 'get', 'operations': '1', 'responseTime': '147'}


Traceback (most recent call last):


  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/googleads/common.py", line 1377, in MakeSoapRequest


    *packed_args, _soapheaders=soap_headers)['body']['rval']


  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/zeep/proxy.py", line 42, in __call__


    self._op_name, args, kwargs)


  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/zeep/wsdl/bindings/soap.py", line 132, in send


    return self.process_reply(client, operation_obj, response)


  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/zeep/wsdl/bindings/soap.py", line 194, in process_reply


    return self.process_error(doc, operation)


  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/zeep/wsdl/bindings/soap.py", line 299, in process_error


    detail=fault_node.find('detail'))


zeep.exceptions.Fault: [TargetingIdeaError.INVALID_SEARCH_PARAMETERS @ selector.searchParameters.searchParameters[0]; trigger:'RelatedToQuerySearchParameter']




During handling of the above exception, another exception occurred:




Traceback (most recent call last):


  File "keyword_planner.py", line 94, in <module>


    main(adwords_client, int(AD_GROUP_ID) if AD_GROUP_ID.isdigit() else None)


  File "keyword_planner.py", line 68, in main


    page = targeting_idea_service.get(selector)


  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/googleads/common.py", line 1389, in MakeSoapRequest


    e.detail, errors=error_list, message=e.message)


googleads.errors.GoogleAdsServerFault: [TargetingIdeaError.INVALID_SEARCH_PARAMETERS @ selector.searchParameters.searchParameters[0]; trigger:'RelatedToQuerySearchParameter']

Cameron Warren

unread,
Sep 24, 2018, 4:41:15 PM9/24/18
to AdWords API and Google Ads API Forum
Thanks Teja,

What version of Python are you running? 

Do I need to have any other packages installed besides googleads? Are you sure you made no changes to my base code when you ran it?

I'm still getting the same error:

File "keyword_planner.py", line 93, in <module>

    main(adwords_client)

  File "keyword_planner.py", line 64, in main

    page = targeting_idea_service.get(selector)

  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/googleads/common.py", line 1389, in MakeSoapRequest

    e.detail, errors=error_list, message=e.message)

googleads.errors.GoogleAdsServerFault: [TargetingIdeaError.INVALID_SEARCH_PARAMETERS @ selector.searchParameters.searchParameters[0]; trigger:'RelatedToQuerySearchParameter']


On Friday, September 21, 2018 at 2:54:03 PM UTC-6, Teja Makani wrote:

Cameron Warren

unread,
Sep 24, 2018, 4:41:15 PM9/24/18
to adwor...@googlegroups.com
Still not working. Here are the logs:









[2018-09-24 09:59:58,399 - googleads.soap - INFO] Request made: Service: "TargetingIdeaService" Method: "get" URL: "https://adwords.google.com/api/adwords/o/v201802/TargetingIdeaService"


[2018-09-24 09:59:58,399 - googleads.soap - DEBUG] Outgoing request: {'SOAPAction': '""', 'Content-Type': 'text/xml; charset=utf-8', 'authorization': 'REDACTED'}


<soap-env:Envelope xmlns:soap-env="http://schemas.xmlsoap.org/soap/envelope/">


  <soap-env:Header>


    <ns0:RequestHeader xmlns:ns0="https://adwords.google.com/api/adwords/o/v201802">


      <ns1:developerToken xmlns:ns1="https://adwords.google.com/api/adwords/cm/v201802">xxxxxxxxxxxxxxxxxxx</ns1:developerToken>

  File "keyword_planner.py", line 68, in main


    page = targeting_idea_service.get(selector)


  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/googleads/common.py", line 1389, in MakeSoapRequest


    e.detail, errors=error_list, message=e.message)


googleads.errors.GoogleAdsServerFault: [TargetingIdeaError.INVALID_SEARCH_PARAMETERS @ selector.searchParameters.searchParameters[0]; trigger:'RelatedToQuerySearchParameter']




On Friday, September 21, 2018 at 2:54:03 PM UTC-6, Teja Makani wrote:

Teja Makani

unread,
Sep 25, 2018, 2:17:53 PM9/25/18
to AdWords API and Google Ads API Forum
Hello Cameron,

According to the AdWords API forum rules, you shouldn't be posting any account related data publicly, hence I redacted the sensitive information from your logs and re-posted it. If you suspect that your developer token is compromised, please follow the steps shown in this guide to reset the developer token.

After taking a look at the SOAP logs, it looks like the clientCustomerId field is missing in the headers. This will happen when you are not specifying the clientCustomerId in your googleads.yaml file. Please specify the clientCustomerId and run the program again. 

For example in the SOAP logs the field looks like below:
<ns1:clientCustomerId xmlns:ns1="https://adwords.google.com/api/adwords/cm/v201802">123-456-7890</ns1:clientCustomerId>

If the problem persists, please share the entire SOAP logs without redacting any information. You could reply privately to the author option while sharing the requested data.

Cameron Warren

unread,
Sep 25, 2018, 4:10:14 PM9/25/18
to AdWords API and Google Ads API Forum
Teja,

Thanks for redacting that information. That was an oversight on my end. 

I see the issue now. I will include the customerid and try again.

Thank you.

sulek...@sulekha.net

unread,
Nov 14, 2018, 12:03:34 PM11/14/18
to AdWords API and Google Ads API Forum
Hi ,

I have setup the googleads.yaml file and i am getting below error. Please help on this.

I am using python.3.6 version.

Error summary: {'faultMessage': "[TargetingIdeaError.INVALID_SEARCH_PARAMETERS @ selector.searchParameters.searchParameters[0]; trigger:'LanguageSearchParameter', TargetingIdeaError.INVALID_SEARCH_PARAMETERS @ selector.searchParameters.searchParameters[1]; trigger:'RelatedToQuerySearchParameter', TargetingIdeaError.INVALID_SEARCH_PARAMETERS @ selector.searchParameters.searchParameters[2]; trigger:'NetworkSearchParameter']", 'requestId': '00057a9f2e9dab780add8641cc0b4d94', 'serviceName': 'TargetingIdeaService', 'methodName': 'get', 'operations': '1', 'responseTime': '152'}

Teja Makani

unread,
Nov 14, 2018, 4:34:26 PM11/14/18
to AdWords API and Google Ads API Forum
Hello,

The TargetingIdeaError.INVALID_SEARCH_PARAMETERS error occurs when a SearchParameter does not match the IdeaType specified in the TargetingIdeaSelector or is otherwise invalid. You could refer to the code sample get_keyword_ideas.py. If the problem persists could you please share the SOAP logs(request and response) of the operation performing without redacting any information? Please follow the instruction shown in this README.md file to enable logging. You could use reply privately to the author option while sharing the details requested. 


Regards,
Sai Teja, AdWords API Team.

On Friday, September 21, 2018 at 3:12:28 PM UTC-4, Cameron Warren wrote:
Reply all
Reply to author
Forward
0 new messages