# Metadata

Read TaskBot and agent details.

**API** `zw.getTaskbotInfo()`, `zw.getAgentInfo()`

```javascript
const taskbotInfo = await zw.getTaskbotInfo();
await zw.log("variables", taskbotInfo.variables);

const agent = zw.getAgentInfo();
await zw.log("agent version", agent.version);
```

***

#### At a Glance

* `zw.getAgentInfo()` \
  → returns `{ version: string }` (for example, `{ version: "1.1.72" }`).
* <mark style="color:$info;">async/sync\*</mark> \
  `await zw.getTaskbotInfo()` → returns:

  ```ts
  {
    id: number,
    name: string, // TaskBot name
    runType: "immediate" | "scheduled" | "webhook",
    currentRunResult: "success" | "warning" | "error" | "manually_stopped",
    variables: { ref_id: number, variableNames: string[] },
    tables: Array<{
      ref_id: number,
      type: "G_SHEETS" | "ZW_NATIVE",
      columnNames: string[]
    }>,
    webhookURL: string | null,
  }
  ```

\*`async` in browser, `sync` locally (see [/pages/1CmxmmRih9Urxyv0GTdm#local-vs.-browser-execution](https://docs.zerowork.io/using-zerowork/using-building-blocks/write-javascript/pages/1CmxmmRih9Urxyv0GTdm#local-vs.-browser-execution "mention")).

***

#### **Examples**

**Branch behavior by run type**

```js
const info = await zw.getTaskbotInfo();
if (info.runType === "scheduled") {
  await zw.log("Running in scheduled mode");
}
```

**Get tables by type**

```js
const info = await zw.getTaskbotInfo();
const gSheets = info.tables.filter(t => t.type === "G_SHEETS");
await zw.log("Google Sheets tables", gSheets);
```

**Add webhook URL to state and reuse later**

```js
// @zw-run-locally
import axios from "axios";

// Add TaskBot webhook to global state
const info = await zw.getTaskbotInfo();
const webhookURL = info.webhookURL;
if (webhookURL) {
  (zw.globalState.access().webhooksToTrigger ||=[]).push(webhookURL);
}

// In another TaskBot, access global state and trigger webhooks
const webhooks = zw.globalState.access().webhooksToTrigger || [];
for (const url of webhooks) {
  await axios.post(url);
}
```

***

#### Notes

* **Column/vatiables names, not values.**\
  For tables and variables, metadata returns **names** (variable names and column names). To read values, use `zw.getRef()`.
* **Async behavior.**\
  In the browser, `zw.getTaskbotInfo()` is async — use `await`. When Write JS code runs locally, `await` is optional (examples use `await` for consistency). `zw.getAgentInfo()` is sync everywhere.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.zerowork.io/using-zerowork/using-building-blocks/write-javascript/metadata.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
