> ## Documentation Index
> Fetch the complete documentation index at: https://www.courier.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

> ## Agent Instructions
> Install the Courier skill before writing code: `npx skills add trycourier/courier-skills`. It carries the verified SDK shapes and the rules you cannot get wrong.
> Authenticate every request with `Authorization: Bearer <API_KEY>`. A workspace has several environments and each has its own keys, which are plain `pk_` strings with no environment prefix. Start with Test.
> Send with `client.send.message`, the default import of the v7 Node SDK. Reference a template by its `nt_` id or its alias.
> A send accepts a bare Elemental element list, but storing content on a template requires the top-level elements wrapped in a channel element.
> Templates and journeys can be built in the Courier app or created through the API. Either way they live in the workspace and are referenced by ID when you send.
> The hosted MCP server is https://mcp.courier.com. For a briefing on what Courier is and when to use it, read https://www.courier.com/llms.txt.
> Prefer the Guides tab for how-do-I questions and the Docs tab for how-does-it-behave questions. The API reference lives under /api-reference.

# Elemental group element

> Wrap several elements so one if or loop condition applies to all of them.

export const Doc = ({href, children, name, bare}) => {
  const label = children || name || href;
  if (bare) {
    return <a href={href}>{label}</a>;
  }
  return <a className="cx-endpoint" data-kind="doc" href={href}>
      <span className="cx-endpoint-label">{label}</span>
      <span className="cx-endpoint-method">DOC</span>
    </a>;
};

The group element wraps multiple elements into one unit. Combine it with `if` or `loop` to render or repeat the whole set at once. The type value is `"group"`.

**When to use:**

* Apply conditional logic to multiple elements at once
* Loop over multiple elements together
* Organize related elements into logical sections
* Create reusable element blocks

**Basic example**

<CodeGroup>
  ```json Elemental theme={null}
  {
    "type": "group",
    "elements": [
      {
        "type": "text",
        "content": "Welcome!"
      },
      {
        "type": "action",
        "content": "Get Started",
        "href": "https://example.com/start"
      }
    ]
  }
  ```

  ```javascript Node.js highlight={9-22} theme={null}
  const { requestId } = await client.send.message({
    message: {
      to: {
        email: "sarah@acme-corp.com",
      },
      content: {
        version: "2022-01-01",
        elements: [
          {
            type: "group",
            elements: [
              {
                type: "text",
                content: "Welcome!",
              },
              {
                type: "action",
                content: "Get Started",
                href: "https://example.com/start",
              },
            ],
          },
        ],
      },
    },
  });
  ```

  ```python Python highlight={9-22} theme={null}
  response = client.send.message(
      message={
        "to": {
          "email": "sarah@acme-corp.com",
        },
        "content": {
          "version": "2022-01-01",
          "elements": [
            {
              "type": "group",
              "elements": [
                {
                  "type": "text",
                  "content": "Welcome!",
                },
                {
                  "type": "action",
                  "content": "Get Started",
                  "href": "https://example.com/start",
                },
              ],
            },
          ],
        },
      },
  )
  ```

  ```bash cURL highlight={12-25} theme={null}
  curl -X POST https://api.courier.com/send \
    -H "Authorization: Bearer $COURIER_API_KEY" \
    -H "Content-Type: application/json" \
    -d '{
        "message": {
          "to": {
            "email": "sarah@acme-corp.com"
          },
          "content": {
            "version": "2022-01-01",
            "elements": [
              {
                "type": "group",
                "elements": [
                  {
                    "type": "text",
                    "content": "Welcome!"
                  },
                  {
                    "type": "action",
                    "content": "Get Started",
                    "href": "https://example.com/start"
                  }
                ]
              }
            ]
          }
        }
      }'
  ```

  ```ruby Ruby highlight={9-22} theme={null}
  response = courier.send_.message(
    message: {
      to: {
        email: "sarah@acme-corp.com"
      },
      content: {
        version: "2022-01-01",
        elements: [
          {
            type: "group",
            elements: [
              {
                type: "text",
                content: "Welcome!"
              },
              {
                type: "action",
                content: "Get Started",
                href: "https://example.com/start"
              }
            ]
          }
        ]
      }
    }
  )
  ```

  ```go Go highlight={5-18} theme={null}
  // Elemental nodes carry no typed content fields, so pass the document as raw JSON.
  content := param.Override[shared.ElementalContentParam](json.RawMessage(`{
    "version": "2022-01-01",
    "elements": [
      {
        "type": "group",
        "elements": [
          {
            "type": "text",
            "content": "Welcome!"
          },
          {
            "type": "action",
            "content": "Get Started",
            "href": "https://example.com/start"
          }
        ]
      }
    ]
  }`))

  response, err := client.Send.Message(context.TODO(), courier.SendMessageParams{
  	Message: courier.SendMessageParamsMessage{
  		To: courier.SendMessageParamsMessageToUnion{
  			OfUserRecipient: &shared.UserRecipientParam{
  				Email: courier.String("sarah@acme-corp.com"),
  			},
  		},
  		Content: courier.SendMessageParamsMessageContentUnion{OfElementalContent: &content},
  	},
  })
  ```

  ```java Java highlight={7-16} theme={null}
  SendMessageParams params = SendMessageParams.builder()
      .message(SendMessageParams.Message.builder()
          .to(JsonValue.from(java.util.Map.of("email", "sarah@acme-corp.com")))
          .content(JsonValue.from(java.util.Map.of(
                  "version", "2022-01-01",
                  "elements", java.util.List.of(
                    java.util.Map.of(
                      "type", "group",
                      "elements", java.util.List.of(
                        java.util.Map.of(
                          "type", "text",
                          "content", "Welcome!"),
                        java.util.Map.of(
                          "type", "action",
                          "content", "Get Started",
                          "href", "https://example.com/start")))))))
          .build())
      .build();
  SendMessageResponse response = client.send().message(params);
  ```

  ```php PHP highlight={9-22} theme={null}
  $response = $client->send->message(
    message: [
      'to' => [
        'email' => 'sarah@acme-corp.com',
      ],
      'content' => [
        'version' => '2022-01-01',
        'elements' => [
          [
            'type' => 'group',
            'elements' => [
              [
                'type' => 'text',
                'content' => 'Welcome!',
              ],
              [
                'type' => 'action',
                'content' => 'Get Started',
                'href' => 'https://example.com/start',
              ],
            ],
          ],
        ],
      ],
    ],
  );
  ```

  ```csharp C# highlight={12-25} theme={null}
  // Elemental nodes expose no typed content fields, so build the document from raw JSON.
  SendMessageParams parameters = new()
  {
      Message = new()
      {
          To = new UserRecipient { Email = "sarah@acme-corp.com" },
          Content = ElementalContent.FromRawUnchecked(
              JsonSerializer.Deserialize<Dictionary<string, JsonElement>>("""
              {
                "version": "2022-01-01",
                "elements": [
                  {
                    "type": "group",
                    "elements": [
                      {
                        "type": "text",
                        "content": "Welcome!"
                      },
                      {
                        "type": "action",
                        "content": "Get Started",
                        "href": "https://example.com/start"
                      }
                    ]
                  }
                ]
              }
              """)),
      },
  };

  var response = await client.Send.Message(parameters);
  ```

  ```bash CLI highlight={4} theme={null}
  courier send message \
    --api-key "$COURIER_API_KEY" \
    --message.to '{"email": "sarah@acme-corp.com"}' \
    --message.content '{"version": "2022-01-01", "elements": [{"type": "group", "elements": [{"type": "text", "content": "Welcome!"}, {"type": "action", "content": "Get Started", "href": "https://example.com/start"}]}]}'
  ```

  ```text MCP theme={null}
  With Courier MCP, send an email to sarah@acme-corp.com with a grouped heading and button block.
  ```
