跳到主要内容

Delete an API Key

This example demonstrates how to delete an existing API key in ONLYOFFICE DocSpace by its unique identifier (UUID). Use this operation to revoke a key that is no longer needed or compromised.

Before you start

  1. Replace https://yourportal.onlyoffice.com and YOUR_API_KEY with your actual DocSpace portal URL and API key. Ensure you have the necessary data and permissions to perform migration operations.
  2. Before you can make requests to the API, you need to authenticate. Check out the Personal access tokens page to learn how to obtain and use access tokens.
Full example
// Set your DocSpace portal URL and access token
const API_HOST = 'https://yourportal.onlyoffice.com';
const API_KEY = 'your_api_key';

// Headers with authorization token
const HEADERS = {
Authorization: API_KEY,
};

// Step 1: Delete the API key by ID
function deleteApiKey(keyId) {
const url = `${API_HOST}/api/2.0/keys/${keyId}`;

return fetch(url, {
method: 'DELETE',
headers: HEADERS,
})
.then(async (res) => {
if (res.status === 200) return res.json();
const text = await res.text();
console.log(`API key deletion failed. Status code: ${res.status}, Message: ${text}`);
return null;
})
.then((data) => {
if (data?.response === true) {
console.log('API key deleted successfully.');
}
})
.catch((err) => {
console.log(`API key deletion error: ${err.message}`);
});
}

// Run the method
deleteApiKey('your_key_uuid');

How it works

A DELETE request is sent to /api/2.0/keys/:keyId using the UUID of the key.

If successful, the API responds with:

  • response: true — confirming that the key has been deleted.

This operation is typically used to revoke API keys that are no longer needed or that may have been compromised.