The endpoint and JSON data when making a POST request using curl

786 views
Skip to first unread message

f s

unread,
May 29, 2019, 11:24:53 PM5/29/19
to AdWords API and Google Ads API Forum
I must use Node.js, curl and JSON, NOT library. So, I need endpoint and JSON data.
I'm coding with a test account and I'd like to make one campaign. Could you give me some examples of endpoint and JSON data?

for examples:
      "operations": [
       
{
         
"create": {
           
"name": "new API campaign 1",
           
"status": "PAUSE",
           
"start_date": "01/06/2019",
           
"end_date": "01/09/2019"
         
}
       
}
     
]
   
};
Is it correct? Response is returned statusCode: 200 AND body: {}, but no campaign.


Can I use Bulk Mutates? Can you give me an example of endpoint and JSON in that case?


I think, Google Ads API team should announce endpoint and JSON examples for curl as soon. The official guide is very unfriendly.

Thanks.

revarasi Sofa

unread,
May 29, 2019, 11:27:00 PM5/29/19
to symb...@gmail.com, AdWords API and Google Ads API Forum
service korsi sopa dibandung

--
--
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
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.

Google Ads API Forum Advisor Prod

unread,
May 30, 2019, 4:03:36 PM5/30/19
to adwor...@googlegroups.com
Hello,

Looks like you are missing the required parameters while creating the campaigns. The date should be YYYYMMDD format, the status should be PAUSED, campaign_budget and bidding_strategy_type fields also required to create the campaign. The complete example to create campaigns via CURL is not yet available. I will let my team know regarding your concern and update you once I have more information. Meanwhile you could refer the code samples here and follow the patterns.

Regards,
Sai Teja, Google Ads API team

ref:_00D1U1174p._5001UBe6ec:ref
Message has been deleted
Message has been deleted
Message has been deleted

f s

unread,
Jun 2, 2019, 11:47:55 PM6/2/19
to AdWords API and Google Ads API Forum
I'll show you all of the code.
'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
();

Google Ads API Forum Advisor Prod

unread,
Jun 3, 2019, 3:57:27 PM6/3/19
to adwor...@googlegroups.com

Hello,

I see that your request needed below corrections:

  1. The campaign_budget should be a resource name instead of the actual budget, that says you have to create the budget before even creating the campaign and use that resource name here in the campaign creation.
  2. There is no labels field in the dynamic_search_ads_setting setting. Once the campaign is created using the resource name of the campaign you can create labels for it using CampaignLabel. Corresponding code sample in Java can be found here.

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



ref:_00D1U1174p._5001UBe6ec:ref

f s

unread,
Jun 3, 2019, 9:47:37 PM6/3/19
to AdWords API and Google Ads API Forum
Thanks a lot, and I'm sorry, but I deleted the previous question for a reason.
Even if you have sample code, it's hard work...


2019年6月4日火曜日 4時57分27秒 UTC+9 adsapiforumadvisor:

f s

unread,
Jun 4, 2019, 2:38:47 AM6/4/19
to AdWords API and Google Ads API Forum
Thank you so much, Sai. I was able to create an empty campaign. I've put the successful code below.

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
();

We are still waiting for the endpoint and json sample code via curl.

Google Ads API Forum Advisor Prod

unread,
Jun 4, 2019, 11:20:32 AM6/4/19
to adwor...@googlegroups.com
Hello,

Glad you were able to create the campaign. The end point for Google Ads API is googleads.googleapis.com and the code sample for CURL operations is not yet available. I will update my team regarding your interest. Also, we see most of the advertisers using the client libraries that are provided in various languages which has more example and client library support is also available via GitHub. 

I have attached my result log to create campaigns using Java client library for your reference.

Regarding,
log_campaings.txt
Reply all
Reply to author
Forward
0 new messages