def _GetFieldPathElementIndex(api_error, field):
  """Retrieve the index of a given field in the api_error's fieldPathElements.

  Args:
    api_error: a dict containing a partialFailureError returned from the AdWords
      API.
    field: a str field for which this determines the index in the api_error's
      fieldPathElements.

  Returns:
    An int index of the field path element, or None if the specified field can't
    be found in the api_error.
  """
  field_path_elements = api_error['fieldPathElements']

  if field_path_elements:
    found_index = [field_path_element['index']
                   for field_path_element in field_path_elements
                   if field_path_element['field'] == field]
    if found_index:
      return found_index

  return None