Skip to content

api_keys.php

API key management module: creation, editing, deletion, history viewing, and retrieving key lists for customers and servers.

API Methods

Method Action Description
add create API key Creates a new API key for a customer or a specific server. Requires the customer to have active servers.
delete delete API key Removes the specified API key from the system.
edit edit API key Modifies parameters of an existing API key (name, IP, status, expiration).
history get API key history Returns the history of actions performed on API keys (creation, modification, deletion).
list get API key list Returns a list of all API keys for the current customer.
list_for_server get keys for server Returns a list of API keys bound to a specific server.
view view API key Returns detailed information about a single API key.

api_keys/add

Creates a new API key for a customer or a specific server. Requires the customer to have active servers.

HTTP Method: POST

Parameters:

Parameter Required Type Description
action string Method identifier: add
token string Authorization token
params[name] string Name of the API key
params[server_id] int ID of the server for which the key is created (if not specified, the key applies to all servers)
params[ip] string IP address from which key usage is allowed
params[active] int Key activity status (1 - active, 0 - inactive)
params[login_notify_method] string Login notification method (none, email, webhook)
params[login_notify_address] string Notification address (email or URL depending on the method)

Example Request

curl -s "https://api.hostkey.com/api_keys.php" -X POST \
--data "action=add" \
--data "token=HOSTKEY_TOKEN" \
--data "params[name]=Production Key" \
--data "params[server_id]=10" \
--data "params[ip]=192.168.1.1" \
--data "params[active]=1" \
--data "params[login_notify_method]=email" \
--data "params[login_notify_address][email protected]"
Example of a successful response
{
"result": "OK",
"module": "api_keys",
"action": "add",
"data": {
  "id": 12345,
  "name": "Production Key",
  "token_view": "sk_live_abc123...",
  "server_id": 10,
  "ip": "192.168.1.1",
  "active": 1,
  "login_notify_method": "email",
  "login_notify_address": "[email protected]",
  "customer_id": "cust_123",
  "api_key": "a1b2c3d4e5f6g7h8-i9j0k1l2m3n4o5p6",
  "created_at": "2024-01-15T10:30:00Z"
}
}
Failure response
{
"code": -1,
"message": "invalid argument name",
"details": {
  "reason": "Parameter name is empty or invalid"
}
}

api_keys/edit

Modifies parameters of an existing API key (name, IP, status, expiration).

HTTP Method: POST

Parameters:

Parameter Required Type Description
action string Method identifier: edit
token string Authorization token
params[id] int ID of the API key to edit
params[name] string New name of the API key
params[active] int New activity status (1/0). Default is 1
params[ip] string New IP address for access restriction (or empty string to remove restriction)
params[login_notify_method] string Login notification method (none, email, webhook)
params[login_notify_address] string Notification address (email or URL depending on the method)

Example Request

curl -s "https://api.hostkey.com/api_keys.php" -X POST \
--data "action=edit" \
--data "token=HOSTKEY_TOKEN" \
--data "params[id]=VALUE" \
--data "params[name]=VALUE"
Example of a successful response
{
"result": "OK",
"module": "api_keys",
"action": "edit",
"data": {
  "id": 12345
}
}
Failure response
{
"code": -1,
"message": "invalid argument id",
"description": "Invalid key ID"
}

api_keys/delete

Removes the specified API key from the system.

HTTP Method: POST

Parameters:

Parameter Required Type Description
action string Method identifier: delete
token string Authorization token
params[id] int ID of the API key to delete

Example Request

curl -s "https://api.hostkey.com/api_keys.php" -X POST \
--data "action=delete" \
--data "token=HOSTKEY_TOKEN" \
--data "params[id]=VALUE"
Example of a successful response
{
"result": "OK",
"module": "api_keys",
"action": "delete",
"data": {
  "id": 12345
}
}
Failure response
{
"code": -1,
"message": "invalid argument id",
"description": "Invalid ID (less than 1 or not a number)",
"details": {
  "id": "invalid_value"
}
}

api_keys/history

Returns the history of actions performed on API keys (creation, modification, deletion).

HTTP Method: POST

