Class CardWithId

  • CardWithId is a builder for objects that provide a unique identifier for a card when sending multiple cards.

  • CardWithId is only available for Google Chat apps.

  • The setCard(card) method sets the card of the cardWithId.

  • The setCardId(id) method sets the unique card ID of the cardWithId.

A builder for CardWithId objects. This class is a unique identifier for a card in a message when sending multiple cards.

Only available for Google Chat apps. Not available for Google Workspace add-ons.

const cardSection = CardService.newCardSection();
cardSection.addWidget(
    CardService.newTextParagraph().setText('This is a text paragraph widget.'),
);

const card = CardService.newCardBuilder()
                 .setHeader(CardService.newCardHeader().setTitle('Card title'))
                 .addSection(cardSection)
                 .build();

const cardWithId =
    CardService.newCardWithId().setCardId('card_id').setCard(card);

Methods

MethodReturn typeBrief description
setCard(card)CardWithIdSets the card of the cardWithId.
setCardId(id)CardWithIdSets the unique card ID of the cardWithId.

Detailed documentation

setCard(card)

Sets the card of the cardWithId.

const cardHeader = CardService.newCardHeader()
                       .setTitle('Card Header Title')
                       .setSubtitle('Card Header Subtitle');

const card = CardService.newCardBuilder().setHeader(cardHeader).build();

const cardWithId = CardService.newCardWithId().setCard(card);

Parameters

NameTypeDescription
cardCardThe Card to use.

Return

CardWithId — This object, for chaining.


setCardId(id)

Sets the unique card ID of the cardWithId.

const cardWithId = CardService.newCardWithId();

// Sets the card ID of the cardWithId.
cardWithId.setCardId('card_id');

Parameters

NameTypeDescription
idStringThe text to use.

Return

CardWithId — This object, for chaining.

Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2025-12-03 UTC.