Send an API request

After you complete the prerequisites, generate the OAuth 2.0 credentials, and configure your client, you are ready to make requests.

This page offers two code samples executing two tasks:

For a full list of Display & Video 360 API methods, see the reference documentation.

Create a line item

Here's how to create a Display & Video 360 line item:

Java

// Create the line item structure.
LineItem lineItem =
    new LineItem()
        .setInsertionOrderId(insertion-order-id)
        .setDisplayName(display-name)
        .setLineItemType("LINE_ITEM_TYPE_DISPLAY_DEFAULT")
        .setEntityStatus("ENTITY_STATUS_DRAFT")
        .setContainsEuPoliticalAds(contains-eu-political-ads);

// Create and set the line item flight.
LineItemFlight lineItemFlight =
    new LineItemFlight().setFlightDateType("LINE_ITEM_FLIGHT_DATE_TYPE_INHERITED");
lineItem.setFlight(lineItemFlight);

// Create and set the line item budget.
LineItemBudget lineItemBudget =
    new LineItemBudget().setBudgetAllocationType("LINE_ITEM_BUDGET_ALLOCATION_TYPE_UNLIMITED");
lineItem.setBudget(lineItemBudget);

// Create and set the pacing setting.
Pacing pacing =
    new Pacing()
        .setPacingPeriod("PACING_PERIOD_FLIGHT")
        .setPacingType("PACING_TYPE_ASAP")
        .setDailyMaxMicros(10_000L);
lineItem.setPacing(pacing);

// Create and set the frequency cap.
FrequencyCap frequencyCap =
    new FrequencyCap().setTimeUnit("TIME_UNIT_DAYS").setTimeUnitCount(1).setMaxImpressions(10);
lineItem.setFrequencyCap(frequencyCap);

// Create and set the partner revenue model.
PartnerRevenueModel partnerRevenueModel =
    new PartnerRevenueModel()
        .setMarkupType("PARTNER_REVENUE_MODEL_MARKUP_TYPE_TOTAL_MEDIA_COST_MARKUP")
        .setMarkupAmount(100L);
lineItem.setPartnerRevenueModel(partnerRevenueModel);

// Create and set the bidding strategy.
BiddingStrategy biddingStrategy =
    new BiddingStrategy()
        .setMaximizeSpendAutoBid(
            new MaximizeSpendBidStrategy()
                .setPerformanceGoalType("BIDDING_STRATEGY_PERFORMANCE_GOAL_TYPE_AV_VIEWED"));
lineItem.setBidStrategy(biddingStrategy);

// Configure the create request.
LineItems.Create request = service.advertisers().lineItems().create(advertiser-id, lineItem);

// Create the line item.
LineItem response = request.execute();

// Display the new line item ID.
System.out.printf("Line item %s was created.", response.getName());

Python

# Create a line item object with example values.
line_item_obj = {
    "insertionOrderId": insertion-order-id,
    "displayName": display-name,
    "lineItemType": "LINE_ITEM_TYPE_DISPLAY_DEFAULT",
    "entityStatus": "ENTITY_STATUS_DRAFT",
    "flight": {"flightDateType": "LINE_ITEM_FLIGHT_DATE_TYPE_INHERITED"},
    "budget": {
        "budgetAllocationType": "LINE_ITEM_BUDGET_ALLOCATION_TYPE_FIXED"
    },
    "pacing": {
        "pacingPeriod": "PACING_PERIOD_DAILY",
        "pacingType": "PACING_TYPE_EVEN",
        "dailyMaxMicros": 10000,
    },
    "frequencyCap": {
        "timeUnit": "TIME_UNIT_DAYS",
        "timeUnitCount": 1,
        "maxImpressions": 10,
    },
    "partnerRevenueModel": {
        "markupType": "PARTNER_REVENUE_MODEL_MARKUP_TYPE_CPM",
        "markupAmount": 10000,
    },
    "bidStrategy": {"fixedBid": {"bidAmountMicros": 100000}},
    "containsEuPoliticalAds": contains-eu-political-ads
}

# Build and execute request.
response = (
    service.advertisers()
    .lineItems()
    .create(advertiserId=advertiser-id, body=line_item_obj)
    .execute()
)

