import uuid


def _CreateAdGroup(client, campaign_id):
  """Creates an ad group.

  Args:
    client: an AdWordsClient instance.
    campaign_id: an integer campaign ID.

  Returns:
    An integer ad group ID.
  """
  ad_group_service = client.GetService('AdGroupService')

  operations = [{
      'operator': 'ADD',
      'operand': {
          'campaignId': campaign_id,
          'adGroupType': 'SEARCH_DYNAMIC_ADS',
          'name': 'Earth to Mars Cruises #%d' % uuid.uuid4(),
          'status': 'PAUSED',
          'biddingStrategyConfiguration': {
              'bids': [{
                  'xsi_type': 'CpcBid',
                  'bid': {
                      'microAmount': '3000000'
                  },
              }]
          }
      }
  }]

  ad_group = ad_group_service.mutate(operations)['value'][0]
  ad_group_id = ad_group['id']

  print('Ad group with ID "%d" and name "%s" was created.' % (
      ad_group_id, ad_group['name']))

  return ad_group_id