CardHeader

The header of a `https://developers.google.com/apps-script/reference/card-service/card`.

Available for Google Workspace add-ons and Google Chat apps.

```javascript
const cardHeader = CardService.newCardHeader()
                       .setTitle('Card header title')
                       .setSubtitle('Card header subtitle')
                       .setImageStyle(CardService.ImageStyle.CIRCLE)
                       .setImageUrl('https://image.png');
```

### Methods

| Method | Return type | Brief description |
|---|---|---|
| `https://developers.google.com/apps-script/reference/card-service/card-header#setImageAltText(String)` | `https://developers.google.com/apps-script/reference/card-service/card-header#` | Sets the alternative text for the header image. |
| `https://developers.google.com/apps-script/reference/card-service/card-header#setImageStyle(ImageStyle)` | `https://developers.google.com/apps-script/reference/card-service/card-header#` | Sets the cropping of the icon in the card header. |
| `https://developers.google.com/apps-script/reference/card-service/card-header#setImageUrl(String)` | `https://developers.google.com/apps-script/reference/card-service/card-header#` | Sets the image to use in the header by providing its URL or data string. |
| `https://developers.google.com/apps-script/reference/card-service/card-header#setSubtitle(String)` | `https://developers.google.com/apps-script/reference/card-service/card-header#` | Sets the subtitle of the card header. |
| `https://developers.google.com/apps-script/reference/card-service/card-header#setTitle(String)` | `https://developers.google.com/apps-script/reference/card-service/card-header#` | Sets the title of the card header. |

## Detailed documentation

### `setImageAltText(imageAltText)`

Sets the alternative text for the header image.

#### Parameters

| Name | Type | Description |
|---|---|---|
| `imageAltText` | `String` | The alternative text for the header image. |

#### Return


`https://developers.google.com/apps-script/reference/card-service/card-header#` --- This object, for chaining.

*** ** * ** ***

### `setImageStyle(imageStyle)`

Sets the cropping of the icon in the card header. Defaults to no crop. Optional.

#### Parameters

| Name | Type | Description |
|---|---|---|
| `imageStyle` | `https://developers.google.com/apps-script/reference/card-service/image-style` | The style setting. |

#### Return


`https://developers.google.com/apps-script/reference/card-service/card-header#` --- This object, for chaining.

*** ** * ** ***

### `setImageUrl(imageUrl)`

Sets the image to use in the header by providing its URL or data string.

The provided URL can either be a publicly accessible URL or a base64 encoded image string.
To obtain the latter, you can use the following code to create an encoded image string from an
image in your Google Drive, then store that string for later use with `https://developers.google.com/apps-script/reference/card-service/card-header#setImageUrl(String)`. This method prevents the need for your add-on to access a publicly
available image URL:

```javascript
// The following assumes you have the image to use in Google Drive and have its
// ID.
const imageBytes = DriveApp.getFileById('123abc').getBlob().getBytes();
const encodedImageURL =
    `data:image/jpeg;base64,${Utilities.base64Encode(imageBytes)}`;

// You can store encodeImageURL and use it as a parameter to
// CardHeader.setImageUrl(imageUrl).
```

#### Parameters

| Name | Type | Description |
|---|---|---|
| `imageUrl` | `String` | The URL address of a hosted image to use, or an encoded image string. |

#### Return


`https://developers.google.com/apps-script/reference/card-service/card-header#` --- This object, for chaining.

*** ** * ** ***

### `setSubtitle(subtitle)`

Sets the subtitle of the card header. Optional.

#### Parameters

| Name | Type | Description |
|---|---|---|
| `subtitle` | `String` | The header subtitle text. |

#### Return


`https://developers.google.com/apps-script/reference/card-service/card-header#` --- This object, for chaining.

*** ** * ** ***

### `setTitle(title)`

Sets the title of the card header. Required.

#### Parameters

| Name | Type | Description |
|---|---|---|
| `title` | `String` | The header text. |

#### Return


`https://developers.google.com/apps-script/reference/card-service/card-header#` --- This object, for chaining.