adwords-api-sma
v1.0.4
Published
Unofficial SDK for Google Adwords API
Downloads
11
Readme
Google AdWords API (v201705) Node SDK
An unofficial SDK for Google AdWords API
Installation
npm install adwords-api-sma
Authentication
This library's services get Google AdWords credentials from the following sources in priority order:
- From passed in options values:
var AdWords = require('adwords-api-sma');
var Service = new AdWords.ManagedCustomerService({
ADWORDS_CLIENT_ID: 'your client id',
ADWORDS_CLIENT_CUSTOMER_ID: 'your client customer id',
ADWORDS_DEVELOPER_TOKEN: 'your developer token'
ADWORDS_REFRESH_TOKEN: 'your refresh token',
ADWORDS_SECRET: 'your secret',
ADWORDS_USER_AGENT: 'your user agent',
});
- Via environment variables which are either present or loaded via a
.env
file. An example.env
file is provided in.env-example
.
Failure to provide credentials will cause the library to throw a configuration error.
Using the library
Below are some examples. More examples are present in integration tests and the gulp tasks.
ManagedCustomerService
Setting up the ManagedCustomerService:
var AdWords = require('adwords-api-sma');
var service = new AdWords.ManagedCustomerService();
var clientCustomerId = 'the client customer ID you are interested in';
Getting your managed customers:
var selector = new AdWords.Selector.model({
dateRange: {min: '19700101', max: '20380101'},
fields: service.selectable,
ordering: [{field: 'Name', sortOrder: 'ASCENDING'}],
paging: {startIndex: 0, numberResults: 100},
predicates: []
});
service.get(clientCustomerId, selector, function(err, results) {
if (err) console.log(err);
else console.log(JSON.stringify(results, null, 2));
});
Adding a managed customer:
var operand = new service.Model({
name: 'the name of the customer',
currencyCode: 'USD',
dateTimeZone: 'America/Chicago'
});
service.mutateAdd(
clientCustomerId,
operand,
function(err, results) {
if (err) console.log(err);
else console.log(JSON.stringify(results, null, 2));
}
);
Hiding a managed customer:
var operand = new service.ManagedCustomerLink({
clientCustomerId: clientCustomerId,
isHidden: true,
managerCustomerId: managerCustomerId
});
service.mutateLinkSet(
clientCustomerId,
operand,
function(err, results) {
if (err) console.log(err);
else console.log(JSON.stringify(results, null, 2));
cb(err);
}
);
CampaignService
Setting up the CampaignService:
var AdWords = require('adwords-api-sma');
var service = new AdWords.CampaignService();
var clientCustomerId = 'the client customer ID you are interested in';
Getting your campaigns:
var selector = new AdWords.Selector.model({
dateRange: {min: '19700101', max: '20380101'},
fields: service.selectable,
ordering: [{field: 'Name', sortOrder: 'ASCENDING'}],
paging: {startIndex: 0, numberResults: 100},
predicates: []
});
service.get(clientCustomerId, selector, function(err, results) {
if (err) console.log(err);
else console.log(JSON.stringify(results, null, 2));
});
AdGroupService
Setting up the AdGroupService:
var AdWords = require('adwords-api-sma');
var service = new AdWords.AdGroupService();
var clientCustomerId = 'the client customer ID you are interested in';
Getting AdGroups:
var selector = new AdWords.Selector.model({
fields: service.selectable,
ordering: [{field: 'Name', sortOrder: 'ASCENDING'}],
paging: {startIndex: 0, numberResults: 100}
});
service.get(clientCustomerId, selector, function(err, results) {
if (err) console.log(err);
else console.log(JSON.stringify(results, null, 2));
});
AccountLabelService
Setting up the AccountLabelService:
var AdWords = require('adwords-api-sma');
var service = new AdWords.AccountLabelService();
var clientCustomerId = 'the client customer ID you are interested in';
Getting account labels:
var selector = new AdWords.Selector.model({
fields: service.selectable,
ordering: [{field: 'Name', sortOrder: 'ASCENDING'}],
paging: {startIndex: 0, numberResults: 100}
});
service.get(clientCustomerId, selector, function(err, results) {
if (err) console.log(err);
else console.log(JSON.stringify(results, null, 2));
});
Adding an account label:
var operand = new service.Model({
name: 'the name of the account label'
});
service.mutateAdd(
clientCustomerId,
operand,
function(err, results) {
if (err) console.log(err);
else console.log(JSON.stringify(results, null, 2));
}
);
Removing an account label:
var operand = new service.Model({
id: 'the id of the account label'
});
service.mutateRemove(
clientCustomerId,
operand,
function(err, results) {
if (err) console.log(err);
else console.log(JSON.stringify(results, null, 2));
}
);
Changing the name of an account label:
var operand = new service.Model({
id: 'the id of the account label',
name: 'the new name of the account label'
});
service.mutateSet(
clientCustomerId,
operand,
function(err, results) {
if (err) console.log(err);
else console.log(JSON.stringify(results, null, 2));
}
);
Credits
Erik Evenson googleads-node-lib (Fork)
License
The MIT License (MIT)
Copyright (c) 2016 Talha Asad
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.