## Overview

This endpoint creates a single Campaign along with nested Flights, Creatives and Ads.

Unlike the /v1/campaign endpoint, this /v2/campaign endpoint returns only the Id values of the created entities.

The settable attributes for the Campaign, Flight and Creative objects are very similar to the corresponding v1 endpoints. The only customizations allowed to Ads are to set the IsActive flag, ExternalMetadata, and AttributionSettings. It is not currently possible to set any Delivery settings of the nested Ads. Once created, all of these entities can be retrieved, updated and deleted normally via the v1 endpoints.

This endpoint also can create Jobs of type `create-ads-from-products` and `create-ads-from-product-query`. These should be provided in a `Jobs` key on the nested Flight where the ads should be created. Those jobs will be submitted during this API call and completed asynchronously. It is up to the caller to use the Jobs endpoints to verify the results of the jobs. See [Creating Ads from Products via API](https://dev.kevel.com/docs/creating-ads-from-products-via-api) for more details.

### Differences between v1 and v2

- The v1/campaign endpoint supports creating Flights but not Creatives and Ads within those Flights. Additionally, if the Create Campaign call is made with nested Flight data and that Flight data has erroneous fields, the parent Campaign is still created, but a 400 response is returned with an error message.
- The v2/campaign endpoint validates all entities and either all entities are created successfully or none are.

### Limits on number of entities created

The maximum number of entities that can be created via this endpoint is 10. This count includes the Campaign itself plus Flights, Ads, and Creatives included in the request. Ads created using Jobs are not included in this limit.

### Campaign Attributes

- **AdvertiserId**  
  `int32`  
  required  
  The advertiser's ID for the campaign.

- **Name**  
  `string`  
  required  
  The campaign name. Max 200 characters.

- **Flights**  
  `array of objects`  
  You can pass an array of flights, a blank array, or not include. See [Create Flight](https://dev.kevel.com/reference/flight#create-flight) endpoint.

#### Flights Object

- **IsActive**  
  `boolean`  
  Defaults to false
  
  Specifies whether campaign should be active (serving ads). Defaults to `false`.

- **FreqCapType**  
  `int32`  
  The enum value for how often frequency capping should occur. `1 = Hour, 2 = Day, 3 = Minute`.

- **FreqCap**  
  `int32`  
  The number of times the frequency cap should occur.

- **FreqCapDuration**  
  `int32`  
  Specifies how often the frequency cap should occur.

- **DontAffectParentFreqCap**  
  `boolean`  
  "Opts-out" campaign from advertiser-level frequency cap settings.

- **CapType**  
  `int32`  
  Set to `CapType = 4`. Campaigns can only budget cap on revenue metric. Do not set to `0` - if removing, set to `null`.

- **DailyCapAmount**  
  `int32`  
  The max daily revenue.

- **LifetimeCapAmount**  
  `int32`  
  The max lifetime revenue.

- **CustomFieldsJson**  
  `string`  
  Stringified JSON value containing Custom Fields. See [Custom Fields Documentation](https://dev.kevel.com/docs/custom-fields).

- **SalespersonId**  
  `int32`  
  Network-level login Id of salesperson.

## Example Request

```bash
curl -X POST -H 'X-Adzerk-ApiKey:<API-KEY>' -H "Content-Type:application/json" "https://api.kevel.co/v2/campaign" --data-binary '{"Name":"Nike Q4 Campaign","AdvertiserId":12345,"IsActive":true}'
```

## Example Response

```json
{
  "Id": 1000069242,
  "Flights": [
    {
      "Id": 1003195679,
      "Ads": [
        {
          "Id": 1001151589,
          "Creative": {
            "Id": 1000039937
          }
        }
      ]
    },
    {
      "Id": 1003195680,
      "Ads": [
        {
          "Id": 1001151590,
          "Creative": {
            "Id": 1000039938
          }
        },
        {
          "Creative": {
            "Id": 1000039939
          },
          "Id": 1001151591
        }
      ]
    }
  ]
}
```
