Examples

  • This guide provides examples of directly calling Search Ads 360 REST endpoints using curl, bypassing the need for a client library.

  • Before running the examples, you'll need to set up environment variables for your API version, OAuth 2.0 access token, manager account ID, and client account ID.

  • The provided code samples demonstrate both paginated search using the search method with an adjustable pageSize and streaming search using the searchStream method which returns all results at once.

  • All examples utilize the SA360 Query Language for data retrieval, focusing on campaign data like name, budget, status, and performance metrics.

This guide contains examples of calling the REST endpoints directly, without the use of a client library.

Prerequisites

All the samples below are meant to be easily copy-and-pasteable into a bash shell using curl command. You will need a Search Ads 360 manager account containing at least one client account.

Environment variables

Enter account credentials and IDs below, and then copy-and-paste into your terminal to configure the environment variables used in the subsequent examples.

API_VERSION="0"
OAUTH2_ACCESS_TOKEN="OAUTH_ACCESS_TOKEN"
MANAGER_CUSTOMER_ID="MANAGER_CUSTOMER_ID"
CUSTOMER_ID="CUSTOMER_ID"

Additional optional object IDs

The following examples work on pre-existing campaigns. If you have IDs of an existing campaign to use with these examples, enter it below.

CAMPAIGN_ID=CAMPAIGN_ID

The search method uses pagination, with an adjustable pageSize parameter specified alongside the query.

cURL

#!/bin/bash
# [START curl_command]
curl -f --request POST "https://searchads360.googleapis.com/v${API_VERSION}/customers/${CUSTOMER_ID}/searchAds360:search" \
--header "Content-Type: application/json" \
--header "login-customer-id: ${MANAGER_CUSTOMER_ID}" \
--header "Authorization: Bearer ${OAUTH2_ACCESS_TOKEN}" \
--data '{
"pageSize": 10,
"query": "
  SELECT campaign.name,
    campaign_budget.amount_micros,
    campaign.status,
    campaign.advertising_channel_type,
    metrics.clicks,
    metrics.impressions,
    metrics.ctr,
    metrics.average_cpc,
    metrics.cost_micros,
    campaign.bidding_strategy_type
  FROM campaign
  WHERE segments.date DURING LAST_7_DAYS
    AND campaign.status != 'REMOVED'
"
}'
# [END curl_command]

SA360 Query Language

  SELECT campaign.name,
    campaign_budget.amount_micros,
    campaign.status,
    campaign.advertising_channel_type,
    metrics.clicks,
    metrics.impressions,
    metrics.ctr,
    metrics.average_cpc,
    metrics.cost_micros,
    campaign.bidding_strategy_type
  FROM campaign
  WHERE segments.date DURING LAST_7_DAYS
    AND campaign.status != 'REMOVED'

Streaming

The searchStream method streams all results in a single response, and thus the pageSize field is not supported.

cURL

#!/bin/bash
# [START curl_command]
curl -f --request POST "https://searchads360.googleapis.com/v${API_VERSION}/customers/${CUSTOMER_ID}/searchAds360:searchStream" \
--header "Content-Type: application/json" \
--header "login-customer-id: ${MANAGER_CUSTOMER_ID}" \
--header "Authorization: Bearer ${OAUTH2_ACCESS_TOKEN}" \
--data '{
"query": "
  SELECT campaign.name,
    campaign_budget.amount_micros,
    campaign.status,
    campaign.advertising_channel_type,
    metrics.clicks,
    metrics.impressions,
    metrics.ctr,
    metrics.average_cpc,
    metrics.cost_micros,
    campaign.bidding_strategy_type
  FROM campaign
  WHERE segments.date DURING LAST_7_DAYS
    AND campaign.status != 'REMOVED'
"
}'
# [END curl_command]

SA360 Query Language

  SELECT campaign.name,
    campaign_budget.amount_micros,
    campaign.status,
    campaign.advertising_channel_type,
    metrics.clicks,
    metrics.impressions,
    metrics.ctr,
    metrics.average_cpc,
    metrics.cost_micros,
    campaign.bidding_strategy_type
  FROM campaign
  WHERE segments.date DURING LAST_7_DAYS
    AND campaign.status != 'REMOVED'