Code Examples

Ready-to-use code snippets for the Pinguzo API in PHP, Python, JavaScript, and curl.

Replace YOUR_API_KEY In all examples below, replace YOUR_API_KEY with your actual API key from the API page in your dashboard.

PHP (cURL)

List all servers

// List all servers
$ch = curl_init('https://cp.pinguzo.com/api/v1/rest.php?resource=servers');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
    'Authorization: Bearer YOUR_API_KEY',
]);
$response = curl_exec($ch);
$data = json_decode($response, true);
print_r($data);

Create a monitor

// Create a new HTTPS monitor
$ch = curl_init('https://cp.pinguzo.com/api/v1/rest.php?resource=monitors');
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
    'Authorization: Bearer YOUR_API_KEY',
    'Content-Type: application/json',
]);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode([
    'name' => 'My Website',
    'url' => 'https://example.com',
    'type' => 'https',
    'check_interval' => 60,
]));
$response = curl_exec($ch);
$data = json_decode($response, true);
echo "Monitor ID: " . $data['data']['monitor']['id'];

Python (requests)

List all servers

import requests

response = requests.get(
    'https://cp.pinguzo.com/api/v1/rest.php',
    params={'resource': 'servers'},
    headers={'Authorization': 'Bearer YOUR_API_KEY'}
)
data = response.json()
for server in data['data']['servers']:
    print(f"#{server['id']} {server['name']} — {server['online_status']}")

Create a monitor

import requests

response = requests.post(
    'https://cp.pinguzo.com/api/v1/rest.php',
    params={'resource': 'monitors'},
    headers={
        'Authorization': 'Bearer YOUR_API_KEY',
        'Content-Type': 'application/json'
    },
    json={
        'name': 'My Website',
        'url': 'https://example.com',
        'type': 'https',
        'check_interval': 60
    }
)
data = response.json()
print(f"Monitor ID: {data['data']['monitor']['id']}")

Get incidents from the last 24 hours

import requests

response = requests.get(
    'https://cp.pinguzo.com/api/v1/rest.php',
    params={'resource': 'incidents', 'last_hours': 24},
    headers={'Authorization': 'Bearer YOUR_API_KEY'}
)
data = response.json()
for inc in data['data']['incidents']:
    print(f"[{inc['status']}] {inc['entity_type']} #{inc['entity_id']}: {inc['message']}")

JavaScript (Node.js)

List all servers

const response = await fetch(
  'https://cp.pinguzo.com/api/v1/rest.php?resource=servers',
  { headers: { 'Authorization': 'Bearer YOUR_API_KEY' } }
);
const data = await response.json();
console.log(data);

Create a monitor

const response = await fetch(
  'https://cp.pinguzo.com/api/v1/rest.php?resource=monitors',
  {
    method: 'POST',
    headers: {
      'Authorization': 'Bearer YOUR_API_KEY',
      'Content-Type': 'application/json'
    },
    body: JSON.stringify({
      name: 'My Website',
      url: 'https://example.com',
      type: 'https',
      check_interval: 60
    })
  }
);
const data = await response.json();
console.log(`Monitor ID: ${data.data.monitor.id}`);

JavaScript (Browser)

In browser environments where you can't set the Authorization header (e.g. simple CORS requests), use the ?api_key= query parameter:

const response = await fetch(
  'https://cp.pinguzo.com/api/v1/rest.php?resource=servers&api_key=YOUR_API_KEY'
);
const data = await response.json();
console.log(data);
Security note Avoid exposing your API key in client-side browser code in production. The ?api_key= method is intended for quick testing only. Always proxy API calls through your own backend in production applications.

curl (Command Line)

List servers

curl -H "Authorization: Bearer YOUR_API_KEY" \
  https://cp.pinguzo.com/api/v1/rest.php?resource=servers

Create server

curl -X POST \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"name":"web-02"}' \
  https://cp.pinguzo.com/api/v1/rest.php?resource=servers

Open incidents for a monitor

curl -H "Authorization: Bearer YOUR_API_KEY" \
  "https://cp.pinguzo.com/api/v1/rest.php?resource=incidents&monitor_id=5&status=open"

Delete a monitor

curl -X DELETE \
  -H "Authorization: Bearer YOUR_API_KEY" \
  "https://cp.pinguzo.com/api/v1/rest.php?resource=monitors&id=10"

Next Steps