> ## 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.

# Ad Campaigns

> Create, read, and update ad campaigns that have no post behind them, such as search campaigns.

A campaign is an ad that does not start from one of your posts. Use it for formats such as search ads, where you set a budget, a bidding strategy, and targeting, and the network builds the ads.

To promote a post you have already published, use [Boost Post](https://www.ayrshare.com/docs/apis/ads/facebook/boost-post.md) instead.

> [!NOTE]
>
> Google accepts campaigns. See [Google Search Campaigns](https://www.ayrshare.com/docs/apis/ads/google/search-campaigns.md) and [Google Performance Max Campaigns](https://www.ayrshare.com/docs/apis/ads/google/performance-max-campaigns.md) for what is specific to Google. Other networks refuse a campaign request with `code: 101`, and `details` says why. On Facebook, for example, it says `campaignCreation is not supported on facebook.`

## Endpoints

| Method | Path | What it does |
| - | - | - |
| `POST` | `/ads/{platform}/campaigns` | Create a campaign |
| `GET` | `/ads/{platform}/campaigns/{id}` | Get one campaign |
| `PUT` | `/ads/{platform}/campaigns/{id}` | Change one campaign |

`{platform}` is the ads network. `{id}` is the campaign id returned when you created it. You can read and change only campaigns created through Ayrshare by the same user profile.

## Header Parameters

**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`

**Idempotency-Key** `string` *required*

Required to create a campaign. Send a new unique value, such as a UUID, for each new campaign. If you repeat a request with the same key, Ayrshare returns the first response, marked `idempotentReplayed: true`, and creates nothing new. You can send the key in the body as `idempotencyKey` instead. If you send both, they must match.

## Create a Campaign

`POST /ads/{platform}/campaigns`

New campaigns start `paused` unless you send `status: "active"`, so nothing is spent until you choose to start.

**accountId** `string` *required*

The ad account to create the campaign in.

**name** `string` *required*

The campaign name, 1 to 255 characters.

**type** `string` *required*

The campaign type: `search` or `performanceMax`. Each network supports only some types. A type the network does not support answers `code: 101` and lists the supported ones.

**budget** `object` *required*

**properties**

**amount** `number` *required*

How much to spend per day, with at most two decimal places.

**type** `string` *required*

`daily`.

**currency** `string`

ISO 4217 code, such as `USD`. Defaults to the ad account's currency. Only some networks accept it.

**bidding** `object` *required*

**properties**

**strategy** `string` *required*

`maximizeConversions`, `maximizeConversionValue`, `targetCpa`, `targetRoas`, `maximizeClicks`, or `manualCpc`. Each network supports only some strategies.

**targetCpa** `number`

Target cost per action. Required with `targetCpa`, and not accepted with any other strategy.

**targetRoas** `number`

Target return on ad spend, for example `3.5` for 350%. Required with `targetRoas`, and not accepted with any other strategy.

**euPoliticalAdvertising** `boolean` *required*

Whether the campaign is political advertising in the EU. You must always send it. Ayrshare never fills it in for you.

**schedule** `object`

**properties**

**start** `string`

When to start: an ISO date (`2026-11-01`) or an ISO date-time with `Z` or an offset (`2026-11-01T09:00:00Z`). Defaults to now.

**end** `string`

When to stop, in the same format as `start`. Must be after `start`, or after now if you leave `start` out. Leave it out to run with no end date. A network that schedules whole days, such as Google, also accepts an `end` on the same day as `start`, for a one-day campaign.

**targeting** `object`

Each network supports only some targeting. A field the network does not support answers `code: 101`.

**properties**

**locations** `string[]`

The network's own location ids.

**languages** `string[]`

The network's own language ids.

**status** `string` (default: paused)

`active` or `paused`.

**platformOptions** `object`

Options for one network only, under that network's name, for example `{ "facebook": { ... } }`. Options for any other network answer `code: 101`.

```bash cURL theme={"system"}
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": "Spring search",
  "type": "search",
  "budget": { "amount": 20, "type": "daily" },
  "bidding": { "strategy": "maximizeClicks" },
  "euPoliticalAdvertising": false,
  "platformOptions": {
    "google": {
      "finalUrl": "https://example.com/spring",
      "headlines": ["Spring sale", "Shoes 30% off", "Free returns"],
      "descriptions": ["Every shoe 30% off this week.", "Free returns on every order."],
      "keywords": [{ "text": "running shoes", "matchType": "phrase" }]
    }
  }
}'
```

```javascript JavaScript theme={"system"}
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": "Spring search",
    "type": "search",
    "budget": { "amount": 20, "type": "daily" },
    "bidding": { "strategy": "maximizeClicks" },
    "euPoliticalAdvertising": false,
    "platformOptions": {
      "google": {
        "finalUrl": "https://example.com/spring",
        "headlines": ["Spring sale", "Shoes 30% off", "Free returns"],
        "descriptions": ["Every shoe 30% off this week.", "Free returns on every order."],
        "keywords": [{ "text": "running shoes", "matchType": "phrase" }]
      }
    }
  })
})
  .then((res) => res.json())
  .then((json) => console.log(json))
  .catch(console.error);
