api_keys.php¶
API key management module for handling creation, modification, deletion, and listing of API keys with IP access control and server association.
API Methods¶
| Method | Action | Description |
|---|---|---|
add | add api key | Creates a new API key for the authenticated customer. If the customer has active services or balance, they can create keys. |
add_history | add history entry | Manually adds a history log entry for an API key. |
count_owned | get count of owned keys | Returns the total number of API keys owned by the authenticated customer. |
delete | delete api key | Deletes an API key. |
edit | edit api key | Updates an existing API key's name, IP restrictions, or server association. |
history | get api key history | Retrieves the audit log/history for API keys. |
list | get all api keys | Returns a list of all API keys owned by the authenticated customer. |
list_for_customer | get api keys for customer | Lists API keys filtered by a specific customer ID. |
list_for_server | get api keys for server | Lists API keys associated with a specific server. |
view | get api key details | Returns detailed information for a specific API key. |
api_keys/add¶
Creates a new API key for the authenticated customer. If the customer has active services or balance, they can create keys.
HTTP Method: POST
Parameters:
| Parameter | Required | Type | Description |
|---|---|---|---|
| action | ✅ | string | Method identifier: add |
| params[name] | ✅ | string | Name of the API key. |
| params[ip] | ❌ | string | IP access control list. Supports multiple IPs or CIDR notation separated by spaces. Example: 192.168.1.1/32 10.0.0.0/24. |
| params[server_id] | ❌ | integer | ID of the server to associate with this API key. |
| params[active] | ❌ | boolean | Whether the API key is active. Defaults to 1 (true). |
| params[login_notify_method] | ✅ | string | Method used for login notifications. Allowed values: none, email, webhook. |
| params[login_notify_address] | ❌ | string | Address for the notification (email address or URL). |
Example Request
curl -s "https://invapi.hostkey.com/api_keys.php" -X POST \
--data "action=add" \
--data "params[name]=My Key" \
--data "params[login_notify_method]=email" \
--data "params[login_notify_address][email protected]"
Example of a successful response
{
"result": "OK",
"action": "add",
"data": {
"id": 123,
"name": "My Key",
"token_view": "abc123def456",
"hash": "...",
"server_id": 5,
"active": 1,
"ip": "192.168.1.1/32",
"login_notify_method": "email",
"login_notify_address": "[email protected]",
"customer_id": "cust_123",
"api_key": "abc123def456-..."
}
}
api_keys/add_history¶
Manually adds a history log entry for an API key.
HTTP Method: POST
Parameters:
| Parameter | Required | Type | Description |
|---|---|---|---|
| action | ✅ | string | Method identifier: add_history |
| params[id] | ✅ | integer | The ID of the API key to log history for. |
| params[log_line] | ✅ | string | Description of the historical event. |
Example Request
Example of a successful response
api_keys/count_owned¶
Returns the total number of API keys owned by the authenticated customer.
HTTP Method: GET
Parameters:
| Parameter | Required | Type | Description |
|---|---|---|---|
| action | ✅ | string | The action to perform. Must be 'count_owned'. |
| token | ✅ | string | Authentication token for validating the request. |
Example Request
Example of a successful response
api_keys/delete¶
Deletes an API key.
HTTP Method: POST
Parameters:
| Parameter | Required | Type | Description |
|---|---|---|---|
| token | ✅ | string | The authentication token for the request. |
| params[id] | ✅ | integer | The ID of the API key to delete. |
Example Request
api_keys/edit¶
Updates an existing API key's name, IP restrictions, or server association.
HTTP Method: POST
Parameters:
| Parameter | Required | Type | Description |
|---|---|---|---|
| params[id] | ✅ | integer | The ID of the API key to edit. |
| params[name] | ❌ | string | New name for the API key. |
| params[active] | ❌ | integer | Status of the API key. 1 for active, 0 for inactive. |
| params[ip] | ❌ | string | Updated IP access control list. Supports multiple IPs or CIDR notation separated by spaces. |
| params[login_notify_method] | ✅ | string | Method for login notifications. Allowed values: none, email, webhook. |
| params[login_notify_address] | ❌ | string | The address for notification (valid email if method is email, valid URL if method is webhook). |
Example Request
api_keys/history¶
Retrieves the audit log/history for API keys.
HTTP Method: POST
Parameters:
| Parameter | Required | Type | Description |
|---|---|---|---|
| token | ✅ | string | Authentication token. |
| params[id] | ✅ | integer | The ID of the API key to retrieve history for. |
| params[customer_id] | ✅ | integer | The ID of the customer owning the API key. |
| params[period_from] | ❌ | string | Start date for history filter (default: now). |
| params[period_to] | ❌ | string | End date for history filter (default: now). |
Example Request
Example of a successful response
api_keys/list¶
Returns a list of all API keys owned by the authenticated customer.
HTTP Method: GET
Parameters:
| Parameter | Required | Type | Description |
|---|---|---|---|
| action | ✅ | string | The action to perform. Must be list. |
| token | ✅ | string | Authentication token for user session. |
Example Request
Example of a successful response
{
"result": "OK",
"action": "list",
"data": [
{
"id": 123,
"name": "Key 1",
"active": 1,
"ip": "0.0.0.0/0",
"server_id": 5,
"token_view": "abc...",
"login_notify_method": "email",
"login_notify_address": "[email protected]"
}
]
}
api_keys/list_for_customer¶
Lists API keys filtered by a specific customer ID.
HTTP Method: POST
Parameters:
| Parameter | Required | Type | Description |
|---|---|---|---|
| action | ✅ | string | Method identifier: list_for_customer |
| token | ✅ | string | Authorization token for authentication. |
| params[customer_id] | ✅ | integer | The ID of the customer. Must be a positive integer greater than 0. |
Example Request
Example of a successful response
api_keys/list_for_server¶
Lists API keys associated with a specific server.
HTTP Method: POST
Parameters:
| Parameter | Required | Type | Description |
|---|---|---|---|
| action | ✅ | string | The action to perform: list_for_server |
| token | ✅ | string | Authorization token for authentication. |
| params[server_id] | ✅ | integer | The ID of the server. |
Example Request
Example of a successful response
{
"result": "OK",
"action": "list_for_server",
"data": [
{
"id": 123,
"name": "Server Key",
"active": 1,
"ip": "127.0.0.1",
"server_id": 5,
"token_view": "secret_token",
"login_notify_method": "email",
"login_notify_address": "[email protected]"
}
]
}
api_keys/view¶
Returns detailed information for a specific API key.
HTTP Method: GET
Parameters:
| Parameter | Required | Type | Description |
|---|---|---|---|
| action | ✅ | string | The action to perform. Must be 'view'. |
| token | ✅ | string | Authorization token used to validate the user session. |
| params[id] | ✅ | integer | The ID of the API key to view. |
Example Request