</CodeGroup>

**Fields**

<ParamField path="elements" type="CourierElement[]" required>
  An array of Elemental elements. They render together as one unit.
</ParamField>

<ParamField path="if" type="string | object[]">
  A condition that determines whether the whole group renders. Accepts a string expression or a structured condition array. See <Doc href="/docs/design/elemental/control-flow#if">Control flow</Doc>.
</ParamField>

<ParamField path="loop" type="string">
  An expression that repeats the whole group. See <Doc href="/docs/design/elemental/control-flow#loop">Control flow</Doc>.
</ParamField>

<ParamField path="ref" type="string">
  A reference identifier for the group. See <Doc href="/docs/design/elemental/control-flow#ref">Control flow</Doc>.
</ParamField>

<ParamField path="channels" type="string[]">
  An array of channel names. The group renders only for the listed channels. See <Doc href="/docs/design/elemental/control-flow#channels">Control flow</Doc>.
</ParamField>

**Examples and variants**

**Conditional group**

Show or hide multiple elements based on a condition:

```json theme={null}
{
  "type": "group",
  "if": "{{user.plan}} === 'premium'",
  "elements": [
    {
      "type": "text",
      "content": "**Premium Features**",
      "text_style": "h2"
    },
    {
      "type": "text",
      "content": "You have access to all premium features!"
    },
    {
      "type": "action",
      "content": "Explore Features",
      "href": "https://example.com/premium"
    }
  ]
}
```

**Looping group**

Repeat a group of elements for each item in an array:

```json theme={null}
{
  "type": "group",
  "loop": "data.products",
  "elements": [
    {
      "type": "text",
      "content": "# {{$.item.name}}",
      "text_style": "h2"
    },
    {
      "type": "divider"
    },
    {
      "type": "text",
      "content": "Description: {{$.item.description}}"
    },
    {
      "type": "text",
      "content": "Price: ${{$.item.price}}",
      "bold": true
    },
    {
      "type": "action",
      "content": "View Product",
      "href": "https://example.com/products/{{$.item.id}}"
    }
  ]
}
```

**Nested groups**

Group elements within groups for complex structures:

```json theme={null}
{
  "type": "group",
  "if": "{{order.items.length}} > 0",
  "elements": [
    {
      "type": "text",
      "content": "Order Items",
      "text_style": "h2"
    },
    {
      "type": "group",
      "loop": "data.order.items",
      "elements": [
        {
          "type": "text",
          "content": "{{$.item.name}} - ${{$.item.price}}"
        }
      ]
    },
    {
      "type": "text",
      "content": "Total: ${{order.total}}",
      "bold": true
    }
  ]
}
```
