> For clean Markdown of any page, append `.md` to the page URL. > For a complete documentation index, see https://docs.sarvam.ai/llms.txt. > For full documentation content in one file, see https://docs.sarvam.ai/llms-full.txt. > For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.sarvam.ai/_mcp/server. # Create widget POST https://apps.sarvam.ai/api/analytics/v1/{org_id}/{workspace_id}/boards/{board_id}/widgets Content-Type: application/json Validates the SQL, registers the filter tokens it declares, and places the widget on `tab_id` or the board's first tab. Reference: https://docs.sarvam.ai/api-reference/boards/widgets/create ## Request ### Path parameters - `org_id` (string, required) — Organization ID - `workspace_id` (string, required) — Workspace ID - `board_id` (string, required) ### Headers - `X-API-Key` (string, required) — Your workspace API key. ### Body (application/json) This endpoint expects a CreateWidgetRequest. - `name` (string, required) — Widget display name - `sql` (string, required) — Read-only SELECT against the workspace's analytics views. Filter tokens use `{{name}}` for a required value and `[[AND col = {{name}}]]` for a clause that is dropped when the value is absent. Tenant scoping is enforced server-side. - `viz_type` (enum, optional, default: table) — How the result is rendered - Allowed values: `number`, `table`, `bar`, `line` - `viz_config` (VizConfig, optional) — Renderer options for `viz_type` - `filters` (list of FilterInput, optional) — Declarations for the filter tokens used in `sql` - `tab_id` (string, optional, nullable) — Target tab. Defaults to the board's first tab when absent. ## Response ### 201 Successful Response - `id` (string, required) — Widget identifier - `board_id` (string, required) — Board this widget belongs to - `name` (string, required) — Widget display name - `sql` (string, required) — The widget's stored SQL, filter tokens unexpanded - `viz_type` (string, required) — How the result is rendered - `viz_config` (VizConfig, required) — Renderer options for `viz_type` - `created_by` (Actor, required) — Actor that created the widget - `created_at` (datetime, required) — Creation time, UTC, RFC 3339 - `updated_by` (Actor, required) — Actor that last changed the widget - `updated_at` (datetime, required) — Last change time, UTC, RFC 3339 ## Errors ### 400 Bad Request Error Request failed validation - `error` (ErrorBody, required) — Details of the error that occurred. ### 401 Unauthorized Error Missing or invalid credentials - `error` (ErrorBody, required) — Details of the error that occurred. ### 403 Forbidden Error Credentials are not scoped to this org and workspace - `error` (ErrorBody, required) — Details of the error that occurred. ### 404 Not Found Error No such resource in this workspace - `error` (ErrorBody, required) — Details of the error that occurred. ### 422 Unprocessable Entity Error Validation Error - `detail` (list of ValidationError, optional) ### 429 Too Many Requests Error Rate limit exceeded. Honour the `Retry-After` response header before retrying. - `error` (ErrorBody, required) — Details of the error that occurred. ### 500 Internal Server Error Unexpected server error - `error` (ErrorBody, required) — Details of the error that occurred. ## Types ### VizConfig Widget visualization options. Every field is optional so partial updates work, and unrecognised top-level keys are rejected. - `layout` (Layout, optional, nullable) — Position + size of a widget on the dashboard grid. - `x_axis` (string, optional, nullable) - `y_axis` (list of string, optional, nullable) - `series_breakout` (string, optional, nullable) ### FilterInput - `internal_name` (string, required) - `display_label` (string, required) - `filter_type` (enum, optional, default: string) - Allowed values: `number`, `string`, `date`, `dropdown` - `default_value` (string, optional, nullable) - `dropdown_options` (list of DropdownOption, optional, nullable) ### Actor - `type` (enum, required) — Whether a user or an API key performed the action. - Allowed values: `user`, `api_key` - `id` (string, required) — User identifier for `user`; the key prefix for `api_key`. ### ErrorBody Details of the error that occurred. - `code` (string, required) — A service-specific error code. - `message` (string, required) — A human-readable description of the error. ### ValidationError - `loc` (list of ValidationErrorLocItems, required) - `msg` (string, required) - `type` (string, required) ### Layout Position + size of a widget on the dashboard grid. - `x` (double, required) - `y` (double, required) - `w` (double, required) - `h` (double, required) ### DropdownOption - `label` (string, required) - `value` (string, required) ### ValidationErrorLocItems ## Examples **Request** ```json { "name": "Daily connected calls", "sql": "SELECT\n toDate(effective_datetime) AS day,\n countIf(v2v_connectivity_status = 'connected') AS connected,\n count() AS total\nFROM EngagementFactsBoardsView\nWHERE effective_datetime >= {{start_date}}\n [[AND app_id = {{agent_id}}]]\nGROUP BY day\nORDER BY day", "viz_type": "line", "viz_config": { "x_axis": "day", "y_axis": [ "connected", "total" ] }, "filters": [ { "internal_name": "start_date", "display_label": "Start date", "filter_type": "date", "default_value": "2026-09-01" }, { "internal_name": "agent_id", "display_label": "Agent", "filter_type": "string", "default_value": null } ], "tab_id": "6d1e84b3-9c07-4f52-b8ad-2e5f70c94a18" } ``` **Response** ```json { "id": "a4c9e0f7-31b8-4d6a-9e25-7f0b3c81d46e", "board_id": "0b7f2c9a-5e41-4d2a-9f3b-8c1d6e7a0b52", "name": "Daily connected calls", "sql": "SELECT\n toDate(effective_datetime) AS day,\n countIf(v2v_connectivity_status = 'connected') AS connected,\n count() AS total\nFROM EngagementFactsBoardsView\nWHERE effective_datetime >= {{start_date}}\n [[AND app_id = {{agent_id}}]]\nGROUP BY day\nORDER BY day", "viz_type": "line", "viz_config": { "x_axis": "day", "y_axis": [ "connected", "total" ] }, "created_by": { "type": "api_key", "id": "sk_live_a1b2c3" }, "created_at": "2026-09-01T09:22:31Z", "updated_by": { "type": "api_key", "id": "sk_live_a1b2c3" }, "updated_at": "2026-09-10T14:03:55Z" } ``` **SDK Code** ```python import requests url = "https://apps.sarvam.ai/api/analytics/v1/org_id/workspace_id/boards/board_id/widgets" payload = { "name": "Daily connected calls", "sql": "SELECT toDate(effective_datetime) AS day, countIf(v2v_connectivity_status = 'connected') AS connected, count() AS total FROM EngagementFactsBoardsView WHERE effective_datetime >= {{start_date}} [[AND app_id = {{agent_id}}]] GROUP BY day ORDER BY day", "viz_type": "line", "viz_config": { "x_axis": "day", "y_axis": ["connected", "total"] }, "filters": [ { "internal_name": "start_date", "display_label": "Start date", "filter_type": "date", "default_value": "2026-09-01" }, { "internal_name": "agent_id", "display_label": "Agent", "filter_type": "string", "default_value": None } ], "tab_id": "6d1e84b3-9c07-4f52-b8ad-2e5f70c94a18" } headers = { "X-API-Key": "", "Content-Type": "application/json" } response = requests.post(url, json=payload, headers=headers) print(response.json()) ``` ```javascript const url = 'https://apps.sarvam.ai/api/analytics/v1/org_id/workspace_id/boards/board_id/widgets'; const options = { method: 'POST', headers: {'X-API-Key': '', 'Content-Type': 'application/json'}, body: '{"name":"Daily connected calls","sql":"SELECT\n toDate(effective_datetime) AS day,\n countIf(v2v_connectivity_status = \'connected\') AS connected,\n count() AS total\nFROM EngagementFactsBoardsView\nWHERE effective_datetime >= {{start_date}}\n [[AND app_id = {{agent_id}}]]\nGROUP BY day\nORDER BY day","viz_type":"line","viz_config":{"x_axis":"day","y_axis":["connected","total"]},"filters":[{"internal_name":"start_date","display_label":"Start date","filter_type":"date","default_value":"2026-09-01"},{"internal_name":"agent_id","display_label":"Agent","filter_type":"string","default_value":null}],"tab_id":"6d1e84b3-9c07-4f52-b8ad-2e5f70c94a18"}' }; try { const response = await fetch(url, options); const data = await response.json(); console.log(data); } catch (error) { console.error(error); } ``` ```go package main import ( "fmt" "strings" "net/http" "io" ) func main() { url := "https://apps.sarvam.ai/api/analytics/v1/org_id/workspace_id/boards/board_id/widgets" payload := strings.NewReader("{\n \"name\": \"Daily connected calls\",\n \"sql\": \"SELECT\\n toDate(effective_datetime) AS day,\\n countIf(v2v_connectivity_status = 'connected') AS connected,\\n count() AS total\\nFROM EngagementFactsBoardsView\\nWHERE effective_datetime >= {{start_date}}\\n [[AND app_id = {{agent_id}}]]\\nGROUP BY day\\nORDER BY day\",\n \"viz_type\": \"line\",\n \"viz_config\": {\n \"x_axis\": \"day\",\n \"y_axis\": [\n \"connected\",\n \"total\"\n ]\n },\n \"filters\": [\n {\n \"internal_name\": \"start_date\",\n \"display_label\": \"Start date\",\n \"filter_type\": \"date\",\n \"default_value\": \"2026-09-01\"\n },\n {\n \"internal_name\": \"agent_id\",\n \"display_label\": \"Agent\",\n \"filter_type\": \"string\",\n \"default_value\": null\n }\n ],\n \"tab_id\": \"6d1e84b3-9c07-4f52-b8ad-2e5f70c94a18\"\n}") req, _ := http.NewRequest("POST", url, payload) req.Header.Add("X-API-Key", "") req.Header.Add("Content-Type", "application/json") res, _ := http.DefaultClient.Do(req) defer res.Body.Close() body, _ := io.ReadAll(res.Body) fmt.Println(res) fmt.Println(string(body)) } ``` ```ruby require 'uri' require 'net/http' url = URI("https://apps.sarvam.ai/api/analytics/v1/org_id/workspace_id/boards/board_id/widgets") http = Net::HTTP.new(url.host, url.port) http.use_ssl = true request = Net::HTTP::Post.new(url) request["X-API-Key"] = '' request["Content-Type"] = 'application/json' request.body = "{\n \"name\": \"Daily connected calls\",\n \"sql\": \"SELECT\\n toDate(effective_datetime) AS day,\\n countIf(v2v_connectivity_status = 'connected') AS connected,\\n count() AS total\\nFROM EngagementFactsBoardsView\\nWHERE effective_datetime >= {{start_date}}\\n [[AND app_id = {{agent_id}}]]\\nGROUP BY day\\nORDER BY day\",\n \"viz_type\": \"line\",\n \"viz_config\": {\n \"x_axis\": \"day\",\n \"y_axis\": [\n \"connected\",\n \"total\"\n ]\n },\n \"filters\": [\n {\n \"internal_name\": \"start_date\",\n \"display_label\": \"Start date\",\n \"filter_type\": \"date\",\n \"default_value\": \"2026-09-01\"\n },\n {\n \"internal_name\": \"agent_id\",\n \"display_label\": \"Agent\",\n \"filter_type\": \"string\",\n \"default_value\": null\n }\n ],\n \"tab_id\": \"6d1e84b3-9c07-4f52-b8ad-2e5f70c94a18\"\n}" response = http.request(request) puts response.read_body ``` ```java import com.mashape.unirest.http.HttpResponse; import com.mashape.unirest.http.Unirest; HttpResponse response = Unirest.post("https://apps.sarvam.ai/api/analytics/v1/org_id/workspace_id/boards/board_id/widgets") .header("X-API-Key", "") .header("Content-Type", "application/json") .body("{\n \"name\": \"Daily connected calls\",\n \"sql\": \"SELECT\\n toDate(effective_datetime) AS day,\\n countIf(v2v_connectivity_status = 'connected') AS connected,\\n count() AS total\\nFROM EngagementFactsBoardsView\\nWHERE effective_datetime >= {{start_date}}\\n [[AND app_id = {{agent_id}}]]\\nGROUP BY day\\nORDER BY day\",\n \"viz_type\": \"line\",\n \"viz_config\": {\n \"x_axis\": \"day\",\n \"y_axis\": [\n \"connected\",\n \"total\"\n ]\n },\n \"filters\": [\n {\n \"internal_name\": \"start_date\",\n \"display_label\": \"Start date\",\n \"filter_type\": \"date\",\n \"default_value\": \"2026-09-01\"\n },\n {\n \"internal_name\": \"agent_id\",\n \"display_label\": \"Agent\",\n \"filter_type\": \"string\",\n \"default_value\": null\n }\n ],\n \"tab_id\": \"6d1e84b3-9c07-4f52-b8ad-2e5f70c94a18\"\n}") .asString(); ``` ```php request('POST', 'https://apps.sarvam.ai/api/analytics/v1/org_id/workspace_id/boards/board_id/widgets', [ 'body' => '{ "name": "Daily connected calls", "sql": "SELECT\\n toDate(effective_datetime) AS day,\\n countIf(v2v_connectivity_status = \'connected\') AS connected,\\n count() AS total\\nFROM EngagementFactsBoardsView\\nWHERE effective_datetime >= {{start_date}}\\n [[AND app_id = {{agent_id}}]]\\nGROUP BY day\\nORDER BY day", "viz_type": "line", "viz_config": { "x_axis": "day", "y_axis": [ "connected", "total" ] }, "filters": [ { "internal_name": "start_date", "display_label": "Start date", "filter_type": "date", "default_value": "2026-09-01" }, { "internal_name": "agent_id", "display_label": "Agent", "filter_type": "string", "default_value": null } ], "tab_id": "6d1e84b3-9c07-4f52-b8ad-2e5f70c94a18" }', 'headers' => [ 'Content-Type' => 'application/json', 'X-API-Key' => '', ], ]); echo $response->getBody(); ``` ```csharp using RestSharp; var client = new RestClient("https://apps.sarvam.ai/api/analytics/v1/org_id/workspace_id/boards/board_id/widgets"); var request = new RestRequest(Method.POST); request.AddHeader("X-API-Key", ""); request.AddHeader("Content-Type", "application/json"); request.AddParameter("application/json", "{\n \"name\": \"Daily connected calls\",\n \"sql\": \"SELECT\\n toDate(effective_datetime) AS day,\\n countIf(v2v_connectivity_status = 'connected') AS connected,\\n count() AS total\\nFROM EngagementFactsBoardsView\\nWHERE effective_datetime >= {{start_date}}\\n [[AND app_id = {{agent_id}}]]\\nGROUP BY day\\nORDER BY day\",\n \"viz_type\": \"line\",\n \"viz_config\": {\n \"x_axis\": \"day\",\n \"y_axis\": [\n \"connected\",\n \"total\"\n ]\n },\n \"filters\": [\n {\n \"internal_name\": \"start_date\",\n \"display_label\": \"Start date\",\n \"filter_type\": \"date\",\n \"default_value\": \"2026-09-01\"\n },\n {\n \"internal_name\": \"agent_id\",\n \"display_label\": \"Agent\",\n \"filter_type\": \"string\",\n \"default_value\": null\n }\n ],\n \"tab_id\": \"6d1e84b3-9c07-4f52-b8ad-2e5f70c94a18\"\n}", ParameterType.RequestBody); IRestResponse response = client.Execute(request); ``` ```swift import Foundation let headers = [ "X-API-Key": "", "Content-Type": "application/json" ] let parameters = [ "name": "Daily connected calls", "sql": "SELECT toDate(effective_datetime) AS day, countIf(v2v_connectivity_status = 'connected') AS connected, count() AS total FROM EngagementFactsBoardsView WHERE effective_datetime >= {{start_date}} [[AND app_id = {{agent_id}}]] GROUP BY day ORDER BY day", "viz_type": "line", "viz_config": [ "x_axis": "day", "y_axis": ["connected", "total"] ], "filters": [ [ "internal_name": "start_date", "display_label": "Start date", "filter_type": "date", "default_value": "2026-09-01" ], [ "internal_name": "agent_id", "display_label": "Agent", "filter_type": "string", "default_value": ] ], "tab_id": "6d1e84b3-9c07-4f52-b8ad-2e5f70c94a18" ] as [String : Any] let postData = JSONSerialization.data(withJSONObject: parameters, options: []) let request = NSMutableURLRequest(url: NSURL(string: "https://apps.sarvam.ai/api/analytics/v1/org_id/workspace_id/boards/board_id/widgets")! as URL, cachePolicy: .useProtocolCachePolicy, timeoutInterval: 10.0) request.httpMethod = "POST" request.allHTTPHeaderFields = headers request.httpBody = postData as Data let session = URLSession.shared let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in if (error != nil) { print(error as Any) } else { let httpResponse = response as? HTTPURLResponse print(httpResponse) } }) dataTask.resume() ```