Card Service Service

Card Service

This service allows scripts to configure and build card and widget components and behaviors for a UI. The UI structures you build with this service are automatically available in both desktop and mobile devices, so you don't need to develop separate UIs for both.

Classes

NameBrief description
ActionAn action that enables interactivity within UI elements.
ActionResponseThe response object that may be returned from a callback function (e.g., a form response handler) to perform one or more actions on the client.
ActionResponseBuilderA builder for ActionResponse objects.
AuthorizationActionAn authorization action that will send the user to the AuthorizationUrl when clicked.
AuthorizationExceptionAn error that can be returned to trigger an authorization card to be shown to the user.
ButtonA base class for all buttons.
ButtonSetHolds a set of Button objects that are displayed in a row.
CardA context card that represents a single view in the UI.
CardActionA clickable menu item that is added to the card header menu.
CardBuilderA builder for Card objects.
CardHeaderThe header of a Card.
CardSectionA card section holds groups of widgets and provides visual separation between them.
CardServiceCardService provides the ability to create generic cards used across different Google extensibility products, such as Gmail add-ons.
ComposeActionResponseThe response object that may be returned from a callback method for compose action in a Gmail add-on.
ComposeActionResponseBuilderA builder for ComposeActionResponse objects.
ComposedEmailTypeAn enum value that specifies whether the composed email is a standalone or reply draft.
IconPredefined icons that can be used in various UI objects, such as ImageButton or KeyValue widgets.
ImageA widget that shows a single image.
ImageButtonA ImageButton with an image displayed on it.
ImageStyleAn enum that defines an image cropping style.
KeyValueA widget that displays one or more "keys" around a text "value".
LoadIndicatorAn enum type that specifies the type of loading or progress indicator to display while an Action is being processed.
NavigationA helper object that controls card navigation.
NotificationA notification shown to the user as a response to interacting with a UI element.
NotificationTypeType of notification to show.
OnCloseAn enum that specifies what to do when a URL opened through an OpenLink is closed.
OpenAsAn enum that specifies how to open a URL.
OpenLinkRepresents an action to open a link with some options.
SelectionInputAn input field that allows choosing between a set of predefined options.
SelectionInputTypeType of selection input.
SuggestionsAutocomplete suggestions to supplement a TextInput widget.
SuggestionsResponseA response object that can be returned from a suggestions callback function.
SuggestionsResponseBuilderA builder for SuggestionsResponse objects.
SwitchA UI element that supports being toggled on or off.
TextButtonA TextButton with a text label.
TextInputA input field widget that accepts text input.
TextParagraphA widget that displays text and supports basic HTML formatting.
UniversalActionResponseThe response object that may be returned from a method that creates universal action.
UniversalActionResponseBuilderA builder for the UniversalActionResponse objects.
WidgetBase class for all widgets that can be added to a Card.

Action

Methods

MethodReturn typeBrief description
setFunctionName(functionName)ActionSets the name of the callback function to be called.
setLoadIndicator(loadIndicator)ActionSets the loading indicator that displays while the action is in progress.
setParameters(parameters)ActionAllows custom parameters to be passed to the callback function.

ActionResponse

Methods

MethodReturn typeBrief description
printJson()StringPrints the JSON representation of this object.

ActionResponseBuilder

Methods

MethodReturn typeBrief description
build()ActionResponseBuilds the current action response and validates it.
setNavigation(navigation)ActionResponseBuilderSets the response to a Navigation action.
setNotification(notification)ActionResponseBuilderSets the notification to display when the action is activated.
setOpenLink(openLink)ActionResponseBuilderSets the URL to navigate to when the action is activated.

AuthorizationAction

Methods

MethodReturn typeBrief description
setAuthorizationUrl(authorizationUrl)AuthorizationActionSets the authorization URL that user is taken to from the authorization prompt.

AuthorizationException

Methods

MethodReturn typeBrief description
printJson()StringPrints the JSON representation of this object.
setAuthorizationUrl(authUrl)AuthorizationExceptionSets the authorization URL that user is taken to from the authorization prompt.
setCustomUiCallback(callback)AuthorizationExceptionThe name of a function to call to generate a custom authorization prompt.
setResourceDisplayName(name)AuthorizationExceptionSets the name that is displayed to the user when asking for authorization.
throwException()voidTriggers this exception to be thrown.

Button

Methods

