Exemplos

Este guia contém exemplos de como chamar os endpoints REST diretamente, sem o uso de uma biblioteca de cliente.

Pré-requisitos

Todos os exemplos abaixo podem ser copiados e colados em um shell bash usando o comando curl. Você vai precisar de uma conta de administrador do Search Ads 360 com pelo menos uma conta de cliente.

Variáveis de ambiente

Insira as credenciais e os IDs da conta abaixo e copie e cole no terminal para configurar as variáveis de ambiente usadas nos exemplos seguintes.

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

Outros IDs de objetos opcionais

Os exemplos a seguir funcionam em campanhas já existentes. Se você tiver IDs de uma campanha para usar com esses exemplos, insira-os abaixo.

CAMPAIGN_ID=CAMPAIGN_ID

O método search usa a paginação, com um parâmetro pageSize ajustável especificado com o 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]

Linguagem de consulta do SA360

  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

O método searchStream transmite todos os resultados em uma única resposta. Portanto, o campo pageSize não é compatível.

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]

Linguagem de consulta do SA360

  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'