# PUT /v1/account/apikey

> Create a new API key for your ReportingCloud account with a PUT request; the response body holds the new key as a JSON string to use in Authorization headers.

- **Product:** ReportingCloud
- **Section:** Documentation
- **Kind:** Endpoint
- **Path:** ReportingCloud > API Reference > Web API > Account > /apikey > PUT /v1/account/apikey
- **1884 words**
- **Web URL:** https://docs.textcontrol.com/reporting-cloud/reference/web-api/account/apikey/put/
- **LLMs URL:** https://docs.textcontrol.com/reporting-cloud/reference/web-api/account/apikey/put/llms.txt
- **LLMs-Full URL:** https://docs.textcontrol.com/reporting-cloud/reference/web-api/account/apikey/put/llms-full.txt

---

`PUT` `https://api.reporting.cloud/v1/account/apikey`

### Description

Creates a new API key for the account and returns it as a JSON string. A request that sends the key in the header `Authorization: ReportingCloud-APIKey <key>` needs no user name and password. The request has no body, but must send `Content-Length: 0`. See [API Keys](https://docs.textcontrol.com/reporting-cloud/installation/api-keys/llms-full.txt).

### Examples

#### HTTP

Request:

```bash
curl -u username:password -X PUT -H "Content-Length: 0" \
  "https://api.reporting.cloud/v1/account/apikey"
```

The request has no body, but without a `Content-Length` header or a chunked body, the Web API answers with status 411 (Length Required).

Results:

```json
"rcn9HChVnZmjkQA2YhveFd1CHq8W6SSkjLNqeyRw"
```

#### C#

Request:

```csharp
using System;
using System.Collections.Generic;
using System.Drawing;
using System.IO;
using TXTextControl.ReportingCloud;

class RCSamples
{
    public static void CreateAPIKey()
    {
        ReportingCloud rc = new ReportingCloud(
            "username",
            "password",
            new Uri("https://api.reporting.cloud"));

        try
        {
            string sAPIKey = rc.CreateAccountAPIKey();
            Console.WriteLine("New API key: " + sAPIKey);
        }
        catch (Exception e)
        {
            Console.WriteLine("An error occurred: " + e.Message);
        }
    }
}
```

Results:

```text
New API key: rcn9HChVnZmjkQA2YhveFd1CHq8W6SSkjLNqeyRw
```

#### Java

Request:

```java
import com.textcontrol.reportingcloud.ReportingCloud;

import java.io.IOException;

public class ReportingCloudSample {
    public static void main(String[] args) throws IOException {
        ReportingCloud r = new ReportingCloud("username", "password");
        String apiKey = r.createAPIKey();

        System.out.println("New API key: " + apiKey);
    }
}
```

Results:

```text
New API key: rcn9HChVnZmjkQA2YhveFd1CHq8W6SSkjLNqeyRw
```

#### Ruby

Request:

```ruby
#!/usr/bin/env ruby

require "txtextcontrol/reportingcloud"

reporting_cloud = TXTextControl::ReportingCloud::ReportingCloud.new("username", "password")
api_key = reporting_cloud.create_api_key

puts "New API key: #{api_key}"
```

Results:

```text
New API key: rcn9HChVnZmjkQA2YhveFd1CHq8W6SSkjLNqeyRw
```

#### PHP

Request:

```php
<?php

require_once __DIR__ . '/vendor/autoload.php';

use TextControl\ReportingCloud\ReportingCloud;

$reportingCloud = new ReportingCloud([
    'api_key' => (string) getenv('REPORTINGCLOUD_API_KEY'),
]);

var_dump($reportingCloud->createApiKey());
```

Results:

```text
string(40) "rcn9HChVnZmjkQA2YhveFd1CHq8W6SSkjLNqeyRw"
```

### Authorization

This endpoint requires a "ReportingCloud-APIKey" or a "Basic" user authorization to access the user account, data and templates. Only one of these two methods is required.

[API Keys](https://docs.textcontrol.com/reporting-cloud/installation/api-keys/llms-full.txt) describes how to create an API key, and [Authentication](https://docs.textcontrol.com/reporting-cloud/document-processing/authentication/llms-full.txt) explains both header forms.

#### ReportingCloud-APIKey

| Header field | Description |
|---|---|
| Authorization | **Required**. A valid ReportingCloud account is required. The Authorization field is constructed as follows: An API key needs to be generated in the portal or with [PUT /v1/account/apikey](https://docs.textcontrol.com/reporting-cloud/reference/web-api/account/apikey/put/llms-full.txt). The authorization method and a space, "ReportingCloud-APIKey ", is then put before the actual API key string. For example: `Authorization: ReportingCloud-APIKey oMDM4MrAqL9QEOpyzupnQW5NjvCNtvE5cVDaaLqxI` |

#### Basic

| Header field | Description |
|---|---|
| Authorization | **Required**. A valid ReportingCloud account is required. The Authorization field is constructed as follows: The user name and password are combined into a string separated by a colon, for example `username:password`. The resulting string is encoded using the RFC2045-MIME variant of Base64, except not limited to 76 char/line. The authorization method and a space, "Basic ", is then put before the encoded string. For example: `Authorization: Basic QWxhZGRpbjpPcGVuU2VzYW1l` |

### Success Response

| Status | Description |
|---|---|
| 201 | On success, the HTTP status code in the response header is 201 (Created). The response body contains the newly created API key as a JSON string. |

### Error Response

| Status | Description |
|---|---|
| 403 | A 403 (Forbidden) is returned, if the user is not authorized. |
| 405 | A 405 (Method Not Allowed) is returned, if the request uses another HTTP method than PUT. The Allow header of the response names PUT. |
| 411 | A 411 (Length Required) is returned, if the request has neither a Content-Length header, such as Content-Length: 0, nor a chunked body. |
| 500 | A 500 (Internal Server Error) is returned, if the request has no Authorization header, an empty one or one that is not the authorization method, a space and the credentials. |

---

## Nearby

- **Previous:** [DELETE /v1/account/apikey](https://docs.textcontrol.com/reporting-cloud/reference/web-api/account/apikey/delete/llms-full.txt)
- **Next:** [/v1/account/apikeys](https://docs.textcontrol.com/reporting-cloud/reference/web-api/account/apikeys/llms-full.txt)
