Here's how to create or delete a [`PartnerLink`](https://developers.google.com/data-manager/api/reference/rpc/google.ads.datamanager.v1#partnerlink) resource. The Data Manager API
supports creating partner links for the following account types:

- Google Ads accounts
- Display \& Video 360 partner or Display \& Video 360 advertiser accounts
- Google Ad Manager accounts

## Create a link

Create a [`PartnerLink`](https://developers.google.com/data-manager/api/reference/rpc/google.ads.datamanager.v1#partnerlink) by sending a [`CreatePartnerLinkRequest`](https://developers.google.com/data-manager/api/reference/rpc/google.ads.datamanager.v1#createpartnerlinkrequest).

### Construct the request body

Create a [`PartnerLink`](https://developers.google.com/data-manager/api/reference/rpc/google.ads.datamanager.v1#partnerlink) resource. Here are the fields to set.

`owning_account`

:   Identifies the advertiser account that owns the link. Set to a
    [`ProductAccount`](https://developers.google.com/data-manager/api/reference/rpc/google.ads.datamanager.v1#productaccount) object.

    Set the `account_type` to the [`AccountType`](https://developers.google.com/data-manager/api/reference/rpc/google.ads.datamanager.v1#accounttype) of the advertiser account.

    Set the `account_id` to the ID of the advertiser account.

    Consult the [destinations and headers guide](https://developers.google.com/data-manager/api/devguides/concepts/destinations#advertiser) for
    instructions on the ID to use for each type of advertiser.

`partner_account`

:   Identifies the partner account. Set to a [`ProductAccount`](https://developers.google.com/data-manager/api/reference/rpc/google.ads.datamanager.v1#productaccount) object.

    Set the `account_type` to the [`AccountType`](https://developers.google.com/data-manager/api/reference/rpc/google.ads.datamanager.v1#accounttype) of the partner account. For
    example, if the link is from an advertiser account to a data partner
    account, set this field to `DATA_PARTNER`.

    Set the `account_id` to the ID of the partner account.

### Construct the request

To create a partner link, construct a [`CreatePartnerLinkRequest`](https://developers.google.com/data-manager/api/reference/rpc/google.ads.datamanager.v1#createpartnerlinkrequest).

1. Set the `parent` to the resource name of the advertiser account. Use the
   format:

       accountTypes/{account_type}/accounts/{account}

2. Set the `partner_link` to the `PartnerLink` resource you constructed.

3. If your credentials are for a Google Account with access to a parent account
   of the advertiser account, such as a Google Ads manager account or a Display \& Video 360
   Partner account, set the `login-account` header as described in
   [Configure destinations and headers](https://developers.google.com/data-manager/api/devguides/concepts/destinations#resource-management).

Here are sample requests in JSON to create a link to a data partner account in
different types of advertiser accounts.

### Google Ads


[Open in API Explorer](https://developers.google.com/data-manager/api/reference/rest/v1/accountTypes.accounts.partnerLinks/create?apix=true&apix_params=%0A%7B%22resource%22:%7B%22owningAccount%22:%7B%22accountType%22:%22GOOGLE_ADS%22,%22accountId%22:%22INSERT_GOOGLE_ADS_CUSTOMER_ID%22%7D,%22partnerAccount%22:%7B%22accountType%22:%22DATA_PARTNER%22,%22accountId%22:%22INSERT_DATA_PARTNER_ACCOUNT_ID%22%7D%7D%7D "Open this sample in API Explorer")

```json
{
    "owningAccount": {
        "accountType": "GOOGLE_ADS",
        "accountId": "INSERT_GOOGLE_ADS_CUSTOMER_ID"
    },
    "partnerAccount": {
        "accountType": "DATA_PARTNER",
        "accountId": "INSERT_DATA_PARTNER_ACCOUNT_ID"
    }
}
```

<br />

### DV360 advertiser


[Open in API Explorer](https://developers.google.com/data-manager/api/reference/rest/v1/accountTypes.accounts.partnerLinks/create?apix=true&apix_params=%0A%7B%22resource%22:%7B%22owningAccount%22:%7B%22accountType%22:%22DISPLAY_VIDEO_ADVERTISER%22,%22accountId%22:%22INSERT_DISPLAY_VIDEO_ADVERTISER_ID%22%7D,%22partnerAccount%22:%7B%22accountType%22:%22DATA_PARTNER%22,%22accountId%22:%22INSERT_DATA_PARTNER_ACCOUNT_ID%22%7D%7D%7D "Open this sample in API Explorer")

```json
{
    "owningAccount": {
        "accountType": "DISPLAY_VIDEO_ADVERTISER",
        "accountId": "INSERT_DISPLAY_VIDEO_ADVERTISER_ID"
    },
    "partnerAccount": {
        "accountType": "DATA_PARTNER",
        "accountId": "INSERT_DATA_PARTNER_ACCOUNT_ID"
    }
}
```

<br />

### DV360 partner


[Open in API Explorer](https://developers.google.com/data-manager/api/reference/rest/v1/accountTypes.accounts.partnerLinks/create?apix=true&apix_params=%0A%7B%22resource%22:%7B%22owningAccount%22:%7B%22accountType%22:%22DISPLAY_VIDEO_PARTNER%22,%22accountId%22:%22INSERT_DISPLAY_VIDEO_PARTNER_ID%22%7D,%22partnerAccount%22:%7B%22accountType%22:%22DATA_PARTNER%22,%22accountId%22:%22INSERT_DATA_PARTNER_ACCOUNT_ID%22%7D%7D%7D "Open this sample in API Explorer")

```json
{
    "owningAccount": {
        "accountType": "DISPLAY_VIDEO_PARTNER",
        "accountId": "INSERT_DISPLAY_VIDEO_PARTNER_ID"
    },
    "partnerAccount": {
        "accountType": "DATA_PARTNER",
        "accountId": "INSERT_DATA_PARTNER_ACCOUNT_ID"
    }
}
```

<br />

### Google Ad Manager


[Open in API Explorer](https://developers.google.com/data-manager/api/reference/rest/v1/accountTypes.accounts.partnerLinks/create?apix=true&apix_params=%0A%7B%22resource%22:%7B%22owningAccount%22:%7B%22accountType%22:%22GOOGLE_AD_MANAGER_AUDIENCE_LINK%22,%22accountId%22:%22INSERT_GAM_AUDIENCE_LINK_ID%22%7D,%22partnerAccount%22:%7B%22accountType%22:%22DATA_PARTNER%22,%22accountId%22:%22INSERT_DATA_PARTNER_ACCOUNT_ID%22%7D%7D%7D "Open this sample in API Explorer")

```json
{
    "owningAccount": {
        "accountType": "GOOGLE_AD_MANAGER_AUDIENCE_LINK",
        "accountId": "INSERT_GAM_AUDIENCE_LINK_ID"
    },
    "partnerAccount": {
        "accountType": "DATA_PARTNER",
        "accountId": "INSERT_DATA_PARTNER_ACCOUNT_ID"
    }
}
```

<br />

### Send the request

Send the request and, if required, include
[request headers](https://developers.google.com/data-manager/api/devguides/concepts/destinations#resource-management). Use credentials for a Google Account with
access to the `owning_account`.

If the request succeeds, the response contains the created [`PartnerLink`](https://developers.google.com/data-manager/api/reference/rpc/google.ads.datamanager.v1#partnerlink) with
the `id` and `name` populated.

If the request fails, inspect the errors to determine the cause of the failure,
update the request and headers to fix any issues, and then send the updated
request and headers.

## Delete a link

To delete a [`PartnerLink`](https://developers.google.com/data-manager/api/reference/rpc/google.ads.datamanager.v1#partnerlink), send a [`DeletePartnerLinkRequest`](https://developers.google.com/data-manager/api/reference/rpc/google.ads.datamanager.v1#deletepartnerlinkrequest) with the `name`
set to the resource name. [Set headers](https://developers.google.com/data-manager/api/devguides/concepts/destinations#resource-management) if required.