> For the complete documentation index, see [llms.txt](https://docs.p0.dev/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.p0.dev/access-management/just-in-time-access/just-in-time-api/command-api.md).

# Command API

The Command API enables programmatic creation of access requests within the P0 platform. It is designed to support custom workflows and automation. Integrate with external systems and services to initiate access grants without using the P0 user interface.

This is particularly useful for integrating P0 into your internal tooling, bots, or security workflows that require automatic access escalation based on alerts, CI/CD pipelines, or external approvals.

{% file src="/files/0GQJ2jd7mJ0WPKlWLehf" %}

## Create an access request

> Runs a P0 command for the authenticated identity. The request runs through your organization's access policies, guardrails, and audit trail exactly as a request made in the P0 dashboard or CLI does.

```json
{"openapi":"3.0.4","info":{"title":"P0 Command API","version":"1.0.0"},"servers":[{"url":"https://api.p0.app"}],"security":[{"bearerAuth":[]}],"components":{"securitySchemes":{"bearerAuth":{"type":"http","scheme":"bearer","bearerFormat":"API Key"}},"parameters":{"OrgId":{"name":"orgId","in":"path","required":true,"description":"The P0 organization slug, the same value that appears in console URLs at p0.app/o/{orgId}.","schema":{"type":"string"}}},"schemas":{"CommandRequest":{"type":"object","required":["argv","scriptName"],"properties":{"argv":{"type":"array","items":{"type":"string"},"description":"The command arguments, matching the `p0 request` CLI command with the leading `p0` removed. Each flag and its value are separate array elements, for example `[\"request\", \"aws\", \"role\", \"MyReadOnlyRole\", \"--account\", \"123456789012\", \"--reason\", \"...\"]`."},"scriptName":{"type":"string","description":"The client name to record for the invocation. Use `p0`."},"wait":{"type":"boolean","description":"When `true`, the response streams newline-delimited JSON status updates over the open connection until the request is approved, denied, or errors, instead of returning once the request is created. For one-shot status checks in automation, prefer polling `GET /o/{orgId}/permission-requests/{requestId}` from the Access Requests API."}}},"RequestCreated":{"type":"object","properties":{"ok":{"type":"boolean"},"id":{"type":"string","description":"The ID of the created access request. Use it with the Access Requests API to check status, approve, deny, or revoke."},"message":{"type":"string","description":"A human-readable confirmation, including a link to the request details page."},"isPreexisting":{"type":"boolean","description":"Whether an equivalent request or grant already existed."},"request":{"type":"object","description":"The created access request document."}}},"Error":{"type":"object","properties":{"error":{"type":"string","description":"A human-readable description of the failure."}}}},"responses":{"BadRequestError":{"description":"The request body is invalid, for example `argv` is missing or is not an array of strings.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"UnauthorizedError":{"description":"The caller could not be authenticated.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}}}},"paths":{"/o/{orgId}/command":{"post":{"summary":"Create an access request","description":"Runs a P0 command for the authenticated identity. The request runs through your organization's access policies, guardrails, and audit trail exactly as a request made in the P0 dashboard or CLI does.","parameters":[{"$ref":"#/components/parameters/OrgId"}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/CommandRequest"}}}},"responses":{"200":{"description":"The command ran. For `request` commands the body confirms the created access request and returns its ID.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/RequestCreated"}}}},"400":{"$ref":"#/components/responses/BadRequestError"},"401":{"$ref":"#/components/responses/UnauthorizedError"},"408":{"description":"The command did not complete before the server's timeout."}}}}}}
```
