Yahoo! JAPAN Ads Script | Developer Center
日本語Ad group
・Add an ad group・Pause an ad group
・Set ad group bid
・Get all ad group
・Get all ad group by id
Add an ad group
function addAdGroup() {
const accountId = AdsUtilities.getCurrentAccountId();
const adGroupArray = [
{
adGroupName: 'adGroupNameAAA',
biddingStrategyConfiguration: {
biddingScheme: {
campaignBiddingStrategyType: 'CPC',
cpcBiddingScheme: {
cpc: 1000
},
},
},
campaignId: 1111111,
userStatus: 'ACTIVE',
}
];//Multiple selections are possible
const adGroups = Search.AdGroupService.add({
accountId: accountId,
operand: adGroupArray,
}).rval;
for (let i = 0; i < adGroups.values.length; i++) {
if (adGroups.values[i].operationSucceeded) {
let adGroup = adGroups.values[i].adGroup;
Logger.log('adGroupId-> ' + adGroup.adGroupId + ', adGroupName-> ' + adGroup.adGroupName
+ ', bidMaxCpc-> ' + adGroup.biddingStrategyConfiguration.biddingScheme.cpcBiddingScheme.cpc + ' has been added.');
} else {
let errorList = adGroups.values[i].errors;
errorList.forEach(function (element) {
if (element.code == 'I0001' && element.details[0].requestKey.includes('campaignId')) {
Logger.log('campaignId-> ' + element.details[0].requestValue + ' does not exsit.');
} else if (element.code == 'D0001' && element.details[0].requestKey.includes('adGroupName')) {
Logger.log('adGroupName-> ' + element.details[0].requestValue
+ ' is duplicate.');
} else {
Logger.log('adGroupName-> ' + adGroupArray[i].adGroupName + ' could not be stopped.');
}
});
}
}
}
Pause an ad group
function pauseAdGroup() {
const accountId = AdsUtilities.getCurrentAccountId();
const adGroupIds = [111111111, 222222222];//Empty when not specified
const adGroupsGet = Search.AdGroupService.get({
accountId: accountId,
adGroupIds: adGroupIds,
userStatuses: ['ACTIVE'],
}).rval;
if (adGroupsGet.totalNumEntries == 0) {
Logger.log('Target ID does not exist.');
return;
}
let adGroupArray = [];
for (let i = 0; i < adGroupsGet.values.length; i++) {
let adGroup = adGroupsGet.values[i].adGroup;
//New object to set
const setAdGroup = {
campaignId: adGroup.campaignId,
adGroupId: adGroup.adGroupId,
userStatus: 'PAUSED',
}
adGroupArray.push(setAdGroup);
}
const adGroupsSet = Search.AdGroupService.set({
accountId: accountId,
operand: adGroupArray,
}).rval;
for (let i = 0; i < adGroupsSet.values.length; i++) {
if (adGroupsSet.values[i].operationSucceeded) {
let adGroup = adGroupsSet.values[i].adGroup;
Logger.log('adGroupId-> ' + adGroup.adGroupId
+ ', adGroupName-> ' + adGroup.adGroupName + ' has been paused.');
} else {
Logger.log('adGroupId-> ' + adGroupIds[i] + ' could not be stopped.');
}
}
}
Set ad group bid
function setAdGroupBid(){
const accountId = AdsUtilities.getCurrentAccountId();
const adGroupIds = [111111111, 222222222];//Empty when not specified
const bidMaxCpc = 500;
const adGroupsGet = Search.AdGroupService.get({
accountId: accountId,
adGroupIds: adGroupIds,
}).rval;
if (adGroupsGet.totalNumEntries == 0) {
Logger.log('Target ID does not exist.');
return;
}
let adGroupArray = [];
for (let i = 0; i < adGroupsGet.values.length; i++) {
let adGroup = adGroupsGet.values[i].adGroup;
// create new object to set
let setAdGroup = {
accountId: accountId,
campaignId: adGroup.campaignId,
adGroupId: adGroup.adGroupId,
biddingStrategyConfiguration: {
biddingScheme: {
campaignBiddingStrategyType: 'CPC',
cpcBiddingScheme: {
cpc: bidMaxCpc
},
},
},
};
adGroupArray.push(setAdGroup);
}
const adGroupsSet = Search.AdGroupService.set({
accountId: accountId,
operand: adGroupArray,
}).rval;
for (let i = 0; i < adGroupsSet.values.length; i++) {
if (adGroupsSet.values[i].operationSucceeded) {
let adGroup = adGroupsSet.values[i].adGroup;
Logger.log('adGroupId-> ' + adGroup.adGroupId
+ ', adGroupName-> ' + adGroup.adGroupName
+ ' has been changed to budgetAmount-> ' + adGroup.biddingStrategyConfiguration.biddingScheme.cpcBiddingScheme.cpc);
} else {
Logger.log('adGroupName-> ' + adGroupsGet.values[i].adGroup.adGroupName
+ ' budget could not be changed.');
}
}
}
Get all ad group
function getAllAdGroup(){
const accountId = AdsUtilities.getCurrentAccountId();
const adGroups = Search.AdGroupService.get({
accountId: accountId,
numberResults: 10000,//Max adGroups you can get is 10000.
}).rval;
if (adGroups.totalNumEntries == 0) {
Logger.log('Ad group does not exist.');
return;
}
for (let i = 0; i < adGroups.values.length; i++) {
let adGroup = adGroups.values[i].adGroup;
Logger.log('adGroupId-> ' + adGroup.adGroupId
+ ', adGroupName-> ' + adGroup.adGroupName);
}
}
Get all ad group by id
function getAllAdGroupById(){
const accountId = AdsUtilities.getCurrentAccountId();
const adGroupIds = [111111111, 222222222];//Multiple selections are possible
const adGroups = Search.AdGroupService.get({
accountId: accountId,
adGroupIds: adGroupIds,
}).rval;
if (adGroups.totalNumEntries == 0) {
Logger.log('Target ID does not exist.');
return;
}
for (let i = 0; i < adGroups.values.length; i++) {
let adGroup = adGroups.values[i].adGroup;
Logger.log('adGroupId-> ' + adGroup.adGroupId
+ ', adGroupName-> ' + adGroup.adGroupName);
}
}