const endpoint = 'https://googleads.googleapis.com/v1/customers/${customer_id}/campaigns:mutate';
const operations = { "operations": [
{
"create": {
"name": "new API campaign 1",
"status": "PAUSE",
"start_date": "01/06/2019",
"end_date": "01/09/2019"
}
}
]
};
--
--
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
Also find us on our blog:
https://googleadsdeveloper.blogspot.com/
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
You received this message because you are subscribed to the Google
Groups "AdWords API and Google Ads 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 the Google Groups "AdWords API and Google Ads API Forum" group.
To unsubscribe from this group and stop receiving emails from it, send an email to adwords-api...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/adwords-api/64091221-f563-4793-a70b-8eb91e2fe827%40googlegroups.com.
'use strict';
const rp = require('request-promise-native');
const accessToken = '************'; // replace correctly
const customer_id = 1234567890; // replace correctly
const putCampaign = async () => {
try {
const url = `https://googleads.googleapis.com/v1/customers/${customer_id}/campaigns:mutate`;
const operations = {
'operations': [
{
'create': {
'name': 'new Campaign 1',
'advertising_channel_type': 'SEARCH',
'status': 'PAUSED',
'campaign_budget': 100000,
'start_date': '20190601',
'end_date': '20190701',
'network_settings': {
'target_google_search': true,
'target_search_network': false,
'target_content_network': false,
'target_partner_search_network': false
},
'dynamic_search_ads_setting': {
'domain_name': 'fooooo.com',
'language_code': 'jp',
'use_supplied_urls_only': true,
'labels': ['test']
},
'bidding_strategy_type': 'ENHANCED_CPC',
'payment_mode': 'CLICKS'
}
}
]
};
const options = {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': 'Bearer ' + accessToken,
'developer-token': '************', // replace correctly
'login-customer-id': 6789012345, // replace correctly
},
data: operations,
json: true,
resolveWithFullResponse: true
};
const res = await rp(url, options);
if (res.statusCode === 200) console.log(res.statusCode, res.statusMessage, res.body);
} catch (err) { console.log(err.message); }
};
const main = async () => {
try {
await putCampaign();
} catch (err) { console.log(err); }
}
main();
Hello,
I see that your request needed below corrections:
I recommend you to use OAuth2 Playground to make these CURL operations before you are trying with Node JS. OAuth 2 playground is logging the error messages clearly and using which I can see the mistakes I am doing while making the API call. Also, print the complete response object that you got via API that might give you more insights regarding the error. Please let me know if you have any further questions.
Regards,
Sai Teja, Google Ads API Team
const rp = require('request-promise-native');
const customer_id = 1234567890;
const developerToken = '*******************';
const loginCustomerId = 9876543210;
const accessToken = '*******************';
const headers = {
'developer-token': developerToken,
'login-customer-id': loginCustomerId,
'Accept-Charset': 'utf-8',
'Content-Type': 'application/json',
'Authorization': 'Bearer ' + accessToken
};
// create budget
const createBudget = async () => {
try {
const url = `https://googleads.googleapis.com/v1/customers/${customer_id}/campaignBudgets:mutate`;
const operations = {
'operations': [
{
'create': {
'name': 'new budget test 1',
'amount_micros': 100000000,
'status': 'ENABLED',
'delivery_method': 'STANDARD',
'type': 'STANDARD'
}
}
]
};
const options = {
method: 'POST',
headers: headers,
body: operations, // not data:
json: true,
resolveWithFullResponse: true
};
const res = await rp(url, options);
return res.body.results[0].resourceName;
} catch (err) { console.log(err.message); }
};
// create campaign
const createCampaign = async (budgetResource) => {
try {
const url = `https://googleads.googleapis.com/v1/customers/${customer_id}/campaigns:mutate`;
const operations = {
'operations': [
{
'create': {
'name': 'new campaign test 1',
'advertising_channel_type': 'SEARCH',
'status': 'PAUSED',
'campaign_budget': budgetResource,
'start_date': '20190701',
'end_date': '20190801',
'network_settings': {
'target_google_search': true,
'target_search_network': false,
'target_content_network': false,
'target_partner_search_network': false
},
'manual_cpc': {
'enhanced_cpc_enabled': false
}
}
}
]
};
const options = {
method: 'POST',
headers: headers,
body: operations,
json: true,
resolveWithFullResponse: true
};
const res = await rp(url, options);
return res.body.results[0].resourceName;
} catch (err) { console.log(err.message); }
};
const main = async () => {
try {
const budgetResource = await createBudget();
const campaignResource = await createCampaign(budgetResource);
console.log(campaignResource);
} catch (err) { console.log(err); }
}
main();