> For the complete documentation index, see [llms.txt](https://docs.groundcover.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.groundcover.com/reference/remote-access-and-apis/api-examples/service-accounts-api.md).

# Service Accounts API

Create and manage non-human identities and their policy assignments.

Create and manage non-human identities and their policy assignments.

## Authentication

Admin permissions are required for all operations on this page. Set `GC_API_KEY` to an API key with the required permissions and `GC_BACKEND_ID` to the backend ID. Every example sends both headers. For self-hosted deployments, replace `https://api.groundcover.com` with your API URL.

## Endpoints

| Method | Endpoint                           | Operation                          |
| ------ | ---------------------------------- | ---------------------------------- |
| POST   | `/api/rbac/service-account/create` | Create                             |
| GET    | `/api/rbac/service-accounts/list`  | List                               |
| GET    | `/api/rbac/service-account/{id}`   | Get                                |
| PUT    | `/api/rbac/service-account/update` | Update email or policy assignments |
| DELETE | `/api/rbac/service-account/{id}`   | Delete                             |

## Create a service account

`name`, `email` (valid email address), and `policyUUIDs` (array) are required. Obtain policy UUIDs from the [RBAC Policies API](https://docs.groundcover.com/reference/remote-access-and-apis/api-examples/rbac-policies-api.md).

```bash
curl --request POST \
  --url "https://api.groundcover.com/api/rbac/service-account/create" \
  --header "Authorization: Bearer $GC_API_KEY" \
  --header "X-Backend-Id: $GC_BACKEND_ID" \
  --header "Content-Type: application/json" \
  --data '{
  "name": "automation-reader",
  "email": "automation@example.com",
  "policyUUIDs": [
    "<POLICY_UUID>"
  ]
}'
```

The response is HTTP `200` with `{"serviceAccountId":"<SERVICE_ACCOUNT_ID>"}`. A duplicate name returns `409`.

## List and get

```bash
curl --request GET \
  --url "https://api.groundcover.com/api/rbac/service-accounts/list" \
  --header "Authorization: Bearer $GC_API_KEY" \
  --header "X-Backend-Id: $GC_BACKEND_ID"
```

```bash
curl --request GET \
  --url "https://api.groundcover.com/api/rbac/service-account/<SERVICE_ACCOUNT_ID>" \
  --header "Authorization: Bearer $GC_API_KEY" \
  --header "X-Backend-Id: $GC_BACKEND_ID"
```

List returns an array; get returns one object. Each object includes `serviceAccountId`, `name`, `email`, `policies`, `deleted`, `lastActive`, `createdBy`, and `creationDate`.

## Update policy assignments

The update endpoint accepts `serviceAccountId`, optional `email`, `policyUUIDs`, and `overridePolicies`. At least a nonempty email or a nonempty policy list must be supplied. Policy UUIDs are appended by default; set `overridePolicies` to `true` to replace the assignments.

```bash
curl --request PUT \
  --url "https://api.groundcover.com/api/rbac/service-account/update" \
  --header "Authorization: Bearer $GC_API_KEY" \
  --header "X-Backend-Id: $GC_BACKEND_ID" \
  --header "Content-Type: application/json" \
  --data '{
  "serviceAccountId": "<SERVICE_ACCOUNT_ID>",
  "policyUUIDs": [
    "<POLICY_UUID>"
  ],
  "overridePolicies": true
}'
```

The response is HTTP `200` with `serviceAccountId`. An empty `policyUUIDs` array does **not** clear assignments through this endpoint.

## Delete

Revoke the account's API keys first using the [API Keys API](https://docs.groundcover.com/reference/remote-access-and-apis/api-examples/api-keys-api.md). Deletion is rejected with `400` while API keys prevent deletion, or `404` if the account does not exist.

```bash
curl --request DELETE \
  --url "https://api.groundcover.com/api/rbac/service-account/<SERVICE_ACCOUNT_ID>" \
  --header "Authorization: Bearer $GC_API_KEY" \
  --header "X-Backend-Id: $GC_BACKEND_ID"
```

Success returns HTTP `202` with no response body.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

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

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.groundcover.com/reference/remote-access-and-apis/api-examples/service-accounts-api.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