MethodReturn typeBrief description
setAuthorizationAction(action)ButtonSets an authorization action that opens a URL to the authorization flow when the object is clicked.
setComposeAction(action, composedEmailType)ButtonSets an action that composes a draft email when the object is clicked.
setOnClickAction(action)ButtonSets an action that executes when the object is clicked.
setOnClickOpenLinkAction(action)ButtonSets an action that opens a URL in a tab when the object is clicked.
setOpenLink(openLink)ButtonSets a URL to be opened when the object is clicked.

ButtonSet

Methods

MethodReturn typeBrief description
addButton(button)ButtonSetAdds a button.

Card

Methods

MethodReturn typeBrief description
printJson()StringPrints the JSON representation of this object.

CardAction

Methods

MethodReturn typeBrief description
setAuthorizationAction(action)CardActionSets an authorization action that opens a URL to the authorization flow when the object is clicked.
setComposeAction(action, composedEmailType)CardActionSets an action that composes a draft email when the object is clicked.
setOnClickAction(action)CardActionSets an action that executes when the object is clicked.
setOnClickOpenLinkAction(action)CardActionSets an action that opens a URL in a tab when the object is clicked.
setOpenLink(openLink)CardActionSets a URL to be opened when the object is clicked.
setText(text)CardActionSets the menu text for this action.

CardBuilder

Methods

MethodReturn typeBrief description
addCardAction(cardAction)CardBuilderAdds a CardAction to this Card.
addSection(section)CardBuilderAdds a section to this card.
build()CardBuilds the current card and validates it.
setHeader(cardHeader)CardBuilderSets the header for this card.
setName(name)CardBuilderSets the name for this card.

CardHeader

Methods

MethodReturn typeBrief description
setImageAltText(imageAltText)CardHeaderSets the alternative text for the header image.
setImageStyle(imageStyle)CardHeaderSets the cropping of the icon in then card header.
setImageUrl(imageUrl)CardHeaderSets the image to use in the header by providing its URL.
setSubtitle(subtitle)CardHeaderSets the subtitle of the card header.
setTitle(title)CardHeaderSets the title of the card header.

CardSection

Methods

MethodReturn typeBrief description
addWidget(widget)CardSectionAdds the given widget to this section.
setCollapsible(collapsible)CardSectionSets whether the section can be collapsed.
setHeader(header)CardSectionSets the header of the section.
setNumUncollapsibleWidgets(numUncollapsibleWidgets)CardSectionSets the number of widgets that are still shown when this section is collapsed.

CardService

Properties

PropertyTypeDescription
ComposedEmailTypeComposedEmailTypeThe ComposedEmailType enumeration.
IconIconThe Icon enumeration.
ImageStyleImageStyleThe ImageStyle enumeration.
LoadIndicatorLoadIndicatorThe LoadIndicator enumeration.
NotificationTypeNotificationTypeThe NotificationType enumeration.
OnCloseOnCloseThe OnClose enumeration.
OpenAsOpenAsThe OpenAs enumeration.
SelectionInputTypeSelectionInputTypeThe SelectionInputType 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.
newButtonSet()ButtonSetCreates a new ButtonSet.
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.
newImage()ImageCreates a new Image.
newImageButton()ImageButtonCreates a new ImageButton.
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.
newUniversalActionResponseBuilder()UniversalActionResponseBuilderCreates a new UniversalActionResponseBuilder.

ComposeActionResponse

Methods

MethodReturn typeBrief description
printJson()StringPrints the JSON representation of this object.

ComposeActionResponseBuilder

Methods

MethodReturn typeBrief description
build()ComposeActionResponseBuilds the current compose action response and validates it.
setGmailDraft(draft)ComposeActionResponseBuilderSets the draft GmailMessage created using GmailMessage.createDraftReply(body) or similar functions.

ComposedEmailType

Properties

PropertyTypeDescription
REPLY_AS_DRAFTEnumA draft that is a reply to another message.
STANDALONE_DRAFTEnumA draft that is a standalone message.

Icon

Properties

