The Display \& Video 360 (DV360) service lets you use the
[DV360 API](https://developers.google.com/display-video) in Google Apps Script. This API provides
programmatic access to the Display \& Video API.

This is an advanced service that must be
[enabled before use](https://developers.google.com/apps-script/guides/services/advanced).

## Reference

For detailed information on this service, see the
[reference documentation](https://developers.google.com/display-video/api/reference/rest) for the
DV360 API. Like all advanced services in Apps Script, the DV360
service uses the same objects, methods, and parameters as the public API. For
more information, see
[How method signatures are determined](https://developers.google.com/apps-script/guides/services/advanced#how_method_signatures_are_determined).

To report issues and find other support, see the
[DV360 support guide](https://developers.google.com/display-video/api/support).

## Sample code

The following sample code uses
[version 4](https://developers.google.com/display-video/api/reference/rest/v4) of the API.

### Get a list of partners

This sample logs all of the partners available in the account.
advanced/displayvideo.gs [View on GitHub](https://github.com/googleworkspace/apps-script-samples/blob/main/advanced/displayvideo.gs)

```javascript
/**
 * Logs all of the partners available in the account.
 */
function listPartners() {
  // Retrieve the list of available partners
  try {
    const partners = DisplayVideo.Partners.list();

    if (partners.partners) {
      // Print out the ID and name of each
      for (let i = 0; i < partners.partners.length; i++) {
        const partner = partners.partners[i];
        console.log(
          'Found partner with ID %s and name "%s".',
          partner.partnerId,
          partner.displayName,
        );
      }
    }
  } catch (e) {
    // TODO (Developer) - Handle exception
    console.log("Failed with error: %s", e.error);
  }
}
```

### Get a list of active campaigns

This sample logs names and IDs of all active campaigns. Note the use of
paging tokens to retrieve the whole list.
advanced/displayvideo.gs [View on GitHub](https://github.com/googleworkspace/apps-script-samples/blob/main/advanced/displayvideo.gs)

```javascript
/**
 * Logs names and ID's of all active campaigns.
 * Note the use of paging tokens to retrieve the whole list.
 */
function listActiveCampaigns() {
  const advertiserId = "1234567"; // Replace with your advertiser ID.
  let result;
  let pageToken;
  try {
    do {
      result = DisplayVideo.Advertisers.Campaigns.list(advertiserId, {
        filter: 'entityStatus="ENTITY_STATUS_ACTIVE"',
        pageToken: pageToken,
      });
      if (result.campaigns) {
        for (let i = 0; i < result.campaigns.length; i++) {
          const campaign = result.campaigns[i];
          console.log(
            'Found campaign with ID %s and name "%s".',
            campaign.campaignId,
            campaign.displayName,
          );
        }
      }
      pageToken = result.nextPageToken;
    } while (pageToken);
  } catch (e) {
    // TODO (Developer) - Handle exception
    console.log("Failed with error: %s", e.error);
  }
}
```

### Update the display name of a line item

This sample updates the display name of a line item
advanced/displayvideo.gs [View on GitHub](https://github.com/googleworkspace/apps-script-samples/blob/main/advanced/displayvideo.gs)

```javascript
/**
 * Updates the display name of a line item
 */
function updateLineItemName() {
  const advertiserId = "1234567"; // Replace with your advertiser ID.
  const lineItemId = "123456789"; //Replace with your line item ID.
  const updateMask = "displayName";

  const lineItemDef = {
    displayName: "New Line Item Name (updated from Apps Script!)",
  };

  try {
    const lineItem = DisplayVideo.Advertisers.LineItems.patch(
      lineItemDef,
      advertiserId,
      lineItemId,
      { updateMask: updateMask },
    );
  } catch (e) {
    // TODO (Developer) - Handle exception
    console.log("Failed with error: %s", e.error);
  }
}
```