> ## Documentation Index
> Fetch the complete documentation index at: https://www.ayrshare.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# 更新廣告活動

> 啟動或暫停 Google Ads 廣告活動、重新命名，或變更其每日預算或結束日期。

啟動或暫停您透過 Ayrshare 建立的 Google Ads 廣告活動、重新命名，或變更其每日預算或結束日期。

<ul>
  <li>請至少傳送一個欄位。同一請求中的所有變更會一併套用，或全部不套用。</li>
  <li>建立廣告活動後，便無法變更 `type`、`accountId` 或 `euPoliticalAdvertising`。</li>
  <li>不需要 `Idempotency-Key`：再次傳送相同的變更只會設定相同的值。</li>
  <li>回應會返回廣告活動的 `campaignStatus`。若要讀取其他欄位，請使用 [取得廣告活動](https://www.ayrshare.com/docs/apis/ads/google/get-campaign.md)。</li>
</ul>

## 請求頭參數

**Authorization** `string` *required*

[API Key](https://www.ayrshare.com/docs/apis/overview.md#authorization) of the Primary Profile.

Format: `Authorization: Bearer API_KEY`
**Profile-Key** `string`

[Profile Key](https://www.ayrshare.com/docs/apis/overview.md#profile-key-format) of a User Profile.

Format: `Profile-Key: PROFILE_KEY`

## 路徑參數

**id** `string` *required*

建立廣告活動時返回的 `campaignId`。

## 請求體參數

**status** `string`

`active` 或 `paused`。當 Ayrshare 已在 Google 上暫停廣告時，只傳送 `status: "paused"` 的請求不會被阻擋。

**name** `string`

新的廣告活動名稱，1 到 255 個字元，不可包含換行。

**budget** `object`

`{ "amount": number }`：新的每日支出金額，以廣告帳戶的貨幣計算，最多兩位小數。若廣告活動的預算已在 Google Ads 中與其他廣告活動共用，會返回 `code: 101`：請在 Google Ads 中變更共用預算。

**schedule** `object`

`{ "end": string }`：新的結束日期，格式為 ISO 日期（`2026-11-30`）或日期時間。Google 以廣告帳戶時區的完整日期進行排程，因此廣告活動會於當天 23:59:59 結束。結束日期可以與開始日期為同一天，但不能更早。

## 錯誤

| 代碼 | 發生時機 |
| - | - |
| `101` | 未傳送任何欄位、某個欄位無效，或預算與其他廣告活動共用。`details` 會說明是哪一種情況。 |
| `205` | Google 拒絕了變更。`details` 會說明需要變更的內容。 |
| `400` | 廣告活動不屬於您、不存在，或已在 Google Ads 中移除。當您連結的 Google 使用者無法存取該廣告帳戶，或 Google Ads 存取權已被撤銷時，也會返回此錯誤。 |
| `370` | Google 無法完成請求。請再試一次。 |

```bash cURL theme={"system"}
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 }}'
```

```javascript JavaScript theme={"system"}
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);
```

```python Python theme={"system"}
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 PHP theme={"system"}
<?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;
}
?>
```

```csharp C# theme={"system"}
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);
    }
}
```

```go Go theme={"system"}
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))
}
```

```java Java theme={"system"}
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());
    }
}
```

```ruby Ruby theme={"system"}
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
```

```json 200: Success theme={"system"}
{
  "status": "success",
  "platform": "google",
  "campaignId": "21534567890",
  "campaignStatus": "active"
}
```

```json 400: Shared Budget theme={"system"}
{
  "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."
}
```


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.