Add/Remove target location of campaign

120 views
Skip to first unread message

Sachin Kumar

unread,
Jun 27, 2016, 2:42:57 AM6/27/16
to AdWords API Forum
Hello Team,

Goal: To add/remove target location in campaign

I want to add location in campaign target location. To achieve this I am using this code:



$campaignCriterionService =
        $user->GetService('CampaignCriterionService', ADWORDS_VERSION);
        $user->SetClientCustomerId(base64_decode($ajaxData['clientId']));
        //echo '<pre>';
        //print_r($ajaxData);die();
        $campaignCriteria = array();
       
        // Create locations. The IDs can be found in the documentation or retrieved
        // with the LocationCriterionService.
        $location = new Location();
        $location->id = intval($ajaxData['Target']);   // location id e.g. 2840 etc.    
       
        //$campaignCriteria[] = new CampaignCriterion($ajaxData['CampaignId'], null, $location);
       
        $campaignCriteria[] = new CampaignCriterion(intval($ajaxData['CampaignId']), null, $location);

       
        // Create operations.
          $operations = array();
          foreach ($campaignCriteria as $campaignCriterion) {
            $operations[] = new CampaignCriterionOperation($campaignCriterion, 'ADD');
        }
       
        // Make the mutate request.
        $result = $campaignCriterionService->mutate($operations);


But this giving me following error:

<br />
<b>Fatal error</b>:  Uncaught SoapFault exception: [soap:Server] [EntityNotFound.INVALID_ID @ operations
[0].operand.campaignId; trigger:'CampaignId: 254533954'] in /home/bergstromdev/public_html/Google/Api
/Ads/Common/Lib/AdsSoapClient.php:216
Stack trace:
#0 /home/bergstromdev/public_html/Google/Api/Ads/Common/Lib/AdsSoapClient.php(216): SoapClient-&gt;__soapCall
('mutate', Array, NULL, Array, Array)
#1 /home/bergstromdev/public_html/Google/Api/Ads/AdWords/v201603/CampaignCriterionService.php(7969):
 AdsSoapClient-&gt;__soapCall('mutate', Array)
#2 /home/bergstromdev/public_html/lib/Targetting.class.php(42): CampaignCriterionService-&gt;mutate(Array
)
#3 /home/bergstromdev/public_html/ajaxCall.php(62): Targetting-&gt;addLocationTarget(Object(AdWordsUser
), Array)
#4 {main}
  thrown in <b>/home/bergstromdev/public_html/Google/Api/Ads/Common/Lib/AdsSoapClient.php</b> on line
 <b>216</b><br />



Kindly guide me how I can escape these errors. I pick this code from examples provided in the php library



Peter Oliquino

unread,
Jun 27, 2016, 3:06:40 AM6/27/16
to AdWords API Forum
Hi Sachin,

You are getting this error as a result of operating with the ID of an entity that is either already removed or belongs to a different account. In this case, the trigger is the CampaignId = 254533954. You could check for the campaigns existing and non-existing in your account using this example and retry your code.

Thanks,
Peter
AdWords API Team

Sachin Kumar

unread,
Jun 27, 2016, 3:21:58 AM6/27/16
to adwordsapiadv...@google.com, AdWords API Forum
Hello Peter,

Thanks for your reply.

I am able to see all campaign of an account and find the targeted campaign Id.




I am not getting what wrong I am doing? Please have a look and suggest what need to be done.


Thanks & Regards
Sachin

--
--
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
Also find us on our blog and Google+:
https://googleadsdeveloper.blogspot.com/
https://plus.google.com/+GoogleAdsDevelopers/posts
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
 
You received this message because you are subscribed to the Google
Groups "AdWords API Forum" group.
To post to this group, send email to adwor...@googlegroups.com
To unsubscribe from this group, send email to
adwords-api...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/adwords-api?hl=en
---
You received this message because you are subscribed to a topic in the Google Groups "AdWords API Forum" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/adwords-api/JN9hOETlc-w/unsubscribe.
To unsubscribe from this group and all its topics, send an email to adwords-api...@googlegroups.com.
Visit this group at https://groups.google.com/group/adwords-api.
To view this discussion on the web visit https://groups.google.com/d/msgid/adwords-api/5003ba65-c1f8-434f-bdc6-06009f87331d%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--
Thanks & Regards
Sachin Kumar
+91-9027575460
campaigns.png

Peter Oliquino

unread,
Jun 27, 2016, 3:29:07 AM6/27/16
to AdWords API Forum, adwordsapiadv...@google.com
Hi Sachin, 

Could you provide the SOAP request and response of the operation? Please use Reply privately to author in doing so.

Thanks and regards,
Peter
AdWords API Team

Sachin Kumar

unread,
Jun 27, 2016, 7:11:54 AM6/27/16
to AdWords API Forum
Hello Peter,

Its worked now. I rearrange sequence of these two lines:

$campaignCriterionService =
        $user->GetService('
CampaignCriterionService', ADWORDS_VERSION);
        $user->SetClientCustomerId(base64_decode($ajaxData['clientId']));


Now working fine. Thank you for your response and guidance.
 :):)
Reply all
Reply to author
Forward
0 new messages