Ping examples

Here you can find examples on how to ping a Heartbeat check.

Most examples use GET as the request method, but Heartbeat checks also accept POST requests. Your check won’t record PUT or DELETE requests as pings, and the endpoint will return an error.

Shell

Adding a ping to a shell script only requires a single line.

This is an example using curl. We recommend using the -m and --retry options to specify timeout and retries to reduce the risk of false alerts or blocking the script.

run_backup.sh
curl -m 5 --retry 3 https://ping.checklyhq.com/f0e0b1d3-665d-49d0-8bf0-3e6504c3d372
run_backup.sh
curl -X "POST" -m 5 --retry 3 https://ping.checklyhq.com/f0e0b1d3-665d-49d0-8bf0-3e6504c3d372

This is a similar example with wget. Use the options -t for retries and -T for timeout.

run_backup.sh
wget -T 5 -t 3 https://ping.checklyhq.com/87c05896-3b7d-49ae-83ff-5e81323a54c4

You can use curl for Render cron jobs and the Heroku Scheduler:

run_backup.sh && curl -m 5 --retry 3 https://ping.checklyhq.com/f0e0b1d3-665d-49d0-8bf0-3e6504c3d372

Kubernetes CronJob

Here is an example of how to add the curl command to a Kubernetes CronJob.

my-scheduled-job.yaml
apiVersion: batch/v1
kind: CronJob
metadata:
  name: nightly
spec:
  schedule: "0 2 * * *"
  jobTemplate:
    spec:
      template:
        spec:
          containers:
          - name: curl
            image: docker.io/curlimages/curl:latest
            imagePullPolicy: IfNotPresent
            command:
            - sh
            - -c
            args:
            - 'curl -m 5 --retry 3 https://ping.checklyhq.com/f0e0b1d3-665d-49d0-8bf0-3e6504c3d372;'
          restartPolicy: OnFailure

Node.js

You can use any HTTP request library (https, axios, etc.) to ping your Heartbeat check.

This is an example with the built-in https.get package:

my-scheduled-job.ts
import https from "https";

// Sample URL
const url = "https://ping.checklyhq.com/87c05896-3b7d-49ae-83ff-5e81323a54c4";

const options = {
  timeout: 5000,
};

https.get(url, options, (res) => {
  console.log("statusCode:", res.statusCode);

  res.on('data', (data) => {
    console.log("responseBody:", data);
  });
});
my-scheduled-job.js
const https = require("https");

// Sample URL
const url = "https://ping.checklyhq.com/87c05896-3b7d-49ae-83ff-5e81323a54c4";

const options = {
  timeout: 5000,
};

https.get(url, options, (res) => {
  console.log("statusCode:", res.statusCode);

  res.on('data', (data) => {
    console.log("responseBody:", data);
  });
});

You can also use Axios:

my-scheduled-job.ts
import axios from 'axios'

axios.get('https://ping.checklyhq.com/87c05896-3b7d-49ae-83ff-5e81323a54c4')
  .then(resp => {
      console.log(resp.data);
  })
my-scheduled-job.js
const axios = require('axios');

axios.get('https://ping.checklyhq.com/87c05896-3b7d-49ae-83ff-5e81323a54c4')
  .then(resp => {
      console.log(resp.data);
  })

Vercel cron jobs

You can monitor your Vercel cron jobs with Heartbeat checks. At the end of your cron job, make an HTTP GET or POST request to your ping URL. For example, using fetch():

app/api/my-cron-job/route.js
export async function GET(req, res) {
  // Your job tasks here ...

  // Ping URL
  const URL = 'https://ping.checklyhq.com/c3f5f5bb-6e46-431a-b7b1-35105450cddc';

  // GET request to the Heartbeat
  try {
    const response = await fetch(URL);
    console.log(`Checkly heartbeat ping status ${response.status}`);
  } catch (error) {
    console.log(`Checkly heartbeat ping failed: ${error}`)
  }  
}
pages/api/my-cron-job.js
export default function handler(req, res) {
  // Your job tasks here ...

  // Ping URL
  const URL = 'https://ping.checklyhq.com/c3f5f5bb-6e46-431a-b7b1-35105450cddc';

  // GET request to the Heartbeat
  try {
    const response = await fetch(URL);
    console.log(`Checkly heartbeat ping status ${response.status}`);
  } catch (error) {
    console.log(`Checkly heartbeat ping failed: ${error}`)
  }
}
api/my-cron-job.js
export function GET() {
  // Your job tasks here ...

  // Ping URL
  const URL = 'https://ping.checklyhq.com/c3f5f5bb-6e46-431a-b7b1-35105450cddc';

  // GET request to the Heartbeat
  try {
    const response = await fetch(URL);
    console.log(`Checkly heartbeat ping status ${response.status}`);
  } catch (error) {
    console.log(`Checkly heartbeat ping failed: ${error}`)
  }
}

Python

This is an example using the Python requests library with a timeout of 5 seconds:

my_scheduled_job.py
import requests

# Heartbeat URL
url = "https://ping.checklyhq.com/c3f5f5bb-6e46-431a-b7b1-35105450cddc"

# A GET request to the Heartbeat
response = requests.get(url, timeout=5)

PowerShell

Use PowerShell and Windows Task Scheduler to automate tasks on Windows systems. Adding a ping to a PowerShell script only requires a single line.

We recommend using the timeout and retry options to reduce the risk of false alerts or blocking the script. See the Invoke-RestMethod documentation for more information.

Invoke-RestMethod -Uri https://ping.checklyhq.com/c3f5f5bb-6e46-431a-b7b1-35105450cddc -TimeoutSec 5 -MaximumRetryCount 3 -RetryIntervalSec 5

Last updated on May 1, 2025. You can contribute to this documentation by editing this page on Github