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
- Replace
https://yourportal.onlyoffice.comandYOUR_API_KEYwith your actual DocSpace portal URL and API key. Ensure you have the necessary data and permissions to perform migration operations. - 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
- Node.js
- Python
// 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');
import requests
# Set your DocSpace portal URL and access token
API_HOST = 'https://yourportal.onlyoffice.com'
API_KEY = 'your_api_key'
# Headers with authorization token
HEADERS = {
'Authorization': API_KEY
}
# Step 1: Delete the API key by ID
def delete_api_key(key_id):
url = f'{API_HOST}/api/2.0/keys/{key_id}'
response = requests.delete(url, headers=HEADERS)
if response.status_code == 200 and response.json().get('response') is True:
print('API key deleted successfully.')
else:
print(f"API key deletion failed. Status code: {response.status_code}, Message: {response.text}")
# Run the method
if __name__ == '__main__':
delete_api_key('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.