PropertyTypeDescription
NONEEnumNo icon.
AIRPLANEEnumAirplane flight icon
BOOKMARKEnumBookmark icon
BUSEnumBus icon
CAREnumCar icon
CLOCKEnumClock icon
CONFIRMATION_NUMBER_ICONEnumConfirmation number icon
DOLLAREnumDollar icon
DESCRIPTIONEnumDescription icon
EMAILEnumEmail icon
EVENT_PERFORMEREnumEmail icon
EVENT_SEATEnumEvent seat icon
FLIGHT_ARRIVALEnumFlight arrival icon
FLIGHT_DEPARTUREEnumFlight departure icon
HOTELEnumHotel icon
HOTEL_ROOM_TYPEEnumHotel icon
INVITEEnumInvite icon
MAP_PINEnumMap pin icon
MEMBERSHIPEnumMembershipt icon
MULTIPLE_PEOPLEEnumMultiple people icon
OFFEREnumOffer icon
PERSONEnumPerson icon
PHONEEnumPhone icon
RESTAURANT_ICONEnumRestaurant icon
SHOPPING_CARTEnumShopping cart icon
STAREnumStar icon
STOREEnumStore icon
TICKETEnumTicket icon
TRAINEnumTrain icon
VIDEO_CAMERAEnumVideo camera icon
VIDEO_PLAYEnumVideo play icon

Image

Methods

MethodReturn typeBrief description
setAltText(altText)ImageSets the alternative text of the image for accessibility.
setAuthorizationAction(action)ImageSets an authorization action that opens a URL to the authorization flow when the object is clicked.
setComposeAction(action, composedEmailType)ImageSets an action that composes a draft email when the object is clicked.
setImageUrl(url)ImageSets the URL of the image.
setOnClickAction(action)ImageSets an action that executes when the object is clicked.
setOnClickOpenLinkAction(action)ImageSets an action that opens a URL in a tab when the object is clicked.
setOpenLink(openLink)ImageSets a URL to be opened when the object is clicked.

ImageButton

Methods

MethodReturn typeBrief description
setAltText(altText)ImageButtonSets the alternative text of the button for accessibility.
setAuthorizationAction(action)ImageButtonSets an authorization action that opens a URL to the authorization flow when the object is clicked.
setComposeAction(action, composedEmailType)ImageButtonSets an action that composes a draft email when the object is clicked.
setIcon(icon)ImageButtonSets a predefined Icon to display on the button.
setIconUrl(url)ImageButtonSets the URL of an image to use as this button's icon.
setOnClickAction(action)ImageButtonSets an action that executes when the object is clicked.
setOnClickOpenLinkAction(action)ImageButtonSets an action that opens a URL in a tab when the object is clicked.
setOpenLink(openLink)ImageButtonSets a URL to be opened when the object is clicked.

ImageStyle

Properties

PropertyTypeDescription
SQUAREEnumNo cropping.
CIRCLEEnumCrop to a circle shape.

KeyValue

Methods

MethodReturn typeBrief description
setAuthorizationAction(action)KeyValueSets an authorization action that opens a URL to the authorization flow when the object is clicked.
setBottomLabel(text)KeyValueSets the label text to be used as the key.
setButton(button)KeyValueSets the Button that is displayed to the right of the context.
setComposeAction(action, composedEmailType)KeyValueSets an action that composes a draft email when the object is clicked.
setContent(text)KeyValueSets the text to be used as the value.
setIcon(icon)KeyValueSets the icon to be used as the key.
setIconAltText(altText)KeyValueSets the alternative text for the icon.
setIconUrl(url)KeyValueSets the URL of the icon to be used as the key.
setMultiline(multiline)KeyValueSets whether the value text should be displayed on a single line or multiple lines.
setOnClickAction(action)KeyValueSets an action that executes when the object is clicked.
setOnClickOpenLinkAction(action)KeyValueSets an action that opens a URL in a tab when the object is clicked.
setOpenLink(openLink)KeyValueSets a URL to be opened when the object is clicked.
setSwitch(switchToSet)KeyValueSets the Switch that is displayed to the right of the content.
setTopLabel(text)KeyValueSets the label text to be used as the key.

LoadIndicator

Properties

PropertyTypeDescription
SPINNEREnumUse a spinner indicator.
NONEEnumDo not use an indicator.

Navigation

Methods

MethodReturn typeBrief description
popCard()NavigationPops a card from the navigation stack.
popToNamedCard(cardName)NavigationPops to the specified card by its card name.
popToRoot()NavigationPops the card stack to the root card.
printJson()StringPrints the JSON representation of this object.
pushCard(card)NavigationPushes the given card onto the stack.
updateCard(card)NavigationDoes an in-place replacement of the current card.

Notification

Methods

MethodReturn typeBrief description
setText(text)NotificationSets the text to show in the notification.
setType(type)NotificationSets the notification type to show.

NotificationType

Properties

