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 广告需按账户单独开通。请联系我们以启用该功能。
- 除非您发送
status: "active",否则新活动以paused状态开始。 - 预算按天计算,使用广告账户的币种,并且绝不会与其他活动共享。
- 其他币种的支出会按 Open Exchange Rates 提供的当日汇率换算为美元进行结算。使用无法换算的币种的账户会在创建任何内容之前返回
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 个横向图片 URL:1.91:1,至少 600×314。
string[]
必填
1 到 20 个方形图片 URL:1:1,至少 300×300。
string[]
必填
1 到 5 个方形徽标 URL:1:1,至少 128×128。
string[]
最多 4 个横向徽标 URL:4:1,至少 512×128。Google 最多接受徽标和横向徽标合计 5 个。
图片
Ayrshare 会从每个图片的 URL 下载图片,并在向 Google 发送任何内容之前对其进行检查:- GIF、JPG 或 PNG 格式,每张最大 5120 KB。
- 不小于上述最小尺寸,并符合其字段的宽高比(误差在 1% 以内)。
- 所有图片合计最大 45 MB。
- URL 必须是公开的。私有地址会被拒绝。
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."
}