Generate API payloads using buildToJSON()
mainTo generate the complete JSON payload required for specific Slack API methods, call .buildToJSON() on your Surface object. The output format depends on the type of surface used:
| Surface Type | Method | Target Slack API Parameter/Method |
|---|---|---|
Message | .buildToJSON() | Full payload for chat.postMessage |
Modal | .buildToJSON() | Full payload for the view parameter in views.open, views.update, and views.push |
HomeTab | .buildToJSON() | Full payload for the view parameter in views.publish |
If you only need the UI components without the surrounding API metadata, use the .getBlocks() method instead to retrieve an array of Blocks.
// To get a full API payload:
const payload = Modal.buildToJSON();
// To get only the UI blocks:
const blocks = Modal.getBlocks();