PropertyTypeDescription
INFOEnumAn info-level notification.
ERROREnumAn error-level notification.
WARNINGEnumA warning-level notification.

OnClose

Properties

PropertyTypeDescription
NOTHINGEnumDo nothing on close.
RELOAD_ADD_ONEnumReload the add-on on closing the URL.

OpenAs

Properties

PropertyTypeDescription
FULL_SIZEEnumOpen in a full window or tab.
OVERLAYEnumOpen as an overlay such as a pop-up.

OpenLink

Methods

MethodReturn typeBrief description
setOnClose(onClose)OpenLinkSets the behavior of the URL action when the URL window or tab is closed.
setOpenAs(openAs)OpenLinkSets the behavior of URL when it is opened.
setUrl(url)OpenLinkSets the URL to be opened.

SelectionInput

Methods

MethodReturn typeBrief description
addItem(text, value, selected)SelectionInputAdds a new item that can be selected.
setFieldName(fieldName)SelectionInputSets the key that identifies this selection input in the event object that is generated when there is a UI interaction.
setOnChangeAction(action)SelectionInputSets an Action to be performed whenever the selection input changes.
setTitle(title)SelectionInputSets the title to be shown ahead of the input field.
setType(type)SelectionInputSets the type of this input.

SelectionInputType

Properties

PropertyTypeDescription
CHECK_BOXEnumCheckbox input style.
RADIO_BUTTONEnumRadio buton input style.
DROPDOWNEnumDropdown menu selection input style.

Suggestions

Methods

MethodReturn typeBrief description
addSuggestion(suggestion)SuggestionsAdd a text suggestion.
addSuggestions(suggestions)SuggestionsAdd a list of text suggestions.

SuggestionsResponse

Methods

MethodReturn typeBrief description
printJson()StringPrints the JSON representation of this object.

SuggestionsResponseBuilder

Methods

MethodReturn typeBrief description
build()SuggestionsResponseBuilds the current suggestions response and validates it.
setSuggestions(suggestions)SuggestionsResponseBuilderSets the suggestions used in auto complete in text fields.

Switch

Methods

MethodReturn typeBrief description
setFieldName(fieldName)SwitchSets the key that identifies this switch in the event object that is generated when there is a UI interaction.
setOnChangeAction(action)SwitchSets the action to take when the switch is toggled.
setSelected(selected)SwitchSets whether this switch should start as selected or unselected.
setValue(value)SwitchSets the value that is sent as the form input when this switch is toggled on.

TextButton

Methods

MethodReturn typeBrief description
setAuthorizationAction(action)TextButtonSets an authorization action that opens a URL to the authorization flow when the object is clicked.
setComposeAction(action, composedEmailType)TextButtonSets an action that composes a draft email when the object is clicked.
setOnClickAction(action)TextButtonSets an action that executes when the object is clicked.
setOnClickOpenLinkAction(action)TextButtonSets an action that opens a URL in a tab when the object is clicked.
setOpenLink(openLink)TextButtonSets a URL to be opened when the object is clicked.
setText(text)TextButtonSets the text to be displayed on the button.

TextInput

Methods

MethodReturn typeBrief description
setFieldName(fieldName)TextInputSets the key that identifies this text input in the event object that is generated when there is a UI interaction.
setHint(hint)TextInputSets a hint for the text input.
setMultiline(multiline)TextInputSets whether the input text shows on one line or multiple lines.
setOnChangeAction(action)TextInputSets an action to be performed whenever the text input changes.
setSuggestions(suggestions)TextInputSets the suggestions for autocompletion in the text field.
setSuggestionsAction(suggestionsAction)TextInputSets the callback action to fetch suggestions based on user input for autocompletion.
setTitle(title)TextInputSets the title to be shown above the input field.
setValue(value)TextInputSets the pre-filled value to be set in the input field.

TextParagraph

Methods

MethodReturn typeBrief description
setText(text)TextParagraphSets the text of the paragraph.

UniversalActionResponse

Methods

MethodReturn typeBrief description
printJson()StringPrints the JSON representation of this object.

UniversalActionResponseBuilder

Methods

MethodReturn typeBrief description
build()UniversalActionResponseBuilds the current universal action response and validates it.
displayAddOnCards(cardObjects)UniversalActionResponseBuilderDisplays the add-on with the specified cards.
setOpenLink(openLink)UniversalActionResponseBuilderSets the URL to open when the universal action is selected.

Widget

Send feedback about...

Apps Script
Apps Script