curl \
-H "Authorization: Bearer API_KEY" \
-H "Content-Type: application/json" \
-H "Idempotency-Key: 6f1c2d4e-0b7a-4c55-9a3e-2f8d1b7c9e10" \
-X POST https://api.ayrshare.com/api/ads/google/campaigns \
-d '{
"accountId": "123-456-7890",
"name": "Fall sale",
"type": "search",
"budget": { "amount": 25, "type": "daily" },
"bidding": { "strategy": "maximizeClicks" },
"targeting": { "locations": ["2840"] },
"euPoliticalAdvertising": false,
"platformOptions": {
"google": {
"finalUrl": "https://example.com/fall-sale",
"headlines": ["Fall sale", "Shoes 30% off", "Free returns"],
"descriptions": ["Every shoe 30% off this week.", "Free returns on every order."],
"path1": "shoes",
"keywords": [
{ "text": "running shoes", "matchType": "phrase" },
{ "text": "trail running shoes", "matchType": "exact" }
]
}
}
}'
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": "6f1c2d4e-0b7a-4c55-9a3e-2f8d1b7c9e10"
},
body: JSON.stringify({
"accountId": "123-456-7890",
"name": "Fall sale",
"type": "search",
"budget": { "amount": 25, "type": "daily" },
"bidding": { "strategy": "maximizeClicks" },
"targeting": { "locations": ["2840"] },
"euPoliticalAdvertising": false,
"platformOptions": {
"google": {
"finalUrl": "https://example.com/fall-sale",
"headlines": ["Fall sale", "Shoes 30% off", "Free returns"],
"descriptions": ["Every shoe 30% off this week.", "Free returns on every order."],
"path1": "shoes",
"keywords": [
{ "text": "running shoes", "matchType": "phrase" },
{ "text": "trail running shoes", "matchType": "exact" }
]
}
}
})
})
.then((res) => res.json())
.then((json) => console.log(json))
.catch(console.error);
import requests
headers = {
"Authorization": "Bearer API_KEY",
"Idempotency-Key": "6f1c2d4e-0b7a-4c55-9a3e-2f8d1b7c9e10",
}
payload = {
"accountId": "123-456-7890",
"name": "Fall sale",
"type": "search",
"budget": { "amount": 25, "type": "daily" },
"bidding": { "strategy": "maximizeClicks" },
"targeting": { "locations": ["2840"] },
"euPoliticalAdvertising": False,
"platformOptions": {
"google": {
"finalUrl": "https://example.com/fall-sale",
"headlines": ["Fall sale", "Shoes 30% off", "Free returns"],
"descriptions": ["Every shoe 30% off this week.", "Free returns on every order."],
"path1": "shoes",
"keywords": [
{ "text": "running shoes", "matchType": "phrase" },
{ "text": "trail running shoes", "matchType": "exact" }
]
}
}
}
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",
"type": "search",
"budget": { "amount": 25, "type": "daily" },
"bidding": { "strategy": "maximizeClicks" },
"targeting": { "locations": ["2840"] },
"euPoliticalAdvertising": false,
"platformOptions": {
"google": {
"finalUrl": "https://example.com/fall-sale",
"headlines": ["Fall sale", "Shoes 30% off", "Free returns"],
"descriptions": ["Every shoe 30% off this week.", "Free returns on every order."],
"path1": "shoes",
"keywords": [
{ "text": "running shoes", "matchType": "phrase" },
{ "text": "trail running shoes", "matchType": "exact" }
]
}
}
}
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: 6f1c2d4e-0b7a-4c55-9a3e-2f8d1b7c9e10"
],
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", "6f1c2d4e-0b7a-4c55-9a3e-2f8d1b7c9e10");
var payload = """
{
"accountId": "123-456-7890",
"name": "Fall sale",
"type": "search",
"budget": { "amount": 25, "type": "daily" },
"bidding": { "strategy": "maximizeClicks" },
"targeting": { "locations": ["2840"] },
"euPoliticalAdvertising": false,
"platformOptions": {
"google": {
"finalUrl": "https://example.com/fall-sale",
"headlines": ["Fall sale", "Shoes 30% off", "Free returns"],
"descriptions": ["Every shoe 30% off this week.", "Free returns on every order."],
"path1": "shoes",
"keywords": [
{ "text": "running shoes", "matchType": "phrase" },
{ "text": "trail running shoes", "matchType": "exact" }
]
}
}
}
""";
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",
"type": "search",
"budget": { "amount": 25, "type": "daily" },
"bidding": { "strategy": "maximizeClicks" },
"targeting": { "locations": ["2840"] },
"euPoliticalAdvertising": false,
"platformOptions": {
"google": {
"finalUrl": "https://example.com/fall-sale",
"headlines": ["Fall sale", "Shoes 30% off", "Free returns"],
"descriptions": ["Every shoe 30% off this week.", "Free returns on every order."],
"path1": "shoes",
"keywords": [
{ "text": "running shoes", "matchType": "phrase" },
{ "text": "trail running shoes", "matchType": "exact" }
]
}
}
}`
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", "6f1c2d4e-0b7a-4c55-9a3e-2f8d1b7c9e10")
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",
"type": "search",
"budget": { "amount": 25, "type": "daily" },
"bidding": { "strategy": "maximizeClicks" },
"targeting": { "locations": ["2840"] },
"euPoliticalAdvertising": false,
"platformOptions": {
"google": {
"finalUrl": "https://example.com/fall-sale",
"headlines": ["Fall sale", "Shoes 30% off", "Free returns"],
"descriptions": ["Every shoe 30% off this week.", "Free returns on every order."],
"path1": "shoes",
"keywords": [
{ "text": "running shoes", "matchType": "phrase" },
{ "text": "trail running shoes", "matchType": "exact" }
]
}
}
}
""";
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", "6f1c2d4e-0b7a-4c55-9a3e-2f8d1b7c9e10")
.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'] = '6f1c2d4e-0b7a-4c55-9a3e-2f8d1b7c9e10'
request.body = <<~JSON
{
"accountId": "123-456-7890",
"name": "Fall sale",
"type": "search",
"budget": { "amount": 25, "type": "daily" },
"bidding": { "strategy": "maximizeClicks" },
"targeting": { "locations": ["2840"] },
"euPoliticalAdvertising": false,
"platformOptions": {
"google": {
"finalUrl": "https://example.com/fall-sale",
"headlines": ["Fall sale", "Shoes 30% off", "Free returns"],
"descriptions": ["Every shoe 30% off this week.", "Free returns on every order."],
"path1": "shoes",
"keywords": [
{ "text": "running shoes", "matchType": "phrase" },
{ "text": "trail running shoes", "matchType": "exact" }
]
}
}
}
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": "21534567890",
"adGroupId": "16812345678",
"adId": "71234567890",
"campaignStatus": "paused"
}
{
"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.headlines: Supply at least 3 headlines."
}
Google Ads
Google 検索キャンペーン
予算、キーワード、広告文、地域ターゲティングを含む Google Ads の検索キャンペーンを1回のリクエストで作成します
POST
/
ads
/
google
/
campaigns
curl \
-H "Authorization: Bearer API_KEY" \
-H "Content-Type: application/json" \
-H "Idempotency-Key: 6f1c2d4e-0b7a-4c55-9a3e-2f8d1b7c9e10" \
-X POST https://api.ayrshare.com/api/ads/google/campaigns \
-d '{
"accountId": "123-456-7890",
"name": "Fall sale",
"type": "search",
"budget": { "amount": 25, "type": "daily" },
"bidding": { "strategy": "maximizeClicks" },
"targeting": { "locations": ["2840"] },
"euPoliticalAdvertising": false,
"platformOptions": {
"google": {
"finalUrl": "https://example.com/fall-sale",
"headlines": ["Fall sale", "Shoes 30% off", "Free returns"],
"descriptions": ["Every shoe 30% off this week.", "Free returns on every order."],
"path1": "shoes",
"keywords": [
{ "text": "running shoes", "matchType": "phrase" },
{ "text": "trail running shoes", "matchType": "exact" }
]
}
}
}'
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": "6f1c2d4e-0b7a-4c55-9a3e-2f8d1b7c9e10"
},
body: JSON.stringify({
"accountId": "123-456-7890",
"name": "Fall sale",
"type": "search",
"budget": { "amount": 25, "type": "daily" },
"bidding": { "strategy": "maximizeClicks" },
"targeting": { "locations": ["2840"] },
"euPoliticalAdvertising": false,
"platformOptions": {
"google": {
"finalUrl": "https://example.com/fall-sale",
"headlines": ["Fall sale", "Shoes 30% off", "Free returns"],
"descriptions": ["Every shoe 30% off this week.", "Free returns on every order."],
"path1": "shoes",
"keywords": [
{ "text": "running shoes", "matchType": "phrase" },
{ "text": "trail running shoes", "matchType": "exact" }
]
}
}
})
})
.then((res) => res.json())
.then((json) => console.log(json))
.catch(console.error);
import requests
headers = {
"Authorization": "Bearer API_KEY",
"Idempotency-Key": "6f1c2d4e-0b7a-4c55-9a3e-2f8d1b7c9e10",
}
payload = {
"accountId": "123-456-7890",
"name": "Fall sale",
"type": "search",
"budget": { "amount": 25, "type": "daily" },
"bidding": { "strategy": "maximizeClicks" },
"targeting": { "locations": ["2840"] },
"euPoliticalAdvertising": False,
"platformOptions": {
"google": {
"finalUrl": "https://example.com/fall-sale",
"headlines": ["Fall sale", "Shoes 30% off", "Free returns"],
"descriptions": ["Every shoe 30% off this week.", "Free returns on every order."],
"path1": "shoes",
"keywords": [
{ "text": "running shoes", "matchType": "phrase" },
{ "text": "trail running shoes", "matchType": "exact" }
]
}
}
}
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",
"type": "search",
"budget": { "amount": 25, "type": "daily" },
"bidding": { "strategy": "maximizeClicks" },
"targeting": { "locations": ["2840"] },
"euPoliticalAdvertising": false,
"platformOptions": {
"google": {
"finalUrl": "https://example.com/fall-sale",
"headlines": ["Fall sale", "Shoes 30% off", "Free returns"],
"descriptions": ["Every shoe 30% off this week.", "Free returns on every order."],
"path1": "shoes",
"keywords": [
{ "text": "running shoes", "matchType": "phrase" },
{ "text": "trail running shoes", "matchType": "exact" }
]
}
}
}
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: 6f1c2d4e-0b7a-4c55-9a3e-2f8d1b7c9e10"
],
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", "6f1c2d4e-0b7a-4c55-9a3e-2f8d1b7c9e10");
var payload = """
{
"accountId": "123-456-7890",
"name": "Fall sale",
"type": "search",
"budget": { "amount": 25, "type": "daily" },
"bidding": { "strategy": "maximizeClicks" },
"targeting": { "locations": ["2840"] },
"euPoliticalAdvertising": false,
"platformOptions": {
"google": {
"finalUrl": "https://example.com/fall-sale",
"headlines": ["Fall sale", "Shoes 30% off", "Free returns"],
"descriptions": ["Every shoe 30% off this week.", "Free returns on every order."],
"path1": "shoes",
"keywords": [
{ "text": "running shoes", "matchType": "phrase" },
{ "text": "trail running shoes", "matchType": "exact" }
]
}
}
}
""";
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",
"type": "search",
"budget": { "amount": 25, "type": "daily" },
"bidding": { "strategy": "maximizeClicks" },
"targeting": { "locations": ["2840"] },
"euPoliticalAdvertising": false,
"platformOptions": {
"google": {
"finalUrl": "https://example.com/fall-sale",
"headlines": ["Fall sale", "Shoes 30% off", "Free returns"],
"descriptions": ["Every shoe 30% off this week.", "Free returns on every order."],
"path1": "shoes",
"keywords": [
{ "text": "running shoes", "matchType": "phrase" },
{ "text": "trail running shoes", "matchType": "exact" }
]
}
}
}`
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", "6f1c2d4e-0b7a-4c55-9a3e-2f8d1b7c9e10")
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",
"type": "search",
"budget": { "amount": 25, "type": "daily" },
"bidding": { "strategy": "maximizeClicks" },
"targeting": { "locations": ["2840"] },
"euPoliticalAdvertising": false,
"platformOptions": {
"google": {
"finalUrl": "https://example.com/fall-sale",
"headlines": ["Fall sale", "Shoes 30% off", "Free returns"],
"descriptions": ["Every shoe 30% off this week.", "Free returns on every order."],
"path1": "shoes",
"keywords": [
{ "text": "running shoes", "matchType": "phrase" },
{ "text": "trail running shoes", "matchType": "exact" }
]
}
}
}
""";
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", "6f1c2d4e-0b7a-4c55-9a3e-2f8d1b7c9e10")
.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'] = '6f1c2d4e-0b7a-4c55-9a3e-2f8d1b7c9e10'
request.body = <<~JSON
{
"accountId": "123-456-7890",
"name": "Fall sale",
"type": "search",
"budget": { "amount": 25, "type": "daily" },
"bidding": { "strategy": "maximizeClicks" },
"targeting": { "locations": ["2840"] },
"euPoliticalAdvertising": false,
"platformOptions": {
"google": {
"finalUrl": "https://example.com/fall-sale",
"headlines": ["Fall sale", "Shoes 30% off", "Free returns"],
"descriptions": ["Every shoe 30% off this week.", "Free returns on every order."],
"path1": "shoes",
"keywords": [
{ "text": "running shoes", "matchType": "phrase" },
{ "text": "trail running shoes", "matchType": "exact" }
]
}
}
}
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": "21534567890",
"adGroupId": "16812345678",
"adId": "71234567890",
"campaignStatus": "paused"
}
{
"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.headlines: Supply at least 3 headlines."
}
1回のリクエストで Google Ads の検索キャンペーンを作成します。Ayrshare は予算、キャンペーン、1つの広告グループ、キーワード、1つのレスポンシブ検索広告、地域ターゲティングをまとめて作成します。Google がいずれかの部分を拒否した場合は、何も作成されません。
リクエストは共通の広告キャンペーンの形式を使用します。このページでは Google 固有の内容を説明します。
- Google 広告はアカウントごとに有効化されます。有効化するには、お問い合わせください。
- まず “Social Accounts” ページから Google Ads を連携してください。
accountIdは10桁の Google Ads お客様 ID で、ハイフンの有無は問いません(123-456-7890)。 - 連携する Google ユーザーは、広告アカウントに直接アクセスできる必要があります。マネージャー アカウント経由でのみアクセスできるアカウントは一覧に表示されず、現時点では使用できません。そのユーザーを広告アカウント自体に追加してください。マネージャー アカウントも一覧に表示されません。マネージャー アカウントはキャンペーンを保持できないためです。
status: "active"を送信しない限り、新しいキャンペーンはpausedの状態で開始されます。- 予算は1日あたりの金額で、広告アカウントの通貨で指定します。
budget.currencyは送信しないでください。送信するとcode: 101が返されます。 - 他の通貨での支出は、Open Exchange Rates のその日の為替レートで USD に換算されて請求されます。換算できない通貨のアカウントでは、何も作成される前に
code: 101が返されます。 - 広告は Google 検索にのみ表示され、検索パートナーやディスプレイ ネットワークには表示されません。
コンバージョン トラッキング。
maximizeConversions は、Google Ads アカウントでコンバージョン トラッキングが設定されている場合にのみ機能します。Ayrshare が代わりに設定することはありません。設定していない場合は、maximizeClicks または manualCpc を使用してください。ヘッダーパラメータ
string
必須
新しいキャンペーンごとに、UUID などの新しい一意の値を指定します。同じキーでリクエストを繰り返すと、最初のレスポンスが返され、新たに何も作成されません。Ayrshare がキャンペーンを Google に送信する前に作成が失敗した場合はキーが解放されるため、リクエストを修正して同じキーで再試行できます。これには、Ayrshare が受け付けない値(サポートされていない入札戦略など)、USD に換算できない通貨のアカウント、および Ayrshare が最初に行うアカウント確認の失敗(Google による拒否を含む)が該当します。キャンペーンが Google に送信された後に失敗した作成は、その応答が保持されます。新しいキーで再試行してください。
ボディパラメータ
共通フィールドは広告キャンペーンに記載のとおりに機能します。Google では次のとおりです:string
必須
search。string
必須
maximizeClicks、manualCpc、または maximizeConversions。それ以外を指定すると code: 101 が返されます。boolean
必須
Google はすべてのキャンペーンでこの申告を必須としています。アカウント内に未申告のキャンペーンが1つでもある間は、Google はそのアカウントのキャンペーンに対するすべての変更を拒否します。
object
Google は広告アカウントのタイムゾーンで日単位のスケジュールを設定します。
start はその日の 00:00:00 に開始し、end はその日の 23:59:59 に停止します。送信した時刻は日付の指定にのみ使われます。start には当日を指定できますが、それより前の日は指定できません。1日だけのキャンペーンにするには、start と end に同じ日付を送信してください。end が start より前の日の場合は code: 101 が返されます。object
object
必須
表示 プロパティ
表示 プロパティ
string
必須
広告で開く
http または https のページ。string[]
必須
3〜15個の広告見出し。各見出しは30文字以内です。
string[]
必須
2〜4個の説明文。各説明文は90文字以内です。
string
ドメインの後に表示される表示パスの1つ目の部分。15文字以内です。
string
表示パスの2つ目の部分。15文字以内です。
path1 が必要です。object[]
必須
1つ以上のキーワード:
{ "text": string, "matchType": "exact" | "phrase" | "broad" }。text は80文字以内かつ10語以内です。number
1クリックあたりに支払う上限額。アカウントの通貨で指定します。
manualCpc では必須です。maximizeClicks では各入札の上限になります。maximizeConversions では受け付けられません。curl \
-H "Authorization: Bearer API_KEY" \
-H "Content-Type: application/json" \
-H "Idempotency-Key: 6f1c2d4e-0b7a-4c55-9a3e-2f8d1b7c9e10" \
-X POST https://api.ayrshare.com/api/ads/google/campaigns \
-d '{
"accountId": "123-456-7890",
"name": "Fall sale",
"type": "search",
"budget": { "amount": 25, "type": "daily" },
"bidding": { "strategy": "maximizeClicks" },
"targeting": { "locations": ["2840"] },
"euPoliticalAdvertising": false,
"platformOptions": {
"google": {
"finalUrl": "https://example.com/fall-sale",
"headlines": ["Fall sale", "Shoes 30% off", "Free returns"],
"descriptions": ["Every shoe 30% off this week.", "Free returns on every order."],
"path1": "shoes",
"keywords": [
{ "text": "running shoes", "matchType": "phrase" },
{ "text": "trail running shoes", "matchType": "exact" }
]
}
}
}'
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": "6f1c2d4e-0b7a-4c55-9a3e-2f8d1b7c9e10"
},
body: JSON.stringify({
"accountId": "123-456-7890",
"name": "Fall sale",
"type": "search",
"budget": { "amount": 25, "type": "daily" },
"bidding": { "strategy": "maximizeClicks" },
"targeting": { "locations": ["2840"] },
"euPoliticalAdvertising": false,
"platformOptions": {
"google": {
"finalUrl": "https://example.com/fall-sale",
"headlines": ["Fall sale", "Shoes 30% off", "Free returns"],
"descriptions": ["Every shoe 30% off this week.", "Free returns on every order."],
"path1": "shoes",
"keywords": [
{ "text": "running shoes", "matchType": "phrase" },
{ "text": "trail running shoes", "matchType": "exact" }
]
}
}
})
})
.then((res) => res.json())
.then((json) => console.log(json))
.catch(console.error);
import requests
headers = {
"Authorization": "Bearer API_KEY",
"Idempotency-Key": "6f1c2d4e-0b7a-4c55-9a3e-2f8d1b7c9e10",
}
payload = {
"accountId": "123-456-7890",
"name": "Fall sale",
"type": "search",
"budget": { "amount": 25, "type": "daily" },
"bidding": { "strategy": "maximizeClicks" },
"targeting": { "locations": ["2840"] },
"euPoliticalAdvertising": False,
"platformOptions": {
"google": {
"finalUrl": "https://example.com/fall-sale",
"headlines": ["Fall sale", "Shoes 30% off", "Free returns"],
"descriptions": ["Every shoe 30% off this week.", "Free returns on every order."],
"path1": "shoes",
"keywords": [
{ "text": "running shoes", "matchType": "phrase" },
{ "text": "trail running shoes", "matchType": "exact" }
]
}
}
}
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",
"type": "search",
"budget": { "amount": 25, "type": "daily" },
"bidding": { "strategy": "maximizeClicks" },
"targeting": { "locations": ["2840"] },
"euPoliticalAdvertising": false,
"platformOptions": {
"google": {
"finalUrl": "https://example.com/fall-sale",
"headlines": ["Fall sale", "Shoes 30% off", "Free returns"],
"descriptions": ["Every shoe 30% off this week.", "Free returns on every order."],
"path1": "shoes",
"keywords": [
{ "text": "running shoes", "matchType": "phrase" },
{ "text": "trail running shoes", "matchType": "exact" }
]
}
}
}
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: 6f1c2d4e-0b7a-4c55-9a3e-2f8d1b7c9e10"
],
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", "6f1c2d4e-0b7a-4c55-9a3e-2f8d1b7c9e10");
var payload = """
{
"accountId": "123-456-7890",
"name": "Fall sale",
"type": "search",
"budget": { "amount": 25, "type": "daily" },
"bidding": { "strategy": "maximizeClicks" },
"targeting": { "locations": ["2840"] },
"euPoliticalAdvertising": false,
"platformOptions": {
"google": {
"finalUrl": "https://example.com/fall-sale",
"headlines": ["Fall sale", "Shoes 30% off", "Free returns"],
"descriptions": ["Every shoe 30% off this week.", "Free returns on every order."],
"path1": "shoes",
"keywords": [
{ "text": "running shoes", "matchType": "phrase" },
{ "text": "trail running shoes", "matchType": "exact" }
]
}
}
}
""";
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",
"type": "search",
"budget": { "amount": 25, "type": "daily" },
"bidding": { "strategy": "maximizeClicks" },
"targeting": { "locations": ["2840"] },
"euPoliticalAdvertising": false,
"platformOptions": {
"google": {
"finalUrl": "https://example.com/fall-sale",
"headlines": ["Fall sale", "Shoes 30% off", "Free returns"],
"descriptions": ["Every shoe 30% off this week.", "Free returns on every order."],
"path1": "shoes",
"keywords": [
{ "text": "running shoes", "matchType": "phrase" },
{ "text": "trail running shoes", "matchType": "exact" }
]
}
}
}`
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", "6f1c2d4e-0b7a-4c55-9a3e-2f8d1b7c9e10")
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",
"type": "search",
"budget": { "amount": 25, "type": "daily" },
"bidding": { "strategy": "maximizeClicks" },
"targeting": { "locations": ["2840"] },
"euPoliticalAdvertising": false,
"platformOptions": {
"google": {
"finalUrl": "https://example.com/fall-sale",
"headlines": ["Fall sale", "Shoes 30% off", "Free returns"],
"descriptions": ["Every shoe 30% off this week.", "Free returns on every order."],
"path1": "shoes",
"keywords": [
{ "text": "running shoes", "matchType": "phrase" },
{ "text": "trail running shoes", "matchType": "exact" }
]
}
}
}
""";
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", "6f1c2d4e-0b7a-4c55-9a3e-2f8d1b7c9e10")
.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'] = '6f1c2d4e-0b7a-4c55-9a3e-2f8d1b7c9e10'
request.body = <<~JSON
{
"accountId": "123-456-7890",
"name": "Fall sale",
"type": "search",
"budget": { "amount": 25, "type": "daily" },
"bidding": { "strategy": "maximizeClicks" },
"targeting": { "locations": ["2840"] },
"euPoliticalAdvertising": false,
"platformOptions": {
"google": {
"finalUrl": "https://example.com/fall-sale",
"headlines": ["Fall sale", "Shoes 30% off", "Free returns"],
"descriptions": ["Every shoe 30% off this week.", "Free returns on every order."],
"path1": "shoes",
"keywords": [
{ "text": "running shoes", "matchType": "phrase" },
{ "text": "trail running shoes", "matchType": "exact" }
]
}
}
}
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": "21534567890",
"adGroupId": "16812345678",
"adId": "71234567890",
"campaignStatus": "paused"
}
{
"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.headlines: Supply at least 3 headlines."
}
エラー
| コード | 発生条件 |
|---|---|
101 | フィールドが欠落しているか無効である。details にそのフィールドが示されます。 |
205 | Google がリクエストを拒否した。たとえば、アカウントに同じ名前のキャンペーンがすでに存在する場合や、広告テキストが Google の広告ポリシーに違反している場合などです。details に変更すべき内容が示されます。 |
400 | 連携した Google ユーザーがこの広告アカウントにアクセスできない、Google Ads へのアクセスが取り消された、キャンペーンがお客様のものではない、または変更対象のキャンペーンが Google Ads で削除されている。 |
370 | Google がリクエストを完了できなかった、または Google が Ayrshare のアクセスをまだ承認していない。Google のリクエスト ID がある場合は details に含まれます。Google の応答が失われたために作成リクエストで 370 が返された場合でも、キャンペーンが作成されている可能性があります。Google は1つのアカウント内で同じ名前のキャンペーンを2つ作成することを拒否するため、同じ name で再試行すると、重複が作成される代わりに 205 が返されます。 |