```

```python Python theme={"system"}
import requests

headers = {
    "Authorization": "Bearer API_KEY",
    "Idempotency-Key": "6f1c2d4e-0b7a-4c55-9a3e-2f8d1b7c9e10",
}

payload = {
  "accountId": "123-456-7890",
  "name": "Spring search",
  "type": "search",
  "budget": { "amount": 20, "type": "daily" },
  "bidding": { "strategy": "maximizeClicks" },
  "euPoliticalAdvertising": False,
  "platformOptions": {
    "google": {
      "finalUrl": "https://example.com/spring",
      "headlines": ["Spring sale", "Shoes 30% off", "Free returns"],
      "descriptions": ["Every shoe 30% off this week.", "Free returns on every order."],
      "keywords": [{ "text": "running shoes", "matchType": "phrase" }]
    }
  }
}

r = requests.post("https://api.ayrshare.com/api/ads/google/campaigns", headers=headers, json=payload)

print(r.json())
```

```php PHP theme={"system"}
<?php
$payload = <<<'JSON'
{
  "accountId": "123-456-7890",
  "name": "Spring search",
  "type": "search",
  "budget": { "amount": 20, "type": "daily" },
  "bidding": { "strategy": "maximizeClicks" },
  "euPoliticalAdvertising": false,
  "platformOptions": {
    "google": {
      "finalUrl": "https://example.com/spring",
      "headlines": ["Spring sale", "Shoes 30% off", "Free returns"],
      "descriptions": ["Every shoe 30% off this week.", "Free returns on every order."],
      "keywords": [{ "text": "running shoes", "matchType": "phrase" }]
    }
  }
}
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;
}
?>
```

```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");
        client.DefaultRequestHeaders.Add("Idempotency-Key", "6f1c2d4e-0b7a-4c55-9a3e-2f8d1b7c9e10");

        var payload = """
            {
              "accountId": "123-456-7890",
              "name": "Spring search",
              "type": "search",
              "budget": { "amount": 20, "type": "daily" },
              "bidding": { "strategy": "maximizeClicks" },
              "euPoliticalAdvertising": false,
              "platformOptions": {
                "google": {
                  "finalUrl": "https://example.com/spring",
                  "headlines": ["Spring sale", "Shoes 30% off", "Free returns"],
                  "descriptions": ["Every shoe 30% off this week.", "Free returns on every order."],
                  "keywords": [{ "text": "running shoes", "matchType": "phrase" }]
                }
              }
            }
            """;

        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);
    }
}
```

```go Go theme={"system"}
package main

import (
    "fmt"
    "io"
    "net/http"
    "strings"
)

