ErikEvenson / googleads-node-lib

17 stars 23 forks source link

How to use TrafficEstimatorService? #2

Open mz3 opened 8 years ago

mz3 commented 8 years ago

I love that someone is working on a proper adwords api library for node. I can't get TrafficEstimatorService to work though. Could you add an example or some documentation?

var selector = new AdWords.Selector.model({
  fields: {
    campaignEstimateRequests: [
      {
        adGroupEstimateRequests: [
          {
            keywordEstimateRequests: [
              {
                keyword: {
                  'cm:text': 'homes',
                  'cm:matchType': 'PHRASE'
                },
                maxCpc: {'cm:microAmount': 10000000}
              }
            ]
          }
        ]
      }
    ]
  },
  ordering: [{field: 'Name', sortOrder: 'ASCENDING'}],
  paging: {startIndex: 0, numberResults: 100}
});

service.get(clientCustomerId, selector, function(err, results) {
  //if (err) console.log(err);
  console.log(JSON.stringify(results, null, 2));
});

Gives

SOAP ERROR:
 <soap:Envelope 
  xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
  <soap:Body>
    <soap:Fault>
      <faultcode>soap:Client</faultcode>
      <faultstring>Unmarshalling Error: cvc-complex-type.2.4.a: Invalid content was found starting with element 'fields'. One of '{"https://adwords.google.com/api/adwords/o/v201509":campaignEstimateRequests}' is expected. </faultstring>
    </soap:Fault>
  </soap:Body>
</soap:Envelope>
ErikEvenson commented 8 years ago

I haven't done much work with this service. You don't need to the fields key though -- start with campaignEstimateRequests.

mz3 commented 8 years ago

If I remove fields and use the following:

var selector = new AdWords.Selector.model({

  campaignEstimateRequests: [
    {
      adGroupEstimateRequests: [
        {
          keywordEstimateRequests: [
            {
              keyword: {
                'cm:text': 'homes',
                'cm:matchType': 'PHRASE'
              },
              maxCpc: {'cm:microAmount': 10000000}
            }
          ]
        }
      ]
    }
  ],

  ordering: [{field: 'Name', sortOrder: 'ASCENDING'}],
  paging: {startIndex: 0, numberResults: 100}
});

I get:

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
  <soap:Body>
    <soap:Fault>
      <faultcode>soap:Client</faultcode>
      <faultstring>Unmarshalling Error: cvc-complex-type.2.4.a: Invalid content was found starting with element \'ordering\'. One of \'{"https://adwords.google.com/api/adwords/o/v201509":campaignEstimateRequests}\' is expected</faultstring>
    </soap:Fault>
  </soap:Body>
</soap:Envelope>