---
url: /process-functions/card-execute.md
description: >-
  Returns an executed card with specified context & variables in a specified
  format.
---

# card.execute

Returns an executed card with specified context & variables in a specified format.

```js
card.execute(cardID, contextValues, variables, format)
```

## Parameters

| Parameter | Type | Description |
|---|---|---|
| `cardID` | `string` | The card's id or name. |
| `contextValues` | `object` | The element to use for each dimension in the card's context. Each key is a dimension's id and each value is an element name. |
| `variables` | `object` | Values for the card's variables, keyed by variable name. These override the card's own values; any you leave out keep theirs. `width` and `height` set the output size. |
| `format` | `string` | The output format; see the table below. Defaults to `"live"`. |

## Returns

The executed card in the requested format, or `null` if the card produced no output.

| Format | Returns |
|---|---|
| `"pdf"` | The PDF, base64-encoded. |
| `"png"` | The image, base64-encoded. |
| `"xlsx"` | The Excel workbook as a data URI (`data:...;base64,...`). Strip everything up to the comma to get the base64 content. |
| `"csv_v2"` | The card's data as CSV text. |
| `"live"` | The card's data as a JSON string. |
| `"svg"` | The image, base64-encoded. |

## Examples

```js
const dimValues = {
    "c4ca4238a0b923820dcc509a6f75849b": "Closing Balance",
    "c81e728d9d4c2f636f067f89cc14862c": "Amount",
    "eccbc87e4b5ce2fe28308fd9f2a7baf3": "2021",
    "a87ff679a2f3e71d9181a67b7542122c": "Amount",
    "e4da3b7fbbce2345d7772b0674a318d5": "2002",
    "1679091c5a880faf6fb5e6087eb1b2dc": "AUD",
    "8f14e45fceea167a5a36dedd4bea2543": "Total Labour",
    "c9f0f895fb98ab9159f51fd0297e236d": "no count",
    "45c48cce2e2d7fbdea1afc51c7c6ad26": "Aug",
    "d3d9446802a44259755d38e6d163e820": "Actual",
    "6512bd43d9caa6e02c990b0a82652dca": "All Departments",
    "c20ad4d76fe97759aa27a0c99bff6710": "Net Profit/(Loss) after Income Tax"
};

const pdf = card.execute("7815696ecbf1c96e6894b779456d330e", dimValues, { "width": 1200, "height": 800 }, "pdf");

new EmailBuilder()
    .from("noreply@acme.com")
    .to("finance@acme.com")
    .subject("Financial Report")
    .body("See attached.")
    .attachBase64("FinancialReport.pdf", pdf)
    .send();
```

## Related

* [EmailBuilder](/process-functions/emailbuilder): sends an email, with the card attached.
