Got 5 mins? Help us improve Apps Script documentation by taking a quick online study.

Class CardService

CardService

CardService provides the ability to create generic cards used across different Google extensibility products, such as Gmail add-ons.

return CardService.newCardBuilder()
         .setHeader(CardService.newCardHeader().setTitle("CardTitle"))
         .build();

Or you can return multiple Cards like so:

return [
  CardService.newCardBuilder().build(),
  CardService.newCardBuilder().build(),
  CardService.newCardBuilder().build()
]

The following shows how you could define a card with a header, text, an image and a menu item:

function createWidgetDemoCard() {
  return CardService
     .newCardBuilder()
     .setHeader(
         CardService.newCardHeader()
             .setTitle('Widget demonstration')
             .setSubtitle('Check out these widgets')
             .setImageStyle(CardService.ImageStyle.SQUARE)
             .setImageUrl(
                 'https://www.example.com/images/headerImage.png'))
     .addSection(
          CardService.newCardSection()
              .setHeader('Simple widgets')  // optional
              .addWidget(CardService.newTextParagraph().setText(
                  'These widgets are display-only. ' +
                  'A text paragraph can have multiple lines and ' +
                  'formatting.'))
              .addWidget(CardService.newImage().setImageUrl(
                  'https://www.example.com/images/mapsImage.png')))
     .addCardAction(CardService.newCardAction().setText('Gmail').setOpenLink(
         CardService.newOpenLink().setUrl('https://mail.google.com/mail')))
     .build();
}

Properties

PropertyTypeDescription
BorderTypeBorderTypeThe BorderType enumeration.
ComposedEmailTypeComposedEmailTypeThe ComposedEmailType enumeration.
ContentTypeContentTypeThe ContentType enumeration.
GridItemLayoutGridItemLayoutThe GridItemLayout enumeration.
HorizontalAlignmentHorizontalAlignmentThe HorizontalAlignment enumeration.
IconIconThe Icon enumeration.
ImageCropTypeImageCropTypeThe ImageCropType enumeration.
ImageStyleImageStyleThe ImageStyle enumeration.
LoadIndicatorLoadIndicatorThe LoadIndicator enumeration.
OnCloseOnCloseThe OnClose enumeration.
OpenAsOpenAsThe OpenAs enumeration.
SelectionInputTypeSelectionInputTypeThe SelectionInputType enumeration.
TextButtonStyleTextButtonStyleThe TextButtonStyle enumeration.
UpdateDraftBodyTypeUpdateDraftBodyTypeThe UpdateDraftBodyType enumeration.

Methods

