Skip to content

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-..."
}
}
Failure response
{
"code": -1,
"message": "invalid argument IP address '...'"
}

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

curl -s "https://invapi.hostkey.com/api_keys.php" -X POST \
--data "action=add_history" \
--data "params[id]=VALUE" \
--data "params[log_line]=VALUE"
Example of a successful response
{
"result": "OK",
"module": "api_keys",
"action": "add_history",
"data": {
"id": 1,
"history": {}
}
}
Failure response
{
"code": -1,
"message": "Action is not recognized"
}

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

curl -s "https://invapi.hostkey.com/api_keys.php" -X GET \
--data "action=count_owned" \
--data "token=HOSTKEY_TOKEN"
Example of a successful response
{
"result": "OK",
"module": "api_keys",
"action": "count_owned",
"data": {
"count": 5
}
}
Failure response
{
"code": -1,
"message": "Action is not recognized"
}

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

curl -s "https://invapi.hostkey.com/api_keys.php" -X POST \
--data "token=HOSTKEY_TOKEN" \
--data "params[id]=VALUE"
Example of a successful response
{
"id": 123
}
Failure response
{
"code": -1,
"message": "invalid argument id '0'"
}

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

curl -s "https://invapi.hostkey.com/api_keys.php" -X POST \
--data "params[id]=123" \
--data "params[login_notify_method]=email"
Example of a successful response
{
"id": 123
}
Failure response
{
"code": -1,
"message": "invalid argument id '0'"
}

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

curl -s "https://invapi.hostkey.com/api_keys.php" -X POST \
--data "token=HOSTKEY_TOKEN" \
--data "params[id]=123" \
--data "params[customer_id]=456"
Example of a successful response
{
"result": "OK",
"action": "history",
"data": [
{
"id": 1,
"date": "2024-01-15T12:00:00Z",
"description": "Changed api_key 123. server_id from '0' to '5'",
"message": "...",
"type": "edit",
"login": "admin"
}
]
}
Failure response
{
"code": -1,
"message": "Action is not recognized"
}

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

curl -s "https://invapi.hostkey.com/api_keys.php" -X GET \
--data "action=list" \
--data "token=HOSTKEY_TOKEN"
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]"
}
]
}
Failure response
{
"code": -1,
"message": "Action is not recognized"
}

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

curl -s "https://invapi.hostkey.com/api_keys.php" -X POST \
--data "action=list_for_customer" \
--data "token=HOSTKEY_TOKEN" \
--data "params[customer_id]=VALUE"
Example of a successful response
{
"result": "OK",
"action": "list_for_customer",
"data": [
{
"id": 123,
"name": "Customer Key",
"server_id": null
}
]
}
Failure response
{
"code": -1,
"message": "Action is not recognized"
}

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

curl -s "https://invapi.hostkey.com/api_keys.php" -X POST \
--data "action=list_for_server" \
--data "token=HOSTKEY_TOKEN" \
--data "params[server_id]=5"
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]"
}
]
}
Failure response
{
"code": -1,
"message": "Action is not recognized"
}

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

curl -s "https://invapi.hostkey.com/api_keys.php" -X GET \
--data "action=view" \
--data "token=HOSTKEY_TOKEN" \
--data "params[id]=123"
Example of a successful response
{
"result": "OK",
"action": "view",
"data": {
"id": 123,
"name": "Detailed Key",
"token_view": "abc123def456",
"server_id": 5,
"ip": "192.168.1.1/32",
"created_at": "2024-01-15T10:30:00Z"
}
}
Failure response
{
"code": -1,
"message": "Action required"
}
question_mark
Is there anything I can help you with?
question_mark
AI Assistant ×