> For the complete documentation index, see [llms.txt](https://edrus.gitbook.io/appgregator-api-docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://edrus.gitbook.io/appgregator-api-docs/appgregators/marketing/facebook-ads/before-starting/api/campaign/ad-sets.md).

# Ad Sets

Ad sets are groups of ads, and are used to configure the budget and period the ads should run for. All ads contained within an ad set should have the same targeting, budget, billing, optimization goal, and duration.

| Value for parameter of 'publisher\_platforms'     | Required | Description                                                                                                                                                                                              |
| ------------------------------------------------- | -------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| facebook, instagram, messenger, audience\_network | Optional | The publishing channel for your ad. You can set the publishing channel position by setting them within facebook\_positions, instagram\_positions, audience\_network\_positions, or messenger\_positions. |

<mark style="color:green;">`POST`</mark> `https://us-central1-appgregator.cloudfunctions.net/facebook/adaccounts/adsets/`

#### Query Parameters

| Name                                               | Type   | Description           |
| -------------------------------------------------- | ------ | --------------------- |
| name<mark style="color:red;">\*</mark>             | String | ft-4                  |
| connection\_name<mark style="color:red;">\*</mark> | String | fbads-01              |
| adaccount\_id<mark style="color:red;">\*</mark>    | String | act\_1514519918873559 |

#### Headers

| Name                                        | Type   | Description |
| ------------------------------------------- | ------ | ----------- |
| x-api-key<mark style="color:red;">\*</mark> | String | U2Fsd...    |

{% tabs %}
{% tab title="201: Created Created" %}

```javascript
{
    "id": "23852148656900549"
}
```

{% endtab %}

{% tab title="400: Bad Request Bad Request" %}

```javascript
{
    "error": {
        "message": "Invalid parameter",
        "type": "OAuthException",
        "code": 100,
        "error_subcode": 1815430,
        "is_transient": false,
        "error_user_title": "Tidak ditemukan objek promosi",
        "error_user_msg": "Harap tentukan objek yang dipromosikan untuk set iklan tersebut.",
        "fbtrace_id": "AbyZ-PwJA_CeH-3qrZbstU6"
    }
}
```

{% endtab %}
{% endtabs %}

<details>

<summary>Body JSON</summary>

```shell
{
    "name" : "Campaign5 AdSet",
    "lifetime_budget" : 105000,
    "start_time" : "2022-09-26T09:37:09-0700",
    "end_time" : "2022-10-03T09:37:09-0700",
    "campaign_id" : "23852148573750549",
    "bid_amount" : 500,
    "daily_budget" : "1000",
    "billing_event" : "IMPRESSIONS",
    "optimization_goal" : "POST_ENGAGEMENT",
    "promoted_object": {
        "page_id" : "1842784136033747"
    },    
    "targeting" : {
       "age_min": 20,
       "age_max": 24,
       "behaviors": [
         {
           "id": 6002714895372,
           "name": "All travelers"
         }
       ],
       "genders": [
         1
       ],
       "geo_locations": {
         "countries": [
           "US"
         ],
         "regions": [
           {
             "key": "4081"
           }
         ],
         "cities": [
           {
             "key": "777934",
             "radius": 10,
             "distance_unit": "mile"
           }
         ]
       },
       "interests": [
         {
           "id": "6003108220790",
           "name": "National Basketball Association"
         }
       ],
       "life_events": [
         {
           "id": 6003053860372,
           "name": "Jauh dari Kota Asal"
         }
       ],
       "facebook_positions": [
         "feed"
       ],
       "publisher_platforms": [
         "facebook",
         "audience_network"
       ]
     },
    "status" : "PAUSED"
}
```

</details>

{% tabs %}
{% tab title="cURL" %}

```shell
curl --location --request POST 'https://us-central1-appgregator.cloudfunctions.net/facebook/adaccounts/adsets?name=ft-4&connection_name=fbads-01&adaccount_id=act_1514519918873559' \
--header 'x-api-key: U2Fsd...' \
--header 'Content-Type: application/json' \
--data-raw '{
    "name" : "Campaign5 AdSet",
    "lifetime_budget" : 105000,
    "start_time" : "2022-09-26T09:37:09-0700",
    "end_time" : "2022-10-03T09:37:09-0700",
    "campaign_id" : "23852148573750549",
    "bid_amount" : 500,
    "daily_budget" : "1000",
    "billing_event" : "IMPRESSIONS",
    "optimization_goal" : "POST_ENGAGEMENT",
    "promoted_object": {
        "page_id" : "1842784136033747"
    },    
    "targeting" : {
       "age_min": 20,
       "age_max": 24,
       "behaviors": [
         {
           "id": 6002714895372,
           "name": "All travelers"
         }
       ],
       "genders": [
         1
       ],
       "geo_locations": {
         "countries": [
           "US"
         ],
         "regions": [
           {
             "key": "4081"
           }
         ],
         "cities": [
           {
             "key": "777934",
             "radius": 10,
             "distance_unit": "mile"
           }
         ]
       },
       "interests": [
         {
           "id": "6003108220790",
           "name": "National Basketball Association"
         }
       ],
       "life_events": [
         {
           "id": 6003053860372,
           "name": "Jauh dari Kota Asal"
         }
       ],
       "facebook_positions": [
         "feed"
       ],
       "publisher_platforms": [
         "facebook",
         "audience_network"
       ]
     },
    "status" : "PAUSED"
}'
```

{% endtab %}

{% tab title="NodeJS - Axios" %}

```javascript
var axios = require('axios');
var data = JSON.stringify({
  "name": "Campaign5 AdSet",
  "lifetime_budget": 105000,
  "start_time": "2022-09-26T09:37:09-0700",
  "end_time": "2022-10-03T09:37:09-0700",
  "campaign_id": "23852148573750549",
  "bid_amount": 500,
  "daily_budget": "1000",
  "billing_event": "IMPRESSIONS",
  "optimization_goal": "POST_ENGAGEMENT",
  "promoted_object": {
    "page_id": "1842784136033747"
  },
  "targeting": {
    "age_min": 20,
    "age_max": 24,
    "behaviors": [
      {
        "id": 6002714895372,
        "name": "All travelers"
      }
    ],
    "genders": [
      1
    ],
    "geo_locations": {
      "countries": [
        "US"
      ],
      "regions": [
        {
          "key": "4081"
        }
      ],
      "cities": [
        {
          "key": "777934",
          "radius": 10,
          "distance_unit": "mile"
        }
      ]
    },
    "interests": [
      {
        "id": "6003108220790",
        "name": "National Basketball Association"
      }
    ],
    "life_events": [
      {
        "id": 6003053860372,
        "name": "Jauh dari Kota Asal"
      }
    ],
    "facebook_positions": [
      "feed"
    ],
    "publisher_platforms": [
      "facebook",
      "audience_network"
    ]
  },
  "status": "PAUSED"
});

var config = {
  method: 'post',
  url: 'https://us-central1-appgregator.cloudfunctions.net/facebook/adaccounts/adsets?name=ft-4&connection_name=fbads-01&adaccount_id=act_1514519918873559',
  headers: { 
    'x-api-key': 'U2Fsd...', 
    'Content-Type': 'application/json'
  },
  data : data
};

axios(config)
.then(function (response) {
  console.log(JSON.stringify(response.data));
})
.catch(function (error) {
  console.log(error);
});

```

{% endtab %}

{% tab title="PHP - cURL" %}

```php
<?php

$curl = curl_init();

curl_setopt_array($curl, array(
  CURLOPT_URL => 'https://us-central1-appgregator.cloudfunctions.net/facebook/adaccounts/adsets?name=ft-4&connection_name=fbads-01&adaccount_id=act_1514519918873559',
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => '',
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 0,
  CURLOPT_FOLLOWLOCATION => true,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => 'POST',
  CURLOPT_POSTFIELDS =>'{
    "name" : "Campaign5 AdSet",
    "lifetime_budget" : 105000,
    "start_time" : "2022-09-26T09:37:09-0700",
    "end_time" : "2022-10-03T09:37:09-0700",
    "campaign_id" : "23852148573750549",
    "bid_amount" : 500,
    "daily_budget" : "1000",
    "billing_event" : "IMPRESSIONS",
    "optimization_goal" : "POST_ENGAGEMENT",
    "promoted_object": {
        "page_id" : "1842784136033747"
    },    
    "targeting" : {
       "age_min": 20,
       "age_max": 24,
       "behaviors": [
         {
           "id": 6002714895372,
           "name": "All travelers"
         }
       ],
       "genders": [
         1
       ],
       "geo_locations": {
         "countries": [
           "US"
         ],
         "regions": [
           {
             "key": "4081"
           }
         ],
         "cities": [
           {
             "key": "777934",
             "radius": 10,
             "distance_unit": "mile"
           }
         ]
       },
       "interests": [
         {
           "id": "6003108220790",
           "name": "National Basketball Association"
         }
       ],
       "life_events": [
         {
           "id": 6003053860372,
           "name": "Jauh dari Kota Asal"
         }
       ],
       "facebook_positions": [
         "feed"
       ],
       "publisher_platforms": [
         "facebook",
         "audience_network"
       ]
     },
    "status" : "PAUSED"
}',
  CURLOPT_HTTPHEADER => array(
    'x-api-key: U2Fsd...',
    'Content-Type: application/json'
  ),
));

$response = curl_exec($curl);

curl_close($curl);
echo $response;

```

{% endtab %}
{% endtabs %}