# Display the new line item.
print(f"Line Item {response['name']} was created.")

PHP

// Create the line item structure.
$lineItem = new Google_Service_DisplayVideo_LineItem();
$lineItem->setInsertionOrderId(insertion-order-id);
$lineItem->setDisplayName(display-name);
$lineItem->setLineItemType('LINE_ITEM_TYPE_DISPLAY_DEFAULT');
$lineItem->setEntityStatus('ENTITY_STATUS_DRAFT');
$lineItem->setContainsEuPoliticalAds(contains-eu-political-ads);

// Create and set the line item flight.
$flight = new Google_Service_DisplayVideo_LineItemFlight();
$flight->setFlightDateType('LINE_ITEM_FLIGHT_DATE_TYPE_INHERITED');
$lineItem->setFlight($flight);

// Create and set the line item budget.
$budget = new Google_Service_DisplayVideo_LineItemBudget();
$budget->setBudgetAllocationType(
    'LINE_ITEM_BUDGET_ALLOCATION_TYPE_UNLIMITED'
);
$lineItem->setBudget($budget);

// Create and set the pacing setting.
$pacing = new Google_Service_DisplayVideo_Pacing();
$pacing->setPacingPeriod('PACING_PERIOD_FLIGHT');
$pacing->setPacingType('PACING_TYPE_ASAP');
$pacing->setDailyMaxMicros(10000);
$lineItem->setPacing($pacing);

// Create and set the frequency cap.
$frequencyCap = new Google_Service_DisplayVideo_FrequencyCap();
$frequencyCap->setMaxImpressions(10);
$frequencyCap->setTimeUnit('TIME_UNIT_DAYS');
$frequencyCap->setTimeUnitCount(1);
$lineItem->setFrequencyCap($frequencyCap);

// Create and set the partner revenue model.
$partnerRevenueModel =
    new Google_Service_DisplayVideo_PartnerRevenueModel();
$partnerRevenueModel->setMarkupType(
    'PARTNER_REVENUE_MODEL_MARKUP_TYPE_TOTAL_MEDIA_COST_MARKUP'
);
$partnerRevenueModel->setMarkupAmount(100);
$lineItem->setPartnerRevenueModel($partnerRevenueModel);

// Create and set the bidding strategy.
$MaxSpendBidStrategy = new Google_Service_DisplayVideo_MaximizeSpendBidStrategy();
$MaxSpendBidStrategy->setPerformanceGoalType('BIDDING_STRATEGY_PERFORMANCE_GOAL_TYPE_AV_VIEWED');
$biddingStrategy = new Google_Service_DisplayVideo_BiddingStrategy();
$biddingStrategy->setMaximizeSpendAutoBid($MaxSpendBidStrategy);
$lineItem->setBidStrategy($biddingStrategy);

// Call the API, creating the line item under the advertiser and
// insertion order given.
try {
    $result = $this->service->advertisers_lineItems->create(
        advertiser-id,
        $lineItem
    );
} catch (\Exception $e) {
    $this->renderError($e);
    return;
}

// Display the new line item ID.
printf('<p>Line Item %s was created.</p>', $result['name']);

Retrieve a line item

Here's how to retrieve a Display & Video 360 line item:

Java

// Get the line item.
LineItem response = service.advertisers().lineItems().get(advertiser-id, line-item-id).execute();

// Print the retrieved line item name.
System.out.printf("Line item %s was retrieved.", response.getName());

Python

# Get the line item.
line_item_response = (
    service.advertisers()
    .lineItems()
    .get(
        advertiserId=advertiser-id,
        lineItemId=line-item-id,
    )
    .execute()
)

# Print the retrieved line item name.
print(f'Line item {line_item_response["name"]} retrieved.')

PHP

// Call the API to retrieve the line item.
try {
    $response =
        $this->service->advertisers_lineItems->get(
            advertiser-id,
            line-item-id
        );
} catch (\Exception $e) {
    $this->renderError($e);
    return;
}

// Print the retrieved line item name.
printf('

Line item %s was retrieved.

', $response['name']);