curl \
-H "Authorization: Bearer API_KEY" \
-H "Content-Type: application/json" \
-X PUT https://api.ayrshare.com/api/ads/google/campaigns/21534567890 \
-d '{"status": "active", "budget": { "amount": 30 }}'
const API_KEY = "API_KEY";
fetch("https://api.ayrshare.com/api/ads/google/campaigns/21534567890", {
method: "PUT",
headers: {
"Authorization": `Bearer ${API_KEY}`,
"Content-Type": "application/json"
},
body: JSON.stringify({"status": "active", "budget": { "amount": 30 }})
})
.then((res) => res.json())
.then((json) => console.log(json))
.catch(console.error);
import requests
headers = {
"Authorization": "Bearer API_KEY",
}
payload = {"status": "active", "budget": { "amount": 30 }}
r = requests.put("https://api.ayrshare.com/api/ads/google/campaigns/21534567890", headers=headers, json=payload)
print(r.json())
<?php
$payload = <<<'JSON'
{"status": "active", "budget": { "amount": 30 }}
JSON;
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.ayrshare.com/api/ads/google/campaigns/21534567890",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_CUSTOMREQUEST => "PUT",
CURLOPT_HTTPHEADER => [
"Authorization: Bearer API_KEY",
"Content-Type: application/json"
],
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");
var payload = """
{"status": "active", "budget": { "amount": 30 }}
""";
var response = await client.PutAsync(
"https://api.ayrshare.com/api/ads/google/campaigns/21534567890",
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 := `{"status": "active", "budget": { "amount": 30 }}`
req, _ := http.NewRequest("PUT", "https://api.ayrshare.com/api/ads/google/campaigns/21534567890", strings.NewReader(payload))
req.Header.Add("Authorization", "Bearer API_KEY")
req.Header.Add("Content-Type", "application/json")
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 UpdateCampaign {
public static void main(String[] args) throws Exception {
String payload = """
{"status": "active", "budget": { "amount": 30 }}
""";
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create("https://api.ayrshare.com/api/ads/google/campaigns/21534567890"))
.header("Authorization", "Bearer API_KEY")
.header("Content-Type", "application/json")
.PUT(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/21534567890')
request = Net::HTTP::Put.new(uri)
request['Authorization'] = 'Bearer API_KEY'
request['Content-Type'] = 'application/json'
request.body = <<~JSON
{"status": "active", "budget": { "amount": 30 }}
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",
"campaignStatus": "active"
}
{
"action": "request",
"status": "error",
"code": 101,
"message": "Missing or incorrect parameters. Please verify with the docs. https://www.ayrshare.com/docs/apis",
"details": "This campaign uses a budget shared with other campaigns in Google Ads. Change the shared budget in Google Ads."
}
Google Ads
Cập nhật Chiến dịch
Bắt đầu hoặc tạm dừng một chiến dịch Google Ads, đổi tên chiến dịch, hoặc thay đổi ngân sách hằng ngày hay ngày kết thúc.
PUT
/
ads
/
google
/
campaigns
/
{id}
curl \
-H "Authorization: Bearer API_KEY" \
-H "Content-Type: application/json" \
-X PUT https://api.ayrshare.com/api/ads/google/campaigns/21534567890 \
-d '{"status": "active", "budget": { "amount": 30 }}'
const API_KEY = "API_KEY";
fetch("https://api.ayrshare.com/api/ads/google/campaigns/21534567890", {
method: "PUT",
headers: {
"Authorization": `Bearer ${API_KEY}`,
"Content-Type": "application/json"
},
body: JSON.stringify({"status": "active", "budget": { "amount": 30 }})
})
.then((res) => res.json())
.then((json) => console.log(json))
.catch(console.error);
import requests
headers = {
"Authorization": "Bearer API_KEY",
}
payload = {"status": "active", "budget": { "amount": 30 }}
r = requests.put("https://api.ayrshare.com/api/ads/google/campaigns/21534567890", headers=headers, json=payload)
print(r.json())
<?php
$payload = <<<'JSON'
{"status": "active", "budget": { "amount": 30 }}
JSON;
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.ayrshare.com/api/ads/google/campaigns/21534567890",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_CUSTOMREQUEST => "PUT",
CURLOPT_HTTPHEADER => [
"Authorization: Bearer API_KEY",
"Content-Type: application/json"
],
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");
var payload = """
{"status": "active", "budget": { "amount": 30 }}
""";
var response = await client.PutAsync(
"https://api.ayrshare.com/api/ads/google/campaigns/21534567890",
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 := `{"status": "active", "budget": { "amount": 30 }}`
req, _ := http.NewRequest("PUT", "https://api.ayrshare.com/api/ads/google/campaigns/21534567890", strings.NewReader(payload))
req.Header.Add("Authorization", "Bearer API_KEY")
req.Header.Add("Content-Type", "application/json")
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 UpdateCampaign {
public static void main(String[] args) throws Exception {
String payload = """
{"status": "active", "budget": { "amount": 30 }}
""";
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create("https://api.ayrshare.com/api/ads/google/campaigns/21534567890"))
.header("Authorization", "Bearer API_KEY")
.header("Content-Type", "application/json")
.PUT(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/21534567890')
request = Net::HTTP::Put.new(uri)
request['Authorization'] = 'Bearer API_KEY'
request['Content-Type'] = 'application/json'
request.body = <<~JSON
{"status": "active", "budget": { "amount": 30 }}
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",
"campaignStatus": "active"
}
{
"action": "request",
"status": "error",
"code": 101,
"message": "Missing or incorrect parameters. Please verify with the docs. https://www.ayrshare.com/docs/apis",
"details": "This campaign uses a budget shared with other campaigns in Google Ads. Change the shared budget in Google Ads."
}
Bắt đầu hoặc tạm dừng một chiến dịch Google Ads mà bạn đã tạo qua Ayrshare, đổi tên chiến dịch, hoặc thay đổi ngân sách hằng ngày hay ngày kết thúc.
- Gửi ít nhất một trường. Tất cả thay đổi trong một yêu cầu được áp dụng cùng lúc hoặc không áp dụng thay đổi nào.
- Bạn không thể thay đổi
type,accountIdhoặceuPoliticalAdvertisingsau khi tạo chiến dịch. - Không cần
Idempotency-Key: gửi lại cùng một thay đổi sẽ đặt cùng các giá trị. - Phản hồi trả về
campaignStatuscủa chiến dịch. Dùng Lấy Chiến dịch để đọc các trường khác.
Tham số Header
Tham số Path
string
bắt buộc
campaignId được trả về khi bạn tạo chiến dịch.Tham số Body
string
active hoặc paused. Một yêu cầu chỉ gửi status: "paused" sẽ không bị chặn khi Ayrshare đã tạm dừng quảng cáo trên Google.string
Tên chiến dịch mới, từ 1 đến 255 ký tự, không có ngắt dòng.
object
{ "amount": number }: số tiền mới chi tiêu mỗi ngày, theo đơn vị tiền tệ của tài khoản quảng cáo, tối đa hai chữ số thập phân. Một chiến dịch có ngân sách được bạn dùng chung với các chiến dịch khác trong Google Ads sẽ trả về code: 101: hãy thay đổi ngân sách dùng chung trong Google Ads.object
{ "end": string }: ngày kết thúc mới, dưới dạng ngày ISO (2026-11-30) hoặc ngày giờ. Google lên lịch theo nguyên ngày trong múi giờ của tài khoản quảng cáo, vì vậy chiến dịch dừng lúc 23:59:59 của ngày đó. Ngày này có thể trùng với ngày bắt đầu, nhưng không được sớm hơn.Lỗi
| Mã | Khi nào |
|---|---|
101 | Không có trường nào được gửi, một trường không hợp lệ, hoặc ngân sách được dùng chung với các chiến dịch khác. details cho biết trường hợp nào. |
205 | Google đã từ chối thay đổi. details cho biết cần thay đổi gì. |
400 | Chiến dịch không thuộc về bạn, không tồn tại, hoặc đã bị xóa trong Google Ads. Cũng xảy ra khi người dùng Google mà bạn liên kết không thể truy cập tài khoản quảng cáo, hoặc quyền truy cập Google Ads đã bị thu hồi. |
370 | Google không thể hoàn tất yêu cầu. Hãy thử lại. |
curl \
-H "Authorization: Bearer API_KEY" \
-H "Content-Type: application/json" \
-X PUT https://api.ayrshare.com/api/ads/google/campaigns/21534567890 \
-d '{"status": "active", "budget": { "amount": 30 }}'
const API_KEY = "API_KEY";
fetch("https://api.ayrshare.com/api/ads/google/campaigns/21534567890", {
method: "PUT",
headers: {
"Authorization": `Bearer ${API_KEY}`,
"Content-Type": "application/json"
},
body: JSON.stringify({"status": "active", "budget": { "amount": 30 }})
})
.then((res) => res.json())
.then((json) => console.log(json))
.catch(console.error);
import requests
headers = {
"Authorization": "Bearer API_KEY",
}
payload = {"status": "active", "budget": { "amount": 30 }}
r = requests.put("https://api.ayrshare.com/api/ads/google/campaigns/21534567890", headers=headers, json=payload)
print(r.json())
<?php
$payload = <<<'JSON'
{"status": "active", "budget": { "amount": 30 }}
JSON;
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.ayrshare.com/api/ads/google/campaigns/21534567890",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_CUSTOMREQUEST => "PUT",
CURLOPT_HTTPHEADER => [
"Authorization: Bearer API_KEY",
"Content-Type: application/json"
],
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");
var payload = """
{"status": "active", "budget": { "amount": 30 }}
""";
var response = await client.PutAsync(
"https://api.ayrshare.com/api/ads/google/campaigns/21534567890",
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 := `{"status": "active", "budget": { "amount": 30 }}`
req, _ := http.NewRequest("PUT", "https://api.ayrshare.com/api/ads/google/campaigns/21534567890", strings.NewReader(payload))
req.Header.Add("Authorization", "Bearer API_KEY")
req.Header.Add("Content-Type", "application/json")
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 UpdateCampaign {
public static void main(String[] args) throws Exception {
String payload = """
{"status": "active", "budget": { "amount": 30 }}
""";
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create("https://api.ayrshare.com/api/ads/google/campaigns/21534567890"))
.header("Authorization", "Bearer API_KEY")
.header("Content-Type", "application/json")
.PUT(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/21534567890')
request = Net::HTTP::Put.new(uri)
request['Authorization'] = 'Bearer API_KEY'
request['Content-Type'] = 'application/json'
request.body = <<~JSON
{"status": "active", "budget": { "amount": 30 }}
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",
"campaignStatus": "active"
}
{
"action": "request",
"status": "error",
"code": 101,
"message": "Missing or incorrect parameters. Please verify with the docs. https://www.ayrshare.com/docs/apis",
"details": "This campaign uses a budget shared with other campaigns in Google Ads. Change the shared budget in Google Ads."
}