How to get list of all campaigns for a given customer Id.

800 views
Skip to first unread message

ntdm...@gmail.com

unread,
Nov 22, 2016, 8:50:52 AM11/22/16
to AdWords API Forum
Hi,

I'm using CampaignField in selector to fetch campaign details, I would like to fetch campaigns only for a given account. how to validate this in selector equals method.


Vishal Vinayak (Adwords API Team)

unread,
Nov 22, 2016, 3:53:44 PM11/22/16
to AdWords API Forum
Hi,

In order to fetch data from a particular account, please ensure that the 10 digit AdWords account ID for that account is defined against the property clientCustomerId in your properties file. As an example, if you use the Java client library, you would need to define the relevant account ID here.  If you prefer to use an AdWords session object (instead of properties file, as mentioned here), you would need to update the value of the variable to the respective account ID. Once you have the account ID defined correctly, you should be able to fetch relevant data from that account. Lastly, please ensure that you use your AdWords client account ID (and not the manager account ID) as the clientCustomerId when trying to fetch campaings related information for an account. 

Regards,
Vishal, AdWords API Team

ntdm...@gmail.com

unread,
Nov 23, 2016, 3:17:20 AM11/23/16
to AdWords API Forum
Please let me know with an example in selector for campaign how to pass the clientCustomerId and fetch the values.
in equals condition what need to be passed please let me know.

// Create selector.
   SelectorBuilder builder = new SelectorBuilder();
   Selector selector = builder
       .fields(CampaignField.Id, CampaignField.Name, CampaignField.Status, CampaignField.CampaignTrialType)
      // .equals(customerId, "429-320-4263")
       .orderAscBy(CampaignField.Name)
       .offset(offset)
       .limit(PAGE_SIZE)
      
       .build();

ntdm...@gmail.com

unread,
Nov 23, 2016, 8:10:08 AM11/23/16
to AdWords API Forum

I would like to fetch all campaigns for a given account.How to fetch account details i know, but how to fetch all the campaigns for a particular account I'm not getting.

I would like to pass account Id and get the list of campaigns under that account. ihope my question is clear.

Example: for account                    camapaign 
                     123456789               123654789,etc

Please provide me selector for this.
 SelectorBuilder builder = new SelectorBuilder();
    Selector selector = builder
        .fields(CampaignField.Id, CampaignField.Name, CampaignField.Status, CampaignField.CampaignTrialType)
.equals (what to be passed here ,123456789)

On Tuesday, November 22, 2016 at 2:53:44 PM UTC-6, Vishal Vinayak (Adwords API Team) wrote:

Vishal Vinayak (Adwords API Team)

unread,
Nov 23, 2016, 11:52:59 AM11/23/16
to AdWords API Forum
Hi,

There is no provision to pass an AdWords account ID in your selector. As explained in my previous response, all you need to get started is to define your 10 digit AdWords account ID as the clientCustomerId in your local properties file. If you prefer to pass the client customer ID at runtime, you can do so with an AdWords Session object as follows:

AdWordsSession session = new AdWordsSession.Builder().fromFile().withOAuth2Credential(oAuth2Credential).build();
session.setClientCustomerID("123-456-7890");

To select an individual campaign, you can use a predicate such as follows:

    Predicate predicate = new Predicate();
    predicate.setField("CampaignId");
    predicate.setOperator(PredicateOperator.EQUALS);
    predicate.setValues(new String[]{"1234567890"});
    selector.setPredicates(new Predicate[] {predicate});

The above code will add the following to your SOAP request XML: 

<predicates> 
    <field>CampaignId</field> 
    <operator>EQUALS</operator> 
    <values>1234567890</values> 
</predicates>
Reply all
Reply to author
Forward
0 new messages