Get running containers for workspace agent
GET
CoderSessionTokenheader
Coder-Session-Token<token>workspaceagent*stringWorkspace agent ID
Format
uuidlabel*stringLabels
Format
key=valueOK
application/json- response
containers?array<>Containers is a list of containers visible to the workspace agent.
devcontainers?array<>Devcontainers is a list of devcontainers visible to the workspace agent.
warnings?array<string>Warnings is a list of warnings that may have occurred during the process of listing containers. This should not include fatal errors.
The samples read CODER_URL and CODER_SESSION_TOKEN: set up your environment.
curl -X GET \ "$CODER_URL/api/v2/workspaceagents/{workspaceagent}/containers?label={label}" \ -H "Coder-Session-Token: $CODER_SESSION_TOKEN"const { CODER_URL, CODER_SESSION_TOKEN } = process.env;const url = `${CODER_URL}/api/v2/workspaceagents/{workspaceagent}/containers?label={label}`;const response = await fetch(url, { method: "GET", headers: { "Coder-Session-Token": CODER_SESSION_TOKEN, },});console.log(response.status, await response.text());import osimport requestsurl = ( os.environ["CODER_URL"] + "/api/v2/workspaceagents/{workspaceagent}/containers?label={label}")token = os.environ["CODER_SESSION_TOKEN"]response = requests.get( url, headers={ "Coder-Session-Token": token, },)print(response.status_code, response.text)package mainimport ( "fmt" "io" "net/http" "os")func main() { url := os.Getenv("CODER_URL") + "/api/v2/workspaceagents/{workspaceagent}/containers?label={label}" token := os.Getenv("CODER_SESSION_TOKEN") req, err := http.NewRequest(http.MethodGet, url, nil) if err != nil { panic(err) } req.Header.Set("Coder-Session-Token", token) 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 Response200
{ "containers": [ { "created_at": "2019-08-24T14:15:22Z", "id": "string", "image": "string", "labels": { "property1": "string", "property2": "string" }, "name": "string", "ports": [ { "host_ip": "string", "host_port": 0, "network": "string", "port": 0 } ], "running": true, "status": "string", "volumes": { "property1": "string", "property2": "string" } } ], "devcontainers": [ { "agent": { "directory": "string", "id": "497f6eca-6276-4993-bfeb-53cbbbba6f08", "name": "string" }, "config_path": "string", "container": { "created_at": "2019-08-24T14:15:22Z", "id": "string", "image": "string", "labels": { "property1": "string", "property2": "string" }, "name": "string", "ports": [ { "host_ip": "string", "host_port": 0, "network": "string", "port": 0 } ], "running": true, "status": "string", "volumes": { "property1": "string", "property2": "string" } }, "dirty": true, "error": "string", "id": "497f6eca-6276-4993-bfeb-53cbbbba6f08", "name": "string", "status": "running", "subagent_id": "7b85d465-b649-4b8b-9da8-5f731c1d294d", "workspace_folder": "string" } ], "warnings": [ "string" ]}