Post Workspace Usage by ID
POST
CoderSessionTokenheader
Coder-Session-Token<token>workspace*stringWorkspace ID
Format
uuidPost workspace usage request
application/json- body
agent_id?stringFormat
uuidapp_name?stringAppName is any name for the app reporting usage. The server normalizes it at ingestion, so a new app needs no server change. The UsageAppName constants are the well-known names.
No Content
The samples read CODER_URL and CODER_SESSION_TOKEN: set up your environment.
curl -X POST \ "$CODER_URL/api/v2/workspaces/{workspace}/usage" \ -H "Coder-Session-Token: $CODER_SESSION_TOKEN" \ -H "Content-Type: application/json" \ -d '{ "agent_id": "2b1e3b65-2c04-4fa2-a2d7-467901e98978", "app_name": "string"}'const { CODER_URL, CODER_SESSION_TOKEN } = process.env;const url = `${CODER_URL}/api/v2/workspaces/{workspace}/usage`;const response = await fetch(url, { method: "POST", headers: { "Coder-Session-Token": CODER_SESSION_TOKEN, "Content-Type": "application/json", }, body: JSON.stringify({ agent_id: "2b1e3b65-2c04-4fa2-a2d7-467901e98978", app_name: "string", }),});console.log(response.status, await response.text());import osimport requestsurl = os.environ["CODER_URL"] + "/api/v2/workspaces/{workspace}/usage"token = os.environ["CODER_SESSION_TOKEN"]response = requests.post( url, headers={ "Coder-Session-Token": token, }, json={ "agent_id": "2b1e3b65-2c04-4fa2-a2d7-467901e98978", "app_name": "string", },)print(response.status_code, response.text)package mainimport ( "fmt" "io" "net/http" "os" "strings")func main() { body := strings.NewReader(`{ "agent_id": "2b1e3b65-2c04-4fa2-a2d7-467901e98978", "app_name": "string"}`) url := os.Getenv("CODER_URL") + "/api/v2/workspaces/{workspace}/usage" token := os.Getenv("CODER_SESSION_TOKEN") req, err := http.NewRequest(http.MethodPost, url, body) if err != nil { panic(err) } req.Header.Set("Coder-Session-Token", token) req.Header.Set("Content-Type", "application/json") resp, err := http.DefaultClient.Do(req) if err != nil { panic(err) } defer resp.Body.Close() out, err := io.ReadAll(resp.Body) if err != nil { panic(err) } fmt.Println(resp.Status, string(out))}Example Response204
Empty