func main() {
    payload := `{
  "accountId": "123-456-7890",
  "name": "Spring search",
  "type": "search",
  "budget": { "amount": 20, "type": "daily" },
  "bidding": { "strategy": "maximizeClicks" },
  "euPoliticalAdvertising": false,
  "platformOptions": {
    "google": {
      "finalUrl": "https://example.com/spring",
      "headlines": ["Spring sale", "Shoes 30% off", "Free returns"],
      "descriptions": ["Every shoe 30% off this week.", "Free returns on every order."],
      "keywords": [{ "text": "running shoes", "matchType": "phrase" }]
    }
  }
}`

    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))
}
```

```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 CreateCampaign {
    public static void main(String[] args) throws Exception {
        String payload = """
            {
              "accountId": "123-456-7890",
              "name": "Spring search",
              "type": "search",
              "budget": { "amount": 20, "type": "daily" },
              "bidding": { "strategy": "maximizeClicks" },
              "euPoliticalAdvertising": false,
              "platformOptions": {
                "google": {
                  "finalUrl": "https://example.com/spring",
                  "headlines": ["Spring sale", "Shoes 30% off", "Free returns"],
                  "descriptions": ["Every shoe 30% off this week.", "Free returns on every order."],
                  "keywords": [{ "text": "running shoes", "matchType": "phrase" }]
                }
              }
            }
            """;

        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());
    }
}
```

```ruby Ruby theme={"system"}
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": "Spring search",
    "type": "search",
    "budget": { "amount": 20, "type": "daily" },
    "bidding": { "strategy": "maximizeClicks" },
    "euPoliticalAdvertising": false,
    "platformOptions": {
      "google": {
        "finalUrl": "https://example.com/spring",
        "headlines": ["Spring sale", "Shoes 30% off", "Free returns"],
        "descriptions": ["Every shoe 30% off this week.", "Free returns on every order."],
        "keywords": [{ "text": "running shoes", "matchType": "phrase" }]
      }
    }
  }
JSON

response = Net::HTTP.start(uri.hostname, uri.port, use_ssl: true) do |http|
  http.request(request)
end

puts response.body
```

A successful create answers `status: "success"`, the `campaignId`, and the campaign's own state as `campaignStatus` (`active` or `paused`). Get and update answer the same way.

## Get a Campaign

`GET /ads/{platform}/campaigns/{id}`

Returns the campaign as the network reports it. A campaign that is not yours, or that does not exist, answers `code: 400`.

## Update a Campaign

`PUT /ads/{platform}/campaigns/{id}`

Send at least one of these fields. You cannot change `type`, `accountId`, or `euPoliticalAdvertising` after you create the campaign.

**name** `string`

The new campaign name.

**status** `string`

`active` or `paused`. A request that only sends `status: "paused"` is not blocked when Ayrshare has paused ads on that network. It still needs a linked network, and it can still fail if the network itself is down.

**budget** `object`

`{ "amount": number }`: the new amount to spend per day.

**schedule** `object`

`{ "end": string }`: the new end date, in the same format as `schedule.start`. It must be after the campaign's start. A network that schedules whole days, such as Google, also accepts the same day as the start.

## Errors

These errors carry an Ayrshare `code`:

| Code | When |
| - | - |
| `101` | The request is invalid, the network does not support campaigns or this campaign type, or the idempotency key is missing. `details` says which. Ayrshare checks for the key after it confirms the network is linked, so an unlinked profile gets the "not linked" error first. |
| `400` | The campaign is not yours or does not exist. |
| `424` | Ads on this network are temporarily unavailable. |

A create can also answer with one of these HTTP statuses. Its body has no `code`, only `{ "action": "createAdCampaign", "status": "error", "message": "..." }`:

| HTTP status | When |
| - | - |
| `409` | The idempotency key was used with a different request, or the request with this key is still in progress. Do not retry with a new key. Check the ad account first. |
| `503` | Ayrshare could not safely reserve the idempotency key, so nothing was created. Retry later with the same key. |


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