Parameters:

Parameter Required Type Description
action string Method identifier: history
token string Authorization token
params[limit] int (inside params[]) Number of records to return
params[offset] int (inside params[]) Offset for pagination
params[key_id] int (inside params[]) Filter by key ID

Example Request

curl -s "https://api.hostkey.com/api_keys.php" -X POST \
--data "action=history" \
--data "token=HOSTKEY_TOKEN" \
--data "params[limit]=10" \
--data "params[offset]=0"
Example of a successful response
{
"result": "OK",
"module": "api_keys",
"action": "history",
"data": [
  {
    "id": 1,
    "key_id": 12345,
    "action": "created",
    "user": "admin",
    "timestamp": "2024-01-15T10:30:00Z",
    "details": "Key created for server 10"
  },
  {
    "id": 2,
    "key_id": 12345,
    "action": "edited",
    "user": "admin",
    "timestamp": "2024-01-16T14:20:00Z",
    "details": "IP changed to 10.0.0.5"
  }
]
}
Failure response
{
"code": -1,
"message": "Invalid parameters",
"details": {}
}

api_keys/list

Returns a list of all API keys for the current customer.

HTTP Method: POST

Parameters:

Parameter Required Type Description
action string Method identifier: list
token string Authorization token

Example Request

curl -s "https://api.hostkey.com/api_keys.php" -X POST \
--data "action=list" \
--data "token=HOSTKEY_TOKEN"
Example of a successful response
{
"result": "OK",
"module": "api_keys",
"action": "list",
"data": [
  {
    "id": 12345,
    "name": "Production Key",
    "token_view": "sk_live_abc123...",
    "server_id": 10,
    "ip": "192.168.1.1",
    "active": 1,
    "login_notify_method": "email",
    "login_notify_address": "[email protected]"
  },
  {
    "id": 12346,
    "name": "Staging Key",
    "token_view": "sk_live_def456...",
    "server_id": null,
    "ip": null,
    "active": 0,
    "login_notify_method": null,
    "login_notify_address": null
  }
]
}
Failure response
{
"code": -1,
"message": "Action required",
"details": {}
}

api_keys/list_for_server

Returns a list of API keys bound to a specific server.

HTTP Method: POST

Parameters:

Parameter Required Type Description
action string Method identifier: list_for_server
token string Authorization token
params[server_id] int Server ID for filtering keys

Example Request

curl -s "https://api.hostkey.com/api_keys.php" -X POST \
--data "action=list_for_server" \
--data "token=HOSTKEY_TOKEN" \
--data "params[server_id]=VALUE"
Example of a successful response
{
"result": "OK",
"module": "api_keys",
"action": "list_for_server",
"data": [
  {
    "id": 12345,
    "name": "Server 10 Key",
    "active": 1,
    "ip": "192.168.1.1",
    "server_id": 10,
    "token_view": "sk_live_abc123...",
    "login_notify_method": "email",
    "login_notify_address": "[email protected]"
  }
]
}
Failure response
{
"code": -1,
"message": "invalid argument server_id",
"details": {
  "reason": "server_id must be greater than 0"
}
}

api_keys/view

Returns detailed information about a single API key.

HTTP Method: POST

Parameters:

Parameter Required Type Description
action string Method identifier: view
token string Authorization token
params[id] int ID of the API key to view

Example Request

curl -s "https://api.hostkey.com/api_keys.php" -X POST \
--data "action=view" \
--data "token=HOSTKEY_TOKEN" \
--data "params[id]=VALUE"
Example of a successful response
{
"result": "OK",
"module": "api_keys",
"action": "view",
"data": {
  "id": 12345,
  "name": "Production Key",
  "token_view": "sk_live_abc123...",
  "server_id": 10,
  "ip": "192.168.1.1",
  "expire": 1735689600,
  "active": 1,
  "created_at": "2024-01-15T10:30:00Z",
  "updated_at": "2024-01-16T14:20:00Z"
}
}
Failure response
{
"code": -1,
"message": "Action required",
"description": "Parameter action is missing"
}

question_mark
Is there anything I can help you with?
question_mark
AI Assistant ×