How do I use the next_page_token in cURL?

48 views
Skip to first unread message

Jarrod Thuener

unread,
May 14, 2019, 5:33:30 PM5/14/19
to AdWords API and Google Ads API Forum
I've seen the obvious response to paging issues "use a library", but I don't have that ability. I have to use cURL.

Here's what the documentation states about paging:

Making a request

The search method requires a SearchGoogleAdsRequest, which consists of the following attributes:

  • customer_id.
  • A Google Ads Query Language query that indicates which resource to query, the attributes, segments, and metrics to retrieve, and the conditions to use to restrict which objects are returned.
  • page_size to indicate how many objects to return in a single response when using paging.
  • An optional page_token to retrieve the next batch of results when using paging.

For more information on the Google Ads Query Language, check out the Google Ads Query Language guide.


and on paging:

Paging through results

Whenever you are retrieving a large number of objects, you'll want to specify the page_size in your request. This will break up the result set of the query into multiple responses that each contain up to page_size objects.

For example, if your account contains 50,000 keywords, the result set for the following query will contain 50,000 GoogleAdsRow objects:

SELECT ad_group.id, ad_group_criterion.type, ad_group_criterion.criterion_id,
       ad_group_criterion
.keyword.text, ad_group_criterion.keyword.match_type
FROM ad_group_criterion
WHERE ad_group_criterion
.type = KEYWORD

To avoid receiving a single response containing all rows in the result set, you can specify a page_size of 1000 so that the Google Ads API will return only the first one thousand rows in the first response, along with a next_page_token. To retrieve the next one thousand rows, simply send the request again, but update the request's page_token to the response's next_page_token.


So my question is where do I specify the page_token?

Thanks!

googleadsapi...@google.com

unread,
May 14, 2019, 11:18:42 PM5/14/19
to AdWords API and Google Ads API Forum
Hi,

Thank you for reaching out. In Google Ads API perspective, page_token and next_page_token doesn't have to be specified. These two are automatically generated when you execute your request. So for example, you have 300 ads and you set the page_size to 100, when you execute the request, the API will generate a response with the next_page_token together with the first 100 results. Then, the API will automatically make an API call until it retrieves all the results. 

Feel free to write back if you have further clarifications.

Regards,
Dave
Google Ads API Team


=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
Also find us on our blog and discussion group:
    https://ads-developers.googleblog.com/search/label/google_ads_api
    https://developers.google.com/adwords/api/community/
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~

Was your question answered? Please rate your experience with us by taking a short survey.
If not -- reply to this email and tell us what else we can do to help.

Take Survey

Also find us on our blog and discussion group:
http://googleadsdeveloper.blogspot.com/search/label/adwords_api
https://developers.google.com/adwords/api/community/

--
--
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
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+unsubscribe@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+unsubscribe@googlegroups.com.
Visit this group at https://groups.google.com/group/adwords-api.
To view this discussion on the web visit https://groups.google.com/d/msgid/adwords-api/c7373fed-1fd1-4195-af68-56d3e83a51dc%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Jarrod Thuener

unread,
May 15, 2019, 6:26:27 AM5/15/19
to AdWords API and Google Ads API Forum
From what I understand, the caveat here is that a library it's used... I have to use curl, so the first call returns the first 10000 results then it provides a next page token. How to I push that token through again to get the next set of results?

Jarrod Thuener

unread,
May 15, 2019, 12:51:40 PM5/15/19
to AdWords API and Google Ads API Forum
Let me rephrase my question for clarity.

Can someone provide a cURL example for pulling the "next_token"?

Thanks!

googleadsapi...@google.com

unread,
May 16, 2019, 3:23:18 AM5/16/19
to AdWords API and Google Ads API Forum
Hi,

My apologies if I couldn't provide an actual cURL example. You would need to add the page token after the page size. See below:

{
  "customer_id": <insert_customer_id_here>,
  "query" : "insert_query_string_here",
  "page_size": "insert_page_size_here",
  "page_token": "inser_page_token_here"
}

Let me know if this helps.

Regards,
Dave
Google Ads API Team


=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
Also find us on our blog and discussion group:
    https://ads-developers.googleblog.com/search/label/google_ads_api
    https://developers.google.com/adwords/api/community/
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~

Was your question answered? Please rate your experience with us by taking a short survey.
If not -- reply to this email and tell us what else we can do to help.

Take Survey

Also find us on our blog and discussion group:
http://googleadsdeveloper.blogspot.com/search/label/adwords_api
https://developers.google.com/adwords/api/community/

Jarrod Thuener

unread,
May 16, 2019, 9:56:58 AM5/16/19
to AdWords API and Google Ads API Forum
Thanks. I got it to work by adding the page_token to the Body. I was previously adding it to the header, which obviously wasn't working. Thanks for the help!!

So all things equal, the only change was the body WAS:
{"query":"my query here"}

and now it is 
{
"query":"same query as above",
"page_token":"the nextPageToken value from the initial response"
}

Thanks!!
Reply all
Reply to author
Forward
0 new messages