> For the complete documentation index, see [llms.txt](https://docs.docontrol.io/docontrol-user-guide/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.docontrol.io/docontrol-user-guide/system-management/api.md). Agents can also search and read this documentation through its [MCP server](https://docs.docontrol.io/docontrol-user-guide/~gitbook/mcp).

# API

DoControl exposes an API enabling you to interact and retrieve data from DoControl and your integrated apps programmatically. The API is based on the [GraphQL](https://graphql.org/) query language. For more information about working with GraphQL, see [error handling](#graphql-error-handling).

{% hint style="warning" %}
You need at least **admin** permission to interact with DoControl API.
{% endhint %}

#### To work with DoControl API, you need to:

1. [Create an API key](#create-api-keys)
2. [Receive an access token](#receive-an-access-token)
3. [Interact with the DoControl API](#interact-with-docontrol-api)

You can use the following pre-made Postman collection as a reference example:

{% file src="/files/ysBdY9HU1emfDxBPJAbu" %}

## Create API keys

You can create API keys to securely access and interact with DoControl via GraphQL.

{% hint style="warning" %}
You need at least **admin** permission to create and delete API keys, and leverage them in DoControl API.
{% endhint %}

![](https://3236294211-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MesrnyDMZGYg1V-tOBo%2Fuploads%2FBMpMvcE9S8BHUl93q79N%2FAPI%20keys.png?alt=media\&token=c2697159-937d-49e9-96ea-1cdf84f6570e)

#### To create an API key:&#x20;

1. From the DoControl side menu, click **Settings** > **Admin** > **API keys**.&#x20;
2. Click **Add API key**.<br>

   <div align="left"><figure><img src="https://3236294211-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MesrnyDMZGYg1V-tOBo%2Fuploads%2FZLLrPIpi0l6jxUfhO3IV%2FAdd%20API%20key.png?alt=media&amp;token=15fc7ec9-b09b-4b07-8092-ae0d1ffe27a1" alt=""><figcaption></figcaption></figure></div>
3. Enter a name for the API key.
4. Select the relevant access permission to apply to the API key:
   * **Super admin** - API key is privileged to change any functionality in DoControl, including system configuration and Team settings.
   * **Admin** - API key is privileged to change any functionality in DoControl, including system configuration, but not Team settings.
   * **Viewer** - API key can only read data in DoControl, except for all data in Settings.
5. When you apply or change access permissions to an API key, keep in mind your own access permission:
   * **Super admin** - Can apply any permission to an API key
   * **Admin** - Can apply only admin or viewer permission, but not super admin permission
6. Enter a name for the API key, and click **Create**. A **refresh token** is shown, copy it and keep it in a safe place.
7. To use DoControl's [API](https://docs.docontrol.io/docontrol-user-guide/system-management/api.md), go to **Advanced** > **API**.

{% hint style="info" %}

* You can add up to 10 API keys.
* The **refresh token** is valid for 10 years.
* When adding a **Key name:**
  * You can only use the following characters: \[a-z, A-Z, 0-9, \_ ]
  * Two keys cannot have the same name
    {% endhint %}

{% hint style="warning" %}
After leaving the **API keys** page, the API key (refresh token) that you have created will not be accessible. **Make sure you copy it, and keep it in a safe place**.
{% endhint %}

## Receive an access token

1. Paste the **refresh token** that you saved (when [creating the API key](#create-api-keys)) as a key value in the following API call: <https://auth.prod.docontrol.io/refresh>. An **access token** is returned.
2. Use the **access token** to interact with the DoControl API.&#x20;

![Postman example for fetching the access token](https://3236294211-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MesrnyDMZGYg1V-tOBo%2Fuploads%2FT5AS5ovgjLhjs4GVV9Tc%2Fimage.png?alt=media\&token=c11769c7-ddb5-4ffb-be56-b34de9b57f0c)

{% hint style="info" %}
The **refresh token** is valid for 10 years, the **access token** is valid for 5 minutes.&#x20;
{% endhint %}

## Interact with DoControl API

For exploratory research and testing, you can interact directly with GraphQL from within DoControl. You need an [access token](#receive-an-access-token) to interact with the DoControl API.

Example for interacting via HTTP request:\ <mark style="color:green;">`POST`</mark>` ``https://apollo-gateway-v4-api.prod.docontrol.io/graphql`\
**`Authorization`**`: Bearer [access token]`\
**`Body:`**`[GraphQL query]`

![Access token entered in the Postman API request header](https://3236294211-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MesrnyDMZGYg1V-tOBo%2Fuploads%2F2DigpQ9A2qOnmqjFovYq%2FAPI%20settings%201.png?alt=media\&token=a4ce127d-6ae0-42f3-8af2-2979ec24de70)

![API call example with GraphQL query in Postman](https://3236294211-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MesrnyDMZGYg1V-tOBo%2Fuploads%2FrhIlmotX2Vacl1TNV99y%2FAPI%20settings%202.png?alt=media\&token=93786a0e-f698-4deb-9f68-8ddf0e26606c)

#### To interact with the DoControl API:

1. From the DoControl side menu, click **Advanced** > **API**.

   ![](https://3236294211-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MesrnyDMZGYg1V-tOBo%2Fuploads%2Fk71VA5oOGMVuIyhwgAU5%2FConsume%20API.png?alt=media\&token=3e422714-df8d-475f-a695-d4c1a3924c75)
2. In the left pane, explore the DoControl API.
3. Explore all available queries, their input and output, variables and their descriptions:&#x20;
   * Click ![](https://3236294211-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MesrnyDMZGYg1V-tOBo%2Fuploads%2Fx9k97dsaFgO2t61UKyRV%2Fimage.png?alt=media\&token=3e686398-852e-4e12-9bf5-38e10955a96e) at the top to display the query output in a separate pane.
   * Click **Docs** at the top to open another pane with the description of the query.&#x20;
4. Create a sample code snippet ready to run in your code:&#x20;
   * Click **Code Explorer** at the top to open a pane with the code.
   * Copy this code and embed it into your own code. &#x20;

## GraphQL error handling

In GraphQL, all requests must go to a single endpoint:

`POST https://example.com/graphql`

A GraphQL API will always return a `200 OK` status code, even in case of an error. You'll get a 5xx error in case the server is not available at all.

The standard error handling mechanism from GraphQL will return a JSON containing:

* A `data` key which contains the data corresponding to the GraphQL operation (query, mutation, subscription) invoked, and
* An `errors` key which contains an array of errors returned by the server, with a message and location.

{% code overflow="wrap" lineNumbers="true" %}

```
{  "errors":[
    {
          "message": "User not found",
          "locations": [{ "line": 6, "column": 7 }],
          "path": ["user", 1]
     }
    ]
   }
```

{% endcode %}


---

# 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.docontrol.io/docontrol-user-guide/system-management/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.
