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

# API Reference

Make your first IONOS CLOUD API request in three steps: get your credentials, get an access token, then list your data centers.

## Make your first request

Run the cURL commands in Bash, for example on macOS, Linux, or Windows Subsystem for Linux (WSL). In Windows PowerShell, `curl` is a different command, so use the CLI example below.

{% columns %}
{% column width="50%" %}
{% stepper %}
{% step %}

### Get your credentials

Use your IONOS CLOUD username and password, and save them in environment variables. If your account uses two-factor authentication (2FA), you must use a secure token instead: create one in the [<mark style="color:blue;">Token Manager</mark>](https://docs.ionos.com/cloud/set-up-ionos-cloud/management/identity-access-management/token-manager), then follow [<mark style="color:blue;">Use a secure token with 2FA</mark>](#use-a-secure-token-with-2fa). For all sign-in methods, see the [<mark style="color:blue;">Authentication reference</mark>](https://docs.ionos.com/cloud/api-reference/security/authentication.md).
{% endstep %}

{% step %}

### Get an access token

Request a token from the token endpoint. Copy the value of `token` from the JSON response and save it in `IONOS_ACCESS_TOKEN`. Already have a token? Save it in `IONOS_ACCESS_TOKEN` and go to step 3.
{% endstep %}

{% step %}

### List your data centers

Send the token in the `Authorization` header. The response lists your data centers in `items`. If `items` is empty, your access works and you have no data center yet. Create one in the [<mark style="color:blue;">Data Center Designer</mark>](https://docs.ionos.com/cloud/set-up-ionos-cloud/get-started/create-data-center) or [<mark style="color:blue;">with the API</mark>](https://docs.ionos.com/api-reference/cloud-api-v6/data-centers/create-a-data-center).
{% endstep %}
{% endstepper %}
{% endcolumn %}

{% column %}
{% code title="Username and password · cURL" %}

```
# Step 1: Set your credentials
export IONOS_USERNAME="<your-username>"
export IONOS_PASSWORD="<your-password>"

# Step 2: Request an access token
curl "https://api.ionos.com/auth/v1/tokens/generate" \
  --user "$IONOS_USERNAME:$IONOS_PASSWORD"

# Copy the token from the response, then save it
export IONOS_ACCESS_TOKEN="<paste-your-token>"

# Step 3: List your data centers
curl "https://api.ionos.com/cloudapi/v6/datacenters" \
  --header "Authorization: Bearer $IONOS_ACCESS_TOKEN"
```

{% endcode %}
{% endcolumn %}
{% endcolumns %}

### Use a secure token with 2FA

If your account uses 2FA, request the access token with your secure token. Steps 1 and 2 change. Step 3 stays the same.

{% code title="Secure token · cURL" %}

```
# Step 1: Set your secure token
export IONOS_SECURE_TOKEN="<your-secure-token>"

# Step 2: Request an access token
curl "https://api.ionos.com/auth/v1/tokens/generate" \
  --header "Authorization: Bearer $IONOS_SECURE_TOKEN"

# Copy the token from the response, then save it
export IONOS_ACCESS_TOKEN="<paste-your-token>"

# Step 3: List your data centers
curl "https://api.ionos.com/cloudapi/v6/datacenters" \
  --header "Authorization: Bearer $IONOS_ACCESS_TOKEN"
```

{% endcode %}

{% hint style="info" %}
**Got an error?**

* A 401 response means the API rejected your username, password, or token.
* A 401 response can also mean that the user or contract is not valid.
* A username and password work only when 2FA is off. Otherwise, use a secure token.
* With more than one contract, the token request also needs `--header "X-Contract-Number: <contract-number>"`. Without it, the API returns an error.
  {% endhint %}

## Send the request from code or the CLI

Each example lists your data centers. Python, Go, and Ruby read the token from `IONOS_ACCESS_TOKEN`, which you set in step 2. The CLI signs you in once and stores a token.

{% tabs %}
{% tab title="Python" %}

```python
# Install the library first: pip install requests
import os

import requests

res = requests.get(
    "https://api.ionos.com/cloudapi/v6/datacenters",
    headers={"Authorization": f"Bearer {os.environ['IONOS_ACCESS_TOKEN']}"},
)
res.raise_for_status()
print(res.json())
```

{% endtab %}

{% tab title="Go" %}

```go
package main

import (
  "fmt"
  "io"
  "net/http"
  "os"
)

func main() {
  req, _ := http.NewRequest("GET", "https://api.ionos.com/cloudapi/v6/datacenters", nil)
  req.Header.Set("Authorization", "Bearer "+os.Getenv("IONOS_ACCESS_TOKEN"))

  res, err := http.DefaultClient.Do(req)
  if err != nil {
    panic(err)
  }
  defer res.Body.Close()

  body, _ := io.ReadAll(res.Body)
  fmt.Println(string(body))
}
```

{% endtab %}

{% tab title="Ruby" %}

```ruby
require "net/http"
require "uri"

token = ENV.fetch("IONOS_ACCESS_TOKEN")
uri = URI("https://api.ionos.com/cloudapi/v6/datacenters")

req = Net::HTTP::Get.new(uri)
req["Authorization"] = "Bearer #{token}"

res = Net::HTTP.start(uri.host, uri.port, use_ssl: true) { |http| http.request(req) }
puts res.body
```

{% endtab %}

{% tab title="CLI" %}
{% code title="ionosctl" %}

```
# Sign in. ionosctl asks for your username and password.
ionosctl config login

# List your data centers
ionosctl compute datacenter list
```

{% endcode %}
{% endtab %}
{% endtabs %}

## Next steps

* [<mark style="color:blue;">Getting started with the API</mark>](https://docs.ionos.com/cloud/api-reference/start-here/getting-started.md)
* [<mark style="color:blue;">Cloud API v6</mark>](https://docs.ionos.com/cloud/api-reference/cloud-api-v6.md)

[<mark style="color:blue;">Documentation home</mark>](https://docs.ionos.com/cloud/home) | [<mark style="color:blue;">SDKs and tools</mark>](https://docs.ionos.com/cloud/sdk-tools-home) | [<mark style="color:blue;">Products</mark>](https://docs.ionos.com/cloud/product-guides)


---

# 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.ionos.com/cloud/api-reference/readme.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.
