curl \
-H "Authorization: Bearer API_KEY" \
-H "Content-Type: application/json" \
-H "Idempotency-Key: 0b7a6f1c-2d4e-4c55-9a3e-2f8d1b7c9e11" \
-X POST https://api.ayrshare.com/api/ads/google/campaigns \
-d '{
"accountId": "123-456-7890",
"name": "Fall sale PMax",
"type": "performanceMax",
"budget": { "amount": 40, "type": "daily" },
"bidding": { "strategy": "maximizeConversions" },
"targeting": { "locations": ["2840"] },
"euPoliticalAdvertising": false,
"platformOptions": {
"google": {
"finalUrl": "https://example.com/fall-sale",
"assets": {
"headlines": ["Fall sale", "Shoes 30% off", "Free returns"],
"longHeadlines": ["Every running shoe 30% off this week only"],
"descriptions": ["Every shoe 30% off this week.", "Free returns on every order."],
"businessName": "Acme Shoes",
"marketingImages": ["https://example.com/images/fall-1200x628.png"],
"squareMarketingImages": ["https://example.com/images/fall-1200x1200.png"],
"logos": ["https://example.com/images/logo-512.png"]
}
}
}
}'
const API_KEY = "API_KEY";
fetch("https://api.ayrshare.com/api/ads/google/campaigns", {
method: "POST",
headers: {
"Authorization": `Bearer ${API_KEY}`,
"Content-Type": "application/json",
"Idempotency-Key": "0b7a6f1c-2d4e-4c55-9a3e-2f8d1b7c9e11"
},
body: JSON.stringify({
"accountId": "123-456-7890",
"name": "Fall sale PMax",
"type": "performanceMax",
"budget": { "amount": 40, "type": "daily" },
"bidding": { "strategy": "maximizeConversions" },
"targeting": { "locations": ["2840"] },
"euPoliticalAdvertising": false,
"platformOptions": {
"google": {
"finalUrl": "https://example.com/fall-sale",
"assets": {
"headlines": ["Fall sale", "Shoes 30% off", "Free returns"],
"longHeadlines": ["Every running shoe 30% off this week only"],
"descriptions": ["Every shoe 30% off this week.", "Free returns on every order."],
"businessName": "Acme Shoes",
"marketingImages": ["https://example.com/images/fall-1200x628.png"],
"squareMarketingImages": ["https://example.com/images/fall-1200x1200.png"],
"logos": ["https://example.com/images/logo-512.png"]
}
}
}
})
})
.then((res) => res.json())
.then((json) => console.log(json))
.catch(console.error);
import requests
headers = {
"Authorization": "Bearer API_KEY",
"Idempotency-Key": "0b7a6f1c-2d4e-4c55-9a3e-2f8d1b7c9e11",
}
payload = {
"accountId": "123-456-7890",
"name": "Fall sale PMax",
"type": "performanceMax",
"budget": { "amount": 40, "type": "daily" },
"bidding": { "strategy": "maximizeConversions" },
"targeting": { "locations": ["2840"] },
"euPoliticalAdvertising": False,
"platformOptions": {
"google": {
"finalUrl": "https://example.com/fall-sale",
"assets": {
"headlines": ["Fall sale", "Shoes 30% off", "Free returns"],
"longHeadlines": ["Every running shoe 30% off this week only"],
"descriptions": ["Every shoe 30% off this week.", "Free returns on every order."],
"businessName": "Acme Shoes",
"marketingImages": ["https://example.com/images/fall-1200x628.png"],
"squareMarketingImages": ["https://example.com/images/fall-1200x1200.png"],
"logos": ["https://example.com/images/logo-512.png"]
}
}
}
}
r = requests.post("https://api.ayrshare.com/api/ads/google/campaigns", headers=headers, json=payload)
print(r.json())
<?php
$payload = <<<'JSON'
{
"accountId": "123-456-7890",
"name": "Fall sale PMax",
"type": "performanceMax",
"budget": { "amount": 40, "type": "daily" },
"bidding": { "strategy": "maximizeConversions" },
"targeting": { "locations": ["2840"] },
"euPoliticalAdvertising": false,
"platformOptions": {
"google": {
"finalUrl": "https://example.com/fall-sale",
"assets": {
"headlines": ["Fall sale", "Shoes 30% off", "Free returns"],
"longHeadlines": ["Every running shoe 30% off this week only"],
"descriptions": ["Every shoe 30% off this week.", "Free returns on every order."],
"businessName": "Acme Shoes",
"marketingImages": ["https://example.com/images/fall-1200x628.png"],
"squareMarketingImages": ["https://example.com/images/fall-1200x1200.png"],
"logos": ["https://example.com/images/logo-512.png"]
}
}
}
}
JSON;
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.ayrshare.com/api/ads/google/campaigns",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_HTTPHEADER => [
"Authorization: Bearer API_KEY",
"Content-Type: application/json",
"Idempotency-Key: 0b7a6f1c-2d4e-4c55-9a3e-2f8d1b7c9e11"
],
CURLOPT_POSTFIELDS => $payload
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error: " . $err;
} else {
echo $response;
}
?>
using System;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
class Program
{
static async Task Main(string[] args)
{
var client = new HttpClient();
client.DefaultRequestHeaders.Add("Authorization", "Bearer API_KEY");
client.DefaultRequestHeaders.Add("Idempotency-Key", "0b7a6f1c-2d4e-4c55-9a3e-2f8d1b7c9e11");
var payload = """
{
"accountId": "123-456-7890",
"name": "Fall sale PMax",
"type": "performanceMax",
"budget": { "amount": 40, "type": "daily" },
"bidding": { "strategy": "maximizeConversions" },
"targeting": { "locations": ["2840"] },
"euPoliticalAdvertising": false,
"platformOptions": {
"google": {
"finalUrl": "https://example.com/fall-sale",
"assets": {
"headlines": ["Fall sale", "Shoes 30% off", "Free returns"],
"longHeadlines": ["Every running shoe 30% off this week only"],
"descriptions": ["Every shoe 30% off this week.", "Free returns on every order."],
"businessName": "Acme Shoes",
"marketingImages": ["https://example.com/images/fall-1200x628.png"],
"squareMarketingImages": ["https://example.com/images/fall-1200x1200.png"],
"logos": ["https://example.com/images/logo-512.png"]
}
}
}
}
""";
var response = await client.PostAsync(
"https://api.ayrshare.com/api/ads/google/campaigns",
new StringContent(payload, Encoding.UTF8, "application/json"));
var content = await response.Content.ReadAsStringAsync();
Console.WriteLine(content);
}
}
package main
import (
"fmt"
"io"
"net/http"
"strings"
)
func main() {
payload := `{
"accountId": "123-456-7890",
"name": "Fall sale PMax",
"type": "performanceMax",
"budget": { "amount": 40, "type": "daily" },
"bidding": { "strategy": "maximizeConversions" },
"targeting": { "locations": ["2840"] },
"euPoliticalAdvertising": false,
"platformOptions": {
"google": {
"finalUrl": "https://example.com/fall-sale",
"assets": {
"headlines": ["Fall sale", "Shoes 30% off", "Free returns"],
"longHeadlines": ["Every running shoe 30% off this week only"],
"descriptions": ["Every shoe 30% off this week.", "Free returns on every order."],
"businessName": "Acme Shoes",
"marketingImages": ["https://example.com/images/fall-1200x628.png"],
"squareMarketingImages": ["https://example.com/images/fall-1200x1200.png"],
"logos": ["https://example.com/images/logo-512.png"]
}
}
}
}`
req, _ := http.NewRequest("POST", "https://api.ayrshare.com/api/ads/google/campaigns", strings.NewReader(payload))
req.Header.Add("Authorization", "Bearer API_KEY")
req.Header.Add("Content-Type", "application/json")
req.Header.Add("Idempotency-Key", "0b7a6f1c-2d4e-4c55-9a3e-2f8d1b7c9e11")
resp, err := http.DefaultClient.Do(req)
if err != nil {
fmt.Println("Error:", err)
return
}
defer resp.Body.Close()
body, _ := io.ReadAll(resp.Body)
fmt.Println(string(body))
}
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
public class CreateCampaign {
public static void main(String[] args) throws Exception {
String payload = """
{
"accountId": "123-456-7890",
"name": "Fall sale PMax",
"type": "performanceMax",
"budget": { "amount": 40, "type": "daily" },
"bidding": { "strategy": "maximizeConversions" },
"targeting": { "locations": ["2840"] },
"euPoliticalAdvertising": false,
"platformOptions": {
"google": {
"finalUrl": "https://example.com/fall-sale",
"assets": {
"headlines": ["Fall sale", "Shoes 30% off", "Free returns"],
"longHeadlines": ["Every running shoe 30% off this week only"],
"descriptions": ["Every shoe 30% off this week.", "Free returns on every order."],
"businessName": "Acme Shoes",
"marketingImages": ["https://example.com/images/fall-1200x628.png"],
"squareMarketingImages": ["https://example.com/images/fall-1200x1200.png"],
"logos": ["https://example.com/images/logo-512.png"]
}
}
}
}
""";
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create("https://api.ayrshare.com/api/ads/google/campaigns"))
.header("Authorization", "Bearer API_KEY")
.header("Content-Type", "application/json")
.header("Idempotency-Key", "0b7a6f1c-2d4e-4c55-9a3e-2f8d1b7c9e11")
.POST(HttpRequest.BodyPublishers.ofString(payload))
.build();
HttpResponse<String> response = HttpClient.newHttpClient()
.send(request, HttpResponse.BodyHandlers.ofString());
System.out.println(response.body());
}
}
require 'net/http'
require 'uri'
uri = URI.parse('https://api.ayrshare.com/api/ads/google/campaigns')
request = Net::HTTP::Post.new(uri)
request['Authorization'] = 'Bearer API_KEY'
request['Content-Type'] = 'application/json'
request['Idempotency-Key'] = '0b7a6f1c-2d4e-4c55-9a3e-2f8d1b7c9e11'
request.body = <<~JSON
{
"accountId": "123-456-7890",
"name": "Fall sale PMax",
"type": "performanceMax",
"budget": { "amount": 40, "type": "daily" },
"bidding": { "strategy": "maximizeConversions" },
"targeting": { "locations": ["2840"] },
"euPoliticalAdvertising": false,
"platformOptions": {
"google": {
"finalUrl": "https://example.com/fall-sale",
"assets": {
"headlines": ["Fall sale", "Shoes 30% off", "Free returns"],
"longHeadlines": ["Every running shoe 30% off this week only"],
"descriptions": ["Every shoe 30% off this week.", "Free returns on every order."],
"businessName": "Acme Shoes",
"marketingImages": ["https://example.com/images/fall-1200x628.png"],
"squareMarketingImages": ["https://example.com/images/fall-1200x1200.png"],
"logos": ["https://example.com/images/logo-512.png"]
}
}
}
}
JSON
response = Net::HTTP.start(uri.hostname, uri.port, use_ssl: true) do |http|
http.request(request)
end
puts response.body
{
"status": "success",
"platform": "google",
"campaignId": "21534567891",
"assetGroupId": "6512345678",
"campaignStatus": "paused"
}
{
"status": "success",
"platform": "google",
"campaignId": "21534567891",
"assetGroupId": "6512345678",
"campaignStatus": "paused",
"warnings": [
"This Google Ads account has no conversion tracking. Performance Max optimizes for conversions, so Google may limit the campaign's spend until you set up conversion tracking in Google Ads."
]
}
{
"action": "request",
"status": "error",
"code": 101,
"message": "Missing or incorrect parameters. Please verify with the docs. https://www.ayrshare.com/docs/apis",
"details": "platformOptions.google.assets.logos[0]: the image is 100x100; use at least 128x128."
}
Google Ads
Google Performance Max 廣告活動
使用您的文字和圖片建立 Google Ads Performance Max 廣告活動
POST
/
ads
/
google
/
campaigns
curl \
-H "Authorization: Bearer API_KEY" \
-H "Content-Type: application/json" \
-H "Idempotency-Key: 0b7a6f1c-2d4e-4c55-9a3e-2f8d1b7c9e11" \
-X POST https://api.ayrshare.com/api/ads/google/campaigns \
-d '{
"accountId": "123-456-7890",
"name": "Fall sale PMax",
"type": "performanceMax",
"budget": { "amount": 40, "type": "daily" },
"bidding": { "strategy": "maximizeConversions" },
"targeting": { "locations": ["2840"] },
"euPoliticalAdvertising": false,
"platformOptions": {
"google": {
"finalUrl": "https://example.com/fall-sale",
"assets": {
"headlines": ["Fall sale", "Shoes 30% off", "Free returns"],
"longHeadlines": ["Every running shoe 30% off this week only"],
"descriptions": ["Every shoe 30% off this week.", "Free returns on every order."],
"businessName": "Acme Shoes",
"marketingImages": ["https://example.com/images/fall-1200x628.png"],
"squareMarketingImages": ["https://example.com/images/fall-1200x1200.png"],
"logos": ["https://example.com/images/logo-512.png"]
}
}
}
}'
const API_KEY = "API_KEY";
fetch("https://api.ayrshare.com/api/ads/google/campaigns", {
method: "POST",
headers: {
"Authorization": `Bearer ${API_KEY}`,
"Content-Type": "application/json",
"Idempotency-Key": "0b7a6f1c-2d4e-4c55-9a3e-2f8d1b7c9e11"
},
body: JSON.stringify({
"accountId": "123-456-7890",
"name": "Fall sale PMax",
"type": "performanceMax",
"budget": { "amount": 40, "type": "daily" },
"bidding": { "strategy": "maximizeConversions" },
"targeting": { "locations": ["2840"] },
"euPoliticalAdvertising": false,
"platformOptions": {
"google": {
"finalUrl": "https://example.com/fall-sale",
"assets": {
"headlines": ["Fall sale", "Shoes 30% off", "Free returns"],
"longHeadlines": ["Every running shoe 30% off this week only"],
"descriptions": ["Every shoe 30% off this week.", "Free returns on every order."],
"businessName": "Acme Shoes",
"marketingImages": ["https://example.com/images/fall-1200x628.png"],
"squareMarketingImages": ["https://example.com/images/fall-1200x1200.png"],
"logos": ["https://example.com/images/logo-512.png"]
}
}
}
})
})
.then((res) => res.json())
.then((json) => console.log(json))
.catch(console.error);
import requests
headers = {
"Authorization": "Bearer API_KEY",
"Idempotency-Key": "0b7a6f1c-2d4e-4c55-9a3e-2f8d1b7c9e11",
}
payload = {
"accountId": "123-456-7890",
"name": "Fall sale PMax",
"type": "performanceMax",
"budget": { "amount": 40, "type": "daily" },
"bidding": { "strategy": "maximizeConversions" },
"targeting": { "locations": ["2840"] },
"euPoliticalAdvertising": False,
"platformOptions": {
"google": {
"finalUrl": "https://example.com/fall-sale",
"assets": {
"headlines": ["Fall sale", "Shoes 30% off", "Free returns"],
"longHeadlines": ["Every running shoe 30% off this week only"],
"descriptions": ["Every shoe 30% off this week.", "Free returns on every order."],
"businessName": "Acme Shoes",
"marketingImages": ["https://example.com/images/fall-1200x628.png"],
"squareMarketingImages": ["https://example.com/images/fall-1200x1200.png"],
"logos": ["https://example.com/images/logo-512.png"]
}
}
}
}
r = requests.post("https://api.ayrshare.com/api/ads/google/campaigns", headers=headers, json=payload)
print(r.json())
<?php
$payload = <<<'JSON'
{
"accountId": "123-456-7890",
"name": "Fall sale PMax",
"type": "performanceMax",
"budget": { "amount": 40, "type": "daily" },
"bidding": { "strategy": "maximizeConversions" },
"targeting": { "locations": ["2840"] },
"euPoliticalAdvertising": false,
"platformOptions": {
"google": {
"finalUrl": "https://example.com/fall-sale",
"assets": {
"headlines": ["Fall sale", "Shoes 30% off", "Free returns"],
"longHeadlines": ["Every running shoe 30% off this week only"],
"descriptions": ["Every shoe 30% off this week.", "Free returns on every order."],
"businessName": "Acme Shoes",
"marketingImages": ["https://example.com/images/fall-1200x628.png"],
"squareMarketingImages": ["https://example.com/images/fall-1200x1200.png"],
"logos": ["https://example.com/images/logo-512.png"]
}
}
}
}
JSON;
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.ayrshare.com/api/ads/google/campaigns",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_HTTPHEADER => [
"Authorization: Bearer API_KEY",
"Content-Type: application/json",
"Idempotency-Key: 0b7a6f1c-2d4e-4c55-9a3e-2f8d1b7c9e11"
],
CURLOPT_POSTFIELDS => $payload
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error: " . $err;
} else {
echo $response;
}
?>
using System;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
class Program
{
static async Task Main(string[] args)
{
var client = new HttpClient();
client.DefaultRequestHeaders.Add("Authorization", "Bearer API_KEY");
client.DefaultRequestHeaders.Add("Idempotency-Key", "0b7a6f1c-2d4e-4c55-9a3e-2f8d1b7c9e11");
var payload = """
{
"accountId": "123-456-7890",
"name": "Fall sale PMax",
"type": "performanceMax",
"budget": { "amount": 40, "type": "daily" },
"bidding": { "strategy": "maximizeConversions" },
"targeting": { "locations": ["2840"] },
"euPoliticalAdvertising": false,
"platformOptions": {
"google": {
"finalUrl": "https://example.com/fall-sale",
"assets": {
"headlines": ["Fall sale", "Shoes 30% off", "Free returns"],
"longHeadlines": ["Every running shoe 30% off this week only"],
"descriptions": ["Every shoe 30% off this week.", "Free returns on every order."],
"businessName": "Acme Shoes",
"marketingImages": ["https://example.com/images/fall-1200x628.png"],
"squareMarketingImages": ["https://example.com/images/fall-1200x1200.png"],
"logos": ["https://example.com/images/logo-512.png"]
}
}
}
}
""";
var response = await client.PostAsync(
"https://api.ayrshare.com/api/ads/google/campaigns",
new StringContent(payload, Encoding.UTF8, "application/json"));
var content = await response.Content.ReadAsStringAsync();
Console.WriteLine(content);
}
}
package main
import (
"fmt"
"io"
"net/http"
"strings"
)
func main() {
payload := `{
"accountId": "123-456-7890",
"name": "Fall sale PMax",
"type": "performanceMax",
"budget": { "amount": 40, "type": "daily" },
"bidding": { "strategy": "maximizeConversions" },
"targeting": { "locations": ["2840"] },
"euPoliticalAdvertising": false,
"platformOptions": {
"google": {
"finalUrl": "https://example.com/fall-sale",
"assets": {
"headlines": ["Fall sale", "Shoes 30% off", "Free returns"],
"longHeadlines": ["Every running shoe 30% off this week only"],
"descriptions": ["Every shoe 30% off this week.", "Free returns on every order."],
"businessName": "Acme Shoes",
"marketingImages": ["https://example.com/images/fall-1200x628.png"],
"squareMarketingImages": ["https://example.com/images/fall-1200x1200.png"],
"logos": ["https://example.com/images/logo-512.png"]
}
}
}
}`
req, _ := http.NewRequest("POST", "https://api.ayrshare.com/api/ads/google/campaigns", strings.NewReader(payload))
req.Header.Add("Authorization", "Bearer API_KEY")
req.Header.Add("Content-Type", "application/json")
req.Header.Add("Idempotency-Key", "0b7a6f1c-2d4e-4c55-9a3e-2f8d1b7c9e11")
resp, err := http.DefaultClient.Do(req)
if err != nil {
fmt.Println("Error:", err)
return
}
defer resp.Body.Close()
body, _ := io.ReadAll(resp.Body)
fmt.Println(string(body))
}
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
public class CreateCampaign {
public static void main(String[] args) throws Exception {
String payload = """
{
"accountId": "123-456-7890",
"name": "Fall sale PMax",
"type": "performanceMax",
"budget": { "amount": 40, "type": "daily" },
"bidding": { "strategy": "maximizeConversions" },
"targeting": { "locations": ["2840"] },
"euPoliticalAdvertising": false,
"platformOptions": {
"google": {
"finalUrl": "https://example.com/fall-sale",
"assets": {
"headlines": ["Fall sale", "Shoes 30% off", "Free returns"],
"longHeadlines": ["Every running shoe 30% off this week only"],
"descriptions": ["Every shoe 30% off this week.", "Free returns on every order."],
"businessName": "Acme Shoes",
"marketingImages": ["https://example.com/images/fall-1200x628.png"],
"squareMarketingImages": ["https://example.com/images/fall-1200x1200.png"],
"logos": ["https://example.com/images/logo-512.png"]
}
}
}
}
""";
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create("https://api.ayrshare.com/api/ads/google/campaigns"))
.header("Authorization", "Bearer API_KEY")
.header("Content-Type", "application/json")
.header("Idempotency-Key", "0b7a6f1c-2d4e-4c55-9a3e-2f8d1b7c9e11")
.POST(HttpRequest.BodyPublishers.ofString(payload))
.build();
HttpResponse<String> response = HttpClient.newHttpClient()
.send(request, HttpResponse.BodyHandlers.ofString());
System.out.println(response.body());
}
}
require 'net/http'
require 'uri'
uri = URI.parse('https://api.ayrshare.com/api/ads/google/campaigns')
request = Net::HTTP::Post.new(uri)
request['Authorization'] = 'Bearer API_KEY'
request['Content-Type'] = 'application/json'
request['Idempotency-Key'] = '0b7a6f1c-2d4e-4c55-9a3e-2f8d1b7c9e11'
request.body = <<~JSON
{
"accountId": "123-456-7890",
"name": "Fall sale PMax",
"type": "performanceMax",
"budget": { "amount": 40, "type": "daily" },
"bidding": { "strategy": "maximizeConversions" },
"targeting": { "locations": ["2840"] },
"euPoliticalAdvertising": false,
"platformOptions": {
"google": {
"finalUrl": "https://example.com/fall-sale",
"assets": {
"headlines": ["Fall sale", "Shoes 30% off", "Free returns"],
"longHeadlines": ["Every running shoe 30% off this week only"],
"descriptions": ["Every shoe 30% off this week.", "Free returns on every order."],
"businessName": "Acme Shoes",
"marketingImages": ["https://example.com/images/fall-1200x628.png"],
"squareMarketingImages": ["https://example.com/images/fall-1200x1200.png"],
"logos": ["https://example.com/images/logo-512.png"]
}
}
}
}
JSON
response = Net::HTTP.start(uri.hostname, uri.port, use_ssl: true) do |http|
http.request(request)
end
puts response.body
{
"status": "success",
"platform": "google",
"campaignId": "21534567891",
"assetGroupId": "6512345678",
"campaignStatus": "paused"
}
{
"status": "success",
"platform": "google",
"campaignId": "21534567891",
"assetGroupId": "6512345678",
"campaignStatus": "paused",
"warnings": [
"This Google Ads account has no conversion tracking. Performance Max optimizes for conversions, so Google may limit the campaign's spend until you set up conversion tracking in Google Ads."
]
}
{
"action": "request",
"status": "error",
"code": 101,
"message": "Missing or incorrect parameters. Please verify with the docs. https://www.ayrshare.com/docs/apis",
"details": "platformOptions.google.assets.logos[0]: the image is 100x100; use at least 128x128."
}
請先設定轉換追蹤。 Performance Max 會依據您的轉換來決定在哪裡顯示廣告以及出價多少。Ayrshare 不會阻止沒有轉換追蹤的廣告活動,但在您的 Google Ads 帳戶設定轉換追蹤之前,Google 可能會限制其花費。Ayrshare 不會替您進行設定。若帳戶沒有轉換追蹤,建立回應會包含一則說明此情況的
warnings 項目。- Google 廣告需按帳戶個別開通。請聯絡我們以啟用此功能。
- 新廣告活動預設以
paused狀態開始,除非您傳送status: "active"。 - 預算為每日預算,使用廣告帳戶的幣別,且絕不會與其他廣告活動共用。
- 其他幣別的支出會依 Open Exchange Rates 提供的當日匯率換算為 USD 計費。使用無法換算之幣別的帳戶會在建立任何項目之前返回
code: 101。 - 不支援影片。Google 可能會使用您的圖片製作影片。
請求頭參數
string
必填
每個新的廣告活動都請傳送一個新的唯一值,例如 UUID。以相同金鑰重複發送請求,會返回第一次的回應。若建立請求在 Ayrshare 將廣告活動傳送至 Google 之前就失敗(例如圖片尺寸錯誤),該金鑰會被釋放,因此您可以修正請求後以相同的金鑰重試。
請求體參數
string
必填
performanceMax。object
必填
Performance Max 僅接受以下策略。其他任何值都會返回
code: 101。maximizeConversions:在預算內取得最多轉換。targetCpa搭配targetCpa:同上,並以該單次轉換費用為目標。maximizeConversionValue:在預算內取得最高轉換價值。targetRoas搭配targetRoas:同上,並以該廣告投資報酬率為目標,例如3.5代表 350%。
boolean
必填
Google 要求每個廣告活動都提供此聲明。
string[]
Google 地區 ID,例如
2840 代表美國。省略此欄位即可定位所有地區。object
必填
顯示 子屬性
顯示 子屬性
string
必填
廣告開啟的
http 或 https 頁面。object
必填
您的文字和圖片。每個清單中的項目必須彼此不同。
顯示 子屬性
顯示 子屬性
string[]
必填
3 到 15 個,每個最多 30 個字元。
string[]
必填
1 到 5 個,每個最多 90 個字元。
string[]
必填
2 到 5 個,每個最多 90 個字元。至少一個必須為 60 個字元以內。
string
必填
一個商家名稱,最多 25 個字元。
string[]
必填
1 到 20 個橫向圖片網址:1.91:1,至少 600×314。
string[]
必填
1 到 20 個正方形圖片網址:1:1,至少 300×300。
string[]
必填
1 到 5 個正方形標誌網址:1:1,至少 128×128。
string[]
最多 4 個橫向標誌網址:4:1,至少 512×128。Google 最多接受標誌與橫向標誌合計 5 個。
圖片
Ayrshare 會從每個圖片網址下載圖片,並在傳送任何內容至 Google 之前進行檢查:- GIF、JPG 或 PNG 格式,每個最多 5120 KB。
- 至少達到上方所列的最小尺寸,且符合其欄位的長寬比(誤差 1% 以內)。
- 所有圖片合計最多 45 MB。
- 網址必須是公開的。私人位址會遭拒絕。
code: 101,例如 platformOptions.google.assets.logos[0]: the image is 100x100; use at least 128x128.
curl \
-H "Authorization: Bearer API_KEY" \
-H "Content-Type: application/json" \
-H "Idempotency-Key: 0b7a6f1c-2d4e-4c55-9a3e-2f8d1b7c9e11" \
-X POST https://api.ayrshare.com/api/ads/google/campaigns \
-d '{
"accountId": "123-456-7890",
"name": "Fall sale PMax",
"type": "performanceMax",
"budget": { "amount": 40, "type": "daily" },
"bidding": { "strategy": "maximizeConversions" },
"targeting": { "locations": ["2840"] },
"euPoliticalAdvertising": false,
"platformOptions": {
"google": {
"finalUrl": "https://example.com/fall-sale",
"assets": {
"headlines": ["Fall sale", "Shoes 30% off", "Free returns"],
"longHeadlines": ["Every running shoe 30% off this week only"],
"descriptions": ["Every shoe 30% off this week.", "Free returns on every order."],
"businessName": "Acme Shoes",
"marketingImages": ["https://example.com/images/fall-1200x628.png"],
"squareMarketingImages": ["https://example.com/images/fall-1200x1200.png"],
"logos": ["https://example.com/images/logo-512.png"]
}
}
}
}'
const API_KEY = "API_KEY";
fetch("https://api.ayrshare.com/api/ads/google/campaigns", {
method: "POST",
headers: {
"Authorization": `Bearer ${API_KEY}`,
"Content-Type": "application/json",
"Idempotency-Key": "0b7a6f1c-2d4e-4c55-9a3e-2f8d1b7c9e11"
},
body: JSON.stringify({
"accountId": "123-456-7890",
"name": "Fall sale PMax",
"type": "performanceMax",
"budget": { "amount": 40, "type": "daily" },
"bidding": { "strategy": "maximizeConversions" },
"targeting": { "locations": ["2840"] },
"euPoliticalAdvertising": false,
"platformOptions": {
"google": {
"finalUrl": "https://example.com/fall-sale",
"assets": {
"headlines": ["Fall sale", "Shoes 30% off", "Free returns"],
"longHeadlines": ["Every running shoe 30% off this week only"],
"descriptions": ["Every shoe 30% off this week.", "Free returns on every order."],
"businessName": "Acme Shoes",
"marketingImages": ["https://example.com/images/fall-1200x628.png"],
"squareMarketingImages": ["https://example.com/images/fall-1200x1200.png"],
"logos": ["https://example.com/images/logo-512.png"]
}
}
}
})
})
.then((res) => res.json())
.then((json) => console.log(json))
.catch(console.error);
import requests
headers = {
"Authorization": "Bearer API_KEY",
"Idempotency-Key": "0b7a6f1c-2d4e-4c55-9a3e-2f8d1b7c9e11",
}
payload = {
"accountId": "123-456-7890",
"name": "Fall sale PMax",
"type": "performanceMax",
"budget": { "amount": 40, "type": "daily" },
"bidding": { "strategy": "maximizeConversions" },
"targeting": { "locations": ["2840"] },
"euPoliticalAdvertising": False,
"platformOptions": {
"google": {
"finalUrl": "https://example.com/fall-sale",
"assets": {
"headlines": ["Fall sale", "Shoes 30% off", "Free returns"],
"longHeadlines": ["Every running shoe 30% off this week only"],
"descriptions": ["Every shoe 30% off this week.", "Free returns on every order."],
"businessName": "Acme Shoes",
"marketingImages": ["https://example.com/images/fall-1200x628.png"],
"squareMarketingImages": ["https://example.com/images/fall-1200x1200.png"],
"logos": ["https://example.com/images/logo-512.png"]
}
}
}
}
r = requests.post("https://api.ayrshare.com/api/ads/google/campaigns", headers=headers, json=payload)
print(r.json())
<?php
$payload = <<<'JSON'
{
"accountId": "123-456-7890",
"name": "Fall sale PMax",
"type": "performanceMax",
"budget": { "amount": 40, "type": "daily" },
"bidding": { "strategy": "maximizeConversions" },
"targeting": { "locations": ["2840"] },
"euPoliticalAdvertising": false,
"platformOptions": {
"google": {
"finalUrl": "https://example.com/fall-sale",
"assets": {
"headlines": ["Fall sale", "Shoes 30% off", "Free returns"],
"longHeadlines": ["Every running shoe 30% off this week only"],
"descriptions": ["Every shoe 30% off this week.", "Free returns on every order."],
"businessName": "Acme Shoes",
"marketingImages": ["https://example.com/images/fall-1200x628.png"],
"squareMarketingImages": ["https://example.com/images/fall-1200x1200.png"],
"logos": ["https://example.com/images/logo-512.png"]
}
}
}
}
JSON;
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.ayrshare.com/api/ads/google/campaigns",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_HTTPHEADER => [
"Authorization: Bearer API_KEY",
"Content-Type: application/json",
"Idempotency-Key: 0b7a6f1c-2d4e-4c55-9a3e-2f8d1b7c9e11"
],
CURLOPT_POSTFIELDS => $payload
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error: " . $err;
} else {
echo $response;
}
?>
using System;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
class Program
{
static async Task Main(string[] args)
{
var client = new HttpClient();
client.DefaultRequestHeaders.Add("Authorization", "Bearer API_KEY");
client.DefaultRequestHeaders.Add("Idempotency-Key", "0b7a6f1c-2d4e-4c55-9a3e-2f8d1b7c9e11");
var payload = """
{
"accountId": "123-456-7890",
"name": "Fall sale PMax",
"type": "performanceMax",
"budget": { "amount": 40, "type": "daily" },
"bidding": { "strategy": "maximizeConversions" },
"targeting": { "locations": ["2840"] },
"euPoliticalAdvertising": false,
"platformOptions": {
"google": {
"finalUrl": "https://example.com/fall-sale",
"assets": {
"headlines": ["Fall sale", "Shoes 30% off", "Free returns"],
"longHeadlines": ["Every running shoe 30% off this week only"],
"descriptions": ["Every shoe 30% off this week.", "Free returns on every order."],
"businessName": "Acme Shoes",
"marketingImages": ["https://example.com/images/fall-1200x628.png"],
"squareMarketingImages": ["https://example.com/images/fall-1200x1200.png"],
"logos": ["https://example.com/images/logo-512.png"]
}
}
}
}
""";
var response = await client.PostAsync(
"https://api.ayrshare.com/api/ads/google/campaigns",
new StringContent(payload, Encoding.UTF8, "application/json"));
var content = await response.Content.ReadAsStringAsync();
Console.WriteLine(content);
}
}
package main
import (
"fmt"
"io"
"net/http"
"strings"
)
func main() {
payload := `{
"accountId": "123-456-7890",
"name": "Fall sale PMax",
"type": "performanceMax",
"budget": { "amount": 40, "type": "daily" },
"bidding": { "strategy": "maximizeConversions" },
"targeting": { "locations": ["2840"] },
"euPoliticalAdvertising": false,
"platformOptions": {
"google": {
"finalUrl": "https://example.com/fall-sale",
"assets": {
"headlines": ["Fall sale", "Shoes 30% off", "Free returns"],
"longHeadlines": ["Every running shoe 30% off this week only"],
"descriptions": ["Every shoe 30% off this week.", "Free returns on every order."],
"businessName": "Acme Shoes",
"marketingImages": ["https://example.com/images/fall-1200x628.png"],
"squareMarketingImages": ["https://example.com/images/fall-1200x1200.png"],
"logos": ["https://example.com/images/logo-512.png"]
}
}
}
}`
req, _ := http.NewRequest("POST", "https://api.ayrshare.com/api/ads/google/campaigns", strings.NewReader(payload))
req.Header.Add("Authorization", "Bearer API_KEY")
req.Header.Add("Content-Type", "application/json")
req.Header.Add("Idempotency-Key", "0b7a6f1c-2d4e-4c55-9a3e-2f8d1b7c9e11")
resp, err := http.DefaultClient.Do(req)
if err != nil {
fmt.Println("Error:", err)
return
}
defer resp.Body.Close()
body, _ := io.ReadAll(resp.Body)
fmt.Println(string(body))
}
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
public class CreateCampaign {
public static void main(String[] args) throws Exception {
String payload = """
{
"accountId": "123-456-7890",
"name": "Fall sale PMax",
"type": "performanceMax",
"budget": { "amount": 40, "type": "daily" },
"bidding": { "strategy": "maximizeConversions" },
"targeting": { "locations": ["2840"] },
"euPoliticalAdvertising": false,
"platformOptions": {
"google": {
"finalUrl": "https://example.com/fall-sale",
"assets": {
"headlines": ["Fall sale", "Shoes 30% off", "Free returns"],
"longHeadlines": ["Every running shoe 30% off this week only"],
"descriptions": ["Every shoe 30% off this week.", "Free returns on every order."],
"businessName": "Acme Shoes",
"marketingImages": ["https://example.com/images/fall-1200x628.png"],
"squareMarketingImages": ["https://example.com/images/fall-1200x1200.png"],
"logos": ["https://example.com/images/logo-512.png"]
}
}
}
}
""";
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create("https://api.ayrshare.com/api/ads/google/campaigns"))
.header("Authorization", "Bearer API_KEY")
.header("Content-Type", "application/json")
.header("Idempotency-Key", "0b7a6f1c-2d4e-4c55-9a3e-2f8d1b7c9e11")
.POST(HttpRequest.BodyPublishers.ofString(payload))
.build();
HttpResponse<String> response = HttpClient.newHttpClient()
.send(request, HttpResponse.BodyHandlers.ofString());
System.out.println(response.body());
}
}
require 'net/http'
require 'uri'
uri = URI.parse('https://api.ayrshare.com/api/ads/google/campaigns')
request = Net::HTTP::Post.new(uri)
request['Authorization'] = 'Bearer API_KEY'
request['Content-Type'] = 'application/json'
request['Idempotency-Key'] = '0b7a6f1c-2d4e-4c55-9a3e-2f8d1b7c9e11'
request.body = <<~JSON
{
"accountId": "123-456-7890",
"name": "Fall sale PMax",
"type": "performanceMax",
"budget": { "amount": 40, "type": "daily" },
"bidding": { "strategy": "maximizeConversions" },
"targeting": { "locations": ["2840"] },
"euPoliticalAdvertising": false,
"platformOptions": {
"google": {
"finalUrl": "https://example.com/fall-sale",
"assets": {
"headlines": ["Fall sale", "Shoes 30% off", "Free returns"],
"longHeadlines": ["Every running shoe 30% off this week only"],
"descriptions": ["Every shoe 30% off this week.", "Free returns on every order."],
"businessName": "Acme Shoes",
"marketingImages": ["https://example.com/images/fall-1200x628.png"],
"squareMarketingImages": ["https://example.com/images/fall-1200x1200.png"],
"logos": ["https://example.com/images/logo-512.png"]
}
}
}
}
JSON
response = Net::HTTP.start(uri.hostname, uri.port, use_ssl: true) do |http|
http.request(request)
end
puts response.body
{
"status": "success",
"platform": "google",
"campaignId": "21534567891",
"assetGroupId": "6512345678",
"campaignStatus": "paused"
}
{
"status": "success",
"platform": "google",
"campaignId": "21534567891",
"assetGroupId": "6512345678",
"campaignStatus": "paused",
"warnings": [
"This Google Ads account has no conversion tracking. Performance Max optimizes for conversions, so Google may limit the campaign's spend until you set up conversion tracking in Google Ads."
]
}
{
"action": "request",
"status": "error",
"code": 101,
"message": "Missing or incorrect parameters. Please verify with the docs. https://www.ayrshare.com/docs/apis",
"details": "platformOptions.google.assets.logos[0]: the image is 100x100; use at least 128x128."
}