Before creating a hotel ad, ensure you have an existing Hotel campaign and an
ad group with its [`type`](https://developers.google.com/google-ads/api/reference/rpc/v26/AdGroup.md.txt#type) set to [`HOTEL_ADS`](https://developers.google.com/google-ads/api/reference/rpc/v26/AdGroupTypeEnum.AdGroupType.md.txt#hotel_ads).
Attaching a [`HotelAdInfo`](https://developers.google.com/google-ads/api/reference/rpc/v26/HotelAdInfo.md.txt) to an [`AdGroup`](https://developers.google.com/google-ads/api/reference/rpc/v26/AdGroup.md.txt) that
isn't configured for Hotel campaigns triggers an API mutate error.

Creating a Hotel ad involves two steps:

1. Create an [`Ad`](https://developers.google.com/google-ads/api/reference/rpc/v26/Ad.md.txt) and set its [`hotel_ad`](https://developers.google.com/google-ads/api/reference/rpc/v26/Ad.md.txt#hotel_ad) field to a new [`HotelAdInfo`](https://developers.google.com/google-ads/api/reference/rpc/v26/HotelAdInfo.md.txt) instance.
2. Create an [`AdGroupAd`](https://developers.google.com/google-ads/api/reference/rpc/v26/AdGroupAd.md.txt) to associate the `Ad` with your hotel ad group.

> [!IMPORTANT]
> **Key Point:** To serve Hotel Ads, your [`AdGroupAd`](https://developers.google.com/google-ads/api/reference/rpc/v26/AdGroupAd.md.txt) must have its [`ad`](https://developers.google.com/google-ads/api/reference/rpc/v26/AdGroupAd.md.txt#ad) set and its [`status`](https://developers.google.com/google-ads/api/reference/rpc/v26/AdGroupAd.md.txt#status) set to [`ENABLED`](https://developers.google.com/google-ads/api/reference/rpc/v26/AdGroupAdStatusEnum.AdGroupAdStatus.md.txt#enabled), and its parent `AdGroup` and `Campaign` must also be active. You can use [GAQL queries](https://developers.google.com/google-ads/api/docs/hotel-ads/reporting.md.txt) to verify these values.

While you can create multiple ad group ads in a single hotel ad group,
impression distribution among them is arbitrary. To simplify reporting and
metric attribution, create only **one** ad group ad per ad group.

## Code example

The following code example demonstrates how to create and associate a hotel ad
with an existing ad group:


### Java

```java
private String addHotelAdGroupAd(
    GoogleAdsClient googleAdsClient, long customerId, String adGroupResourceName) {
  // Creates a new hotel ad.
  Ad ad = Ad.newBuilder().setHotelAd(HotelAdInfo.newBuilder().build()).build();
  // Creates a new ad group ad and sets the hotel ad to it.
  AdGroupAd adGroupAd =
      AdGroupAd.newBuilder()
          // Sets the ad to the ad created above.
          .setAd(ad)
          // Set the ad group ad to enabled.  Setting this to paused will cause an error
          // for hotel campaigns.  For hotels pausing should happen at either the ad group or
          // campaign level.
          .setStatus(AdGroupAdStatus.ENABLED)
          // Sets the ad group.
          .setAdGroup(adGroupResourceName)
          .build();

  // Creates an ad group ad operation.
  AdGroupAdOperation operation = AdGroupAdOperation.newBuilder().setCreate(adGroupAd).build();

  // Issues a mutate request to add an ad group ad.
  try (AdGroupAdServiceClient adGroupAdServiceClient =
      googleAdsClient.getLatestVersion().createAdGroupAdServiceClient()) {
    MutateAdGroupAdResult mutateAdGroupAdResult =
        adGroupAdServiceClient
            .mutateAdGroupAds(Long.toString(customerId), Collections.singletonList(operation))
            .getResults(0);
    System.out.printf(
        "Added a hotel ad group ad with resource name: '%s'%n",
        mutateAdGroupAdResult.getResourceName());
    return mutateAdGroupAdResult.getResourceName();
  }
}
      
```

### C#

```c#
private static void AddHotelAdGroupAd(GoogleAdsClient client, long customerId,
    string adGroupResourceName)
{
    // Get the AdGroupAdService.
    AdGroupAdServiceClient service = client.GetService(Services.V26.AdGroupAdService);

    // Create a new ad group ad and sets the hotel ad to it.
    AdGroupAd adGroupAd = new AdGroupAd()
    {
        // Create a new hotel ad.
        Ad = new Ad()
        {
            HotelAd = new HotelAdInfo(),
        },
        // Set the ad group.
        AdGroup = adGroupResourceName,
        // Set the ad group ad to enabled.  Setting this to paused will cause an error
        // for hotel campaigns.  For hotels pausing should happen at either the ad group or
        // campaign level.
        Status = AdGroupAdStatus.Enabled
    };

    // Create an ad group ad operation.
    AdGroupAdOperation adGroupAdOperation = new AdGroupAdOperation()
    {
        Create = adGroupAd
    };

    // Issue a mutate request to add an ad group ad.
    MutateAdGroupAdsResponse response = service.MutateAdGroupAds(customerId.ToString(),
        new AdGroupAdOperation[] { adGroupAdOperation });

    MutateAdGroupAdResult addedAdGroupAd = response.Results[0];
    Console.WriteLine($"Added a hotel ad group ad with resource name " +
        $"{addedAdGroupAd.ResourceName}.");
}
      
```

### PHP

```php
    private static function addHotelAdGroupAd(
        GoogleAdsClient $googleAdsClient,
        int $customerId,
        string $adGroupResourceName
    ) {
        // Creates a new hotel ad.
        $ad = new Ad(
            [
            'hotel_ad' => new HotelAdInfo(),
            ]
        );

        // Creates a new ad group ad and sets the hotel ad to it.
        $adGroupAd = new AdGroupAd(
            [
            'ad' => $ad,
            // Set the ad group ad to enabled.  Setting this to paused will cause an error
            // for hotel campaigns.  For hotels pausing should happen at either the ad group or
            // campaign level.
            'status' => AdGroupAdStatus::ENABLED,
            // Sets the ad group.
            'ad_group' => $adGroupResourceName
            ]
        );

        // Creates an ad group ad operation.
        $adGroupAdOperation = new AdGroupAdOperation();
        $adGroupAdOperation->setCreate($adGroupAd);

        // Issues a mutate request to add an ad group ad.
        $adGroupAdServiceClient = $googleAdsClient->getAdGroupAdServiceClient();
        $response = $adGroupAdServiceClient->mutateAdGroupAds(
            MutateAdGroupAdsRequest::build($customerId, [$adGroupAdOperation])
        );

        /**
 * @var AdGroupAd $addedAdGroupAd
*/
        $addedAdGroupAd = $response->getResults()[0];
        printf(
            "Added a hotel ad group ad with resource name '%s'.%s",
            $addedAdGroupAd->getResourceName(),
            PHP_EOL
        );
    }
      
```

### Python

```python
def add_hotel_ad(
    client: GoogleAdsClient, customer_id: str, ad_group_resource_name: str
) -> str:
    ad_group_ad_service: AdGroupAdServiceClient = client.get_service(
        "AdGroupAdService"
    )

    # Creates a new ad group ad and sets the hotel ad to it.
    ad_group_ad_operation: AdGroupAdOperation = client.get_type(
        "AdGroupAdOperation"
    )
    ad_group_ad: AdGroupAd = ad_group_ad_operation.create
    ad_group_ad.ad_group = ad_group_resource_name
    # Set the ad group ad to enabled.  Setting this to paused will cause an error
    # for hotel campaigns.  For hotels pausing should happen at either the ad group or
    # campaign level.
    ad_group_ad.status = client.enums.AdGroupAdStatusEnum.ENABLED
    client.copy_from(ad_group_ad.ad.hotel_ad, client.get_type("HotelAdInfo"))

    # Add the ad group ad.
    ad_group_ad_response: MutateAdGroupAdsResponse = (
        ad_group_ad_service.mutate_ad_group_ads(
            customer_id=customer_id, operations=[ad_group_ad_operation]
        )
    )

    ad_group_ad_resource_name: str = ad_group_ad_response.results[
        0
    ].resource_name

    print(f"Created hotel ad with resource name '{ad_group_ad_resource_name}'.")

    return ad_group_resource_name
      
```

### Ruby

```ruby
def add_hotel_ad_group_ad(client, customer_id, ad_group_resource)
  # Create a new hotel ad.
  ad_group_ad_operation = client.operation.create_resource.ad_group_ad do |aga|
    # Create a new ad group ad and sets the hotel ad to it.
    aga.ad = client.resource.ad do |ad|
      ad.hotel_ad = client.resource.hotel_ad_info
    end
    # Set the ad group ad to enabled.  Setting this to paused will cause an error
    # for hotel campaigns.  For hotels pausing should happen at either the ad group or
    # campaign level.
    aga.status = :ENABLED

    # Set the ad group.
    aga.ad_group = ad_group_resource
  end

  # Issue a mutate request to add the ad group ad.
  ad_group_ad_service = client.service.ad_group_ad
  response = ad_group_ad_service.mutate_ad_group_ads(
    customer_id: customer_id,
    operations: [ad_group_ad_operation],
  )

  # Fetch the new ad group ad's resource name.
  ad_group_ad_resource = response.results.first.resource_name

  puts "Added hotel ad group ad with resource name '#{ad_group_ad_resource}'."
end
      
```

### Perl

```perl
sub add_hotel_ad_group_ad {
  my ($api_client, $customer_id, $ad_group_resource_name) = @_;

  # Create an ad group ad and set a hotel ad to it.
  my $ad_group_ad = Google::Ads::GoogleAds::V26::Resources::AdGroupAd->new({
      # Set the ad group.
      adGroup => $ad_group_resource_name,
      # Set the ad to a new shopping product ad.
      ad => Google::Ads::GoogleAds::V26::Resources::Ad->new({
          hotelAd => Google::Ads::GoogleAds::V26::Common::HotelAdInfo->new()}
      ),
      status => Google::Ads::GoogleAds::V26::Enums::AdGroupAdStatusEnum::ENABLED
    });

  # Create an ad group ad operation.
  my $ad_group_ad_operation =
    Google::Ads::GoogleAds::V26::Services::AdGroupAdService::AdGroupAdOperation
    ->new({create => $ad_group_ad});

  # Add the ad group ad.
  my $ad_group_ad_resource_name = $api_client->AdGroupAdService()->mutate({
      customerId => $customer_id,
      operations => [$ad_group_ad_operation]})->{results}[0]{resourceName};

  printf "Added a hotel ad group ad with resource name: '%s'.\n",
    $ad_group_ad_resource_name;

  return $ad_group_ad_resource_name;
}
      
```

### curl

> [!NOTE]
> **Note:** While a direct REST code sample for this step isn't provided here, you can achieve this using a manual REST request.   
>
> Refer to the Google Ads API REST interface documentation and the method-specific reference pages. You will need to construct the JSON payload based on the proto definitions.   
>
> Key Resources:
>
> - [Using REST](https://developers.google.com/google-ads/api/rest/overview.md.txt)
> - [REST Interface Structure](https://developers.google.com/google-ads/api/rest/design/overview.md.txt)
> - [JSON Field Mappings](https://developers.google.com/google-ads/api/rest/design/json-mappings.md.txt)
> - Consult the [REST API Reference](https://developers.google.com/google-ads/api/reference/rpc/latest/overview) for the specific service and method.

<br />

## What's next

- Learn how to manage [Hotel listing groups](https://developers.google.com/google-ads/api/docs/hotel-ads/create-listing-groups.md.txt).
- Review [Hotel bidding strategies](https://developers.google.com/google-ads/api/docs/hotel-ads/bidding/overview.md.txt).