MethodReturn typeBrief description
newAction()ActionCreates a new Action.
newActionResponseBuilder()ActionResponseBuilderCreates a new ActionResponseBuilder.
newAuthorizationAction()AuthorizationActionCreates a new AuthorizationAction.
newAuthorizationException()AuthorizationExceptionCreates a new AuthorizationException.
newBorderStyle()BorderStyleCreates a new BorderStyle.
newButtonSet()ButtonSetCreates a new ButtonSet.
newCalendarEventActionResponseBuilder()CalendarEventActionResponseBuilderCreates a new CalendarEventActionResponseBuilder.
newCardAction()CardActionCreates a new CardAction.
newCardBuilder()CardBuilderCreates a new CardBuilder.
newCardHeader()CardHeaderCreates a new CardHeader.
newCardSection()CardSectionCreates a new CardSection.
newComposeActionResponseBuilder()ComposeActionResponseBuilderCreates a new ComposeActionResponseBuilder.
newDatePicker()DatePickerCreates a new DatePicker.
newDateTimePicker()DateTimePickerCreates a new DateTimePicker.
newDecoratedText()DecoratedTextCreates a new DecoratedText.
newDivider()DividerCreates a new Divider.
newDriveItemsSelectedActionResponseBuilder()DriveItemsSelectedActionResponseBuilderCreates a new DriveItemsSelectedActionResponseBuilder.
newEditorFileScopeActionResponseBuilder()EditorFileScopeActionResponseBuilderCreates a new EditorFileScopeActionResponseBuilder.
newFixedFooter()FixedFooterCreates a new FixedFooter.
newGrid()GridCreates a new Grid.
newGridItem()GridItemCreates a new GridItem.
newIconImage()IconImageCreates a new IconImage.
newImage()ImageCreates a new Image.
newImageButton()ImageButtonCreates a new ImageButton.
newImageComponent()ImageComponentCreates a new ImageComponent.
newImageCropStyle()ImageCropStyleCreates a new ImageCropStyle.
newKeyValue()KeyValueCreates a new KeyValue.
newNavigation()NavigationCreates a new Navigation.
newNotification()NotificationCreates a new Notification.
newOpenLink()OpenLinkCreates a new OpenLink.
newSelectionInput()SelectionInputCreates a new SelectionInput.
newSuggestions()SuggestionsCreates a new Suggestions.
newSuggestionsResponseBuilder()SuggestionsResponseBuilderCreates a new SuggestionsResponseBuilder.
newSwitch()SwitchCreates a new Switch.
newTextButton()TextButtonCreates a new TextButton.
newTextInput()TextInputCreates a new TextInput.
newTextParagraph()TextParagraphCreates a new TextParagraph.
newTimePicker()TimePickerCreates a new TimePicker.
newUniversalActionResponseBuilder()UniversalActionResponseBuilderCreates a new UniversalActionResponseBuilder.
newUpdateDraftActionResponseBuilder()UpdateDraftActionResponseBuilderCreates a new UpdateDraftActionResponseBuilder.
newUpdateDraftBccRecipientsAction()UpdateDraftBccRecipientsActionCreates a new UpdateDraftBccRecipientsAction;
newUpdateDraftBodyAction()UpdateDraftBodyActionCreates a new UpdateDraftBodyAction.
newUpdateDraftCcRecipientsAction()UpdateDraftCcRecipientsActionCreates a new UpdateDraftCcRecipientsAction.
newUpdateDraftSubjectAction()UpdateDraftSubjectActionCreates a new UpdateDraftSubjectAction.
newUpdateDraftToRecipientsAction()UpdateDraftToRecipientsActionCreates a new UpdateDraftToRecipientsAction.

Detailed documentation

newAction()

Creates a new Action.

Return

Action — An empty Action.


newActionResponseBuilder()

Creates a new ActionResponseBuilder.

Return

ActionResponseBuilder — An empty ActionResponse builder.


newAuthorizationAction()

Creates a new AuthorizationAction.

Return

AuthorizationAction — An empty AuthorizationAction.


newAuthorizationException()

Creates a new AuthorizationException.

Return

AuthorizationException — An empty AuthorizationException.


newBorderStyle()

Creates a new BorderStyle.

Return

BorderStyle — An empty BorderStyle.


newButtonSet()

Creates a new ButtonSet.

Return

ButtonSet — An empty ButtonSet.


newCalendarEventActionResponseBuilder()


newCardAction()

Creates a new CardAction.

Return

CardAction — An empty CardAction.


newCardBuilder()

Creates a new CardBuilder.

Return

CardBuilder — An empty Card builder.


newCardHeader()

Creates a new CardHeader.

Return

CardHeader — An empty CardHeader.


newCardSection()

Creates a new CardSection.

Return

CardSection — An empty CardSection.


newComposeActionResponseBuilder()

Creates a new ComposeActionResponseBuilder.

Return

ComposeActionResponseBuilder — An empty ComposeActionResponse builder.


newDatePicker()

Creates a new DatePicker.

Return

DatePicker — An empty DatePicker.


newDateTimePicker()

Creates a new DateTimePicker.

Return

DateTimePicker — An empty DateTimePicker.


newDecoratedText()

Creates a new DecoratedText.

Return

DecoratedText — An empty DecoratedText.


newDivider()

Creates a new Divider. The following sample builds a simple card with 2 paragraphs separated by a divider.

function buildCard() {
  let cardSection1TextParagraph1 = CardService.newTextParagraph()
      .setText('Hello world!');

  let cardSection1Divider1 = CardService.newDivider();

  let cardSection1TextParagraph2 = CardService.newTextParagraph()
      .setText('Hello world!');

  let cardSection1 = CardService.newCardSection()
      .addWidget(cardSection1TextParagraph1)
      .addWidget(cardSection1Divider1)
      .addWidget(cardSection1TextParagraph2);

  let card = CardService.newCardBuilder()
      .addSection(cardSection1)
      .build();
  return card;
}

Return

Divider — A divider.


newDriveItemsSelectedActionResponseBuilder()


newEditorFileScopeActionResponseBuilder()


newFixedFooter()

Creates a new FixedFooter.

Return

FixedFooter — An empty FixedFooter.


newGrid()

Creates a new Grid.

Return

Grid — An empty Grid.


newGridItem()

Creates a new GridItem.

Return

GridItem — An empty GridItem.


newIconImage()

Creates a new IconImage.

Return

IconImage — An empty icon image.


newImage()

Creates a new Image.

Return

Image — An empty Image.


newImageButton()

Creates a new ImageButton.

Return

ImageButton — An empty ImageButton.


newImageComponent()

Creates a new ImageComponent.

Return

ImageComponent — An empty ImageComponent.


newImageCropStyle()

Creates a new ImageCropStyle.

Return

ImageCropStyle — An empty ImageCropStyle.


newKeyValue()

Creates a new KeyValue.

Return

KeyValue — An empty KeyValue.


newNavigation()

Creates a new Navigation.

Return

Navigation — An empty Navigation.


newNotification()

Creates a new Notification.

Return

Notification — An empty Notification.


Creates a new OpenLink.

Return

OpenLink — An empty OpenLink.


newSelectionInput()

Creates a new SelectionInput.

Return

SelectionInput — An empty SelectionInput.


newSuggestions()

Creates a new Suggestions.

Return

Suggestions — An empty Suggestions.


newSuggestionsResponseBuilder()

Creates a new SuggestionsResponseBuilder.

Return

SuggestionsResponseBuilder — An empty SuggestionsResponse builder.


newSwitch()

Creates a new Switch.

Return

Switch — An empty Switch.


newTextButton()

Creates a new TextButton.

Return

TextButton — An empty TextButton.


newTextInput()

Creates a new TextInput.

Return

TextInput — An empty TextInput.


newTextParagraph()

Creates a new TextParagraph.

Return

TextParagraph — An empty TextParagraph.


newTimePicker()

Creates a new TimePicker.

Return

TimePicker — An empty TimePicker.


newUniversalActionResponseBuilder()

Creates a new UniversalActionResponseBuilder.

Return

UniversalActionResponseBuilder — An empty UniversalActionResponse builder.


newUpdateDraftActionResponseBuilder()

Creates a new UpdateDraftActionResponseBuilder.

Return

UpdateDraftActionResponseBuilder — An empty UpdateDraftActionResponseBuilder.


newUpdateDraftBccRecipientsAction()

Creates a new UpdateDraftBccRecipientsAction;

Return

UpdateDraftBccRecipientsAction — An empty UpdateDraftBccRecipientsAction.


newUpdateDraftBodyAction()

Creates a new UpdateDraftBodyAction.

Return

UpdateDraftBodyAction — An empty UpdateDraftBodyAction.


newUpdateDraftCcRecipientsAction()

Creates a new UpdateDraftCcRecipientsAction.

Return

UpdateDraftCcRecipientsAction — An Empty UpdateDraftCcRecipientsAction.


newUpdateDraftSubjectAction()

Creates a new UpdateDraftSubjectAction.

Return

UpdateDraftSubjectAction — An empty UpdateDraftSubjectAction.


newUpdateDraftToRecipientsAction()

Creates a new UpdateDraftToRecipientsAction.

Return

UpdateDraftToRecipientsAction — An empty UpdateDraftToRecipientsAction.