> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://docs.coperniq.io/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.coperniq.io/_mcp/server.

# Archive API User

POST https://api.coperniq.io/v1/api-users/{user_id}/archive

Archive an API user. Superadmins only. Deletes all of the API user's keys, so they stop working immediately, then deactivates the API user.

Use this instead of archiving the API user in the Coperniq UI. Archiving it there deactivates the user but does not delete its keys.

If any key can't be deleted, the response is a `502` and the API user is left active, so no key is left working on an archived account. Retry the request to finish. Archiving an API user that has no keys left is safe and returns `200`.

Archiving doesn't stop new keys from being created. If the person who created the API user calls `POST /api-keys` again, the API user is reactivated and gets a new key. The archive only returns `200` once it has confirmed no keys are left.

Authenticate with Basic Auth (your Coperniq email and password), not an API key.


Reference: https://docs.coperniq.io/api-key/api-key-management/archive-api-user

## Authentication

- `Authorization` header (basic auth, required) — Basic authentication of the form `Basic <base64(username:password)>`.

## Request

### Path parameters

- `user_id` (integer, required) — The API user's `id` from `GET /api-users`

### Query parameters

- `company_id` (integer, optional) — ID of the company to manage. Needed only when the authenticated user belongs to more than one company and the default (their first non-collaborator company) is not the one you want. You must be a superadmin in that company. Your company ID can be found in the URL after logging in to the Coperniq UI: `https://app.coperniq.io/{company_id}/inbox`.

## Response

### 200

All of the API user's keys were deleted and the API user was deactivated

- `success` (boolean, optional)
- `deletedKeyCount` (integer, optional) — Number of the API user's keys deleted by this request
- `failedKeyCount` (integer, optional) — Number of the API user's keys that could not be deleted
- `userDeactivated` (boolean, optional) — Whether the API user was deactivated
- `message` (string, optional) — Present when `success` is `false`

## Errors

### 400 Bad Request Error

`user_id` is not a positive integer, the user is not an API user (archive regular users in the Coperniq UI instead), or the credentials or `company_id` are malformed

- `message` (string, optional)

### 401 Unauthorized Error

Authentication credentials are missing or invalid

- `error` (string, optional)

### 403 Forbidden Error

The authenticated user is not a superadmin in the company, or doesn't belong to the requested `company_id`

- `message` (string, optional)

### 404 Not Found Error

No user with this ID in the company

- `message` (string, optional)

### 409 Conflict Error

New keys kept being created for this API user while it was being archived. Stop whatever is creating them, then retry

- `success` (boolean, optional)
- `deletedKeyCount` (integer, optional) — Number of the API user's keys deleted by this request
- `failedKeyCount` (integer, optional) — Number of the API user's keys that could not be deleted
- `userDeactivated` (boolean, optional) — Whether the API user was deactivated
- `message` (string, optional) — Present when `success` is `false`

### 502 Bad Gateway Error

Some keys could not be deleted. The API user was not deactivated; retry the request to finish

- `success` (boolean, optional)
- `deletedKeyCount` (integer, optional) — Number of the API user's keys deleted by this request
- `failedKeyCount` (integer, optional) — Number of the API user's keys that could not be deleted
- `userDeactivated` (boolean, optional) — Whether the API user was deactivated
- `message` (string, optional) — Present when `success` is `false`

## Examples

**Response**

```json
{
  "success": true,
  "deletedKeyCount": 2,
  "failedKeyCount": 0,
  "userDeactivated": true
}
```

**SDK Code**

```python API Key Management_archiveApiUser_example
import requests

url = "https://api.coperniq.io/v1/api-users/1/archive"

response = requests.post(url, auth=("<username>", "<password>"))

print(response.json())
```

```javascript API Key Management_archiveApiUser_example
const url = 'https://api.coperniq.io/v1/api-users/1/archive';
const credentials = btoa("<username>:<password>");

const options = {method: 'POST', headers: {Authorization: `Basic ${credentials}`}};

try {
  const response = await fetch(url, options);
  const data = await response.json();
  console.log(data);
} catch (error) {
  console.error(error);
}
```

```go API Key Management_archiveApiUser_example
package main

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

func main() {

	url := "https://api.coperniq.io/v1/api-users/1/archive"

	req, _ := http.NewRequest("POST", url, nil)

	req.SetBasicAuth("<username>", "<password>")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(res)
	fmt.Println(string(body))

}
```

```ruby API Key Management_archiveApiUser_example
require 'uri'
require 'net/http'

url = URI("https://api.coperniq.io/v1/api-users/1/archive")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Post.new(url)
request.basic_auth("<username>", "<password>")

response = http.request(request)
puts response.read_body
```

```java API Key Management_archiveApiUser_example
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.post("https://api.coperniq.io/v1/api-users/1/archive")
  .basicAuth("<username>", "<password>")
  .asString();
```

```php API Key Management_archiveApiUser_example
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://api.coperniq.io/v1/api-users/1/archive', [
  'headers' => [
  ],
    'auth' => ['<username>', '<password>'],
]);

echo $response->getBody();
```

```csharp API Key Management_archiveApiUser_example
using RestSharp;
using RestSharp.Authenticators;

var client = new RestClient("https://api.coperniq.io/v1/api-users/1/archive");
client.Authenticator = new HttpBasicAuthenticator("<username>", "<password>");
var request = new RestRequest(Method.POST);

IRestResponse response = client.Execute(request);
```

```swift API Key Management_archiveApiUser_example
import Foundation

let credentials = Data("<username>:<password>".utf8).base64EncodedString()

let headers = ["Authorization": "Basic \(credentials)"]

let request = NSMutableURLRequest(url: NSURL(string: "https://api.coperniq.io/v1/api-users/1/archive")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "POST"
request.allHTTPHeaderFields = headers

let session = URLSession.shared
let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in
  if (error != nil) {
    print(error as Any)
  } else {
    let httpResponse = response as? HTTPURLResponse
    print(httpResponse)
  }
})

dataTask.resume()
```