Skip to content
Start here

Create Preview Health Check

client.healthchecks.previews.create(PreviewCreateParams { zone_id, address, name, 11 more } params, RequestOptionsoptions?): Healthcheck { id, address, check_regions, 15 more }
POST/zones/{zone_id}/healthchecks/preview

Create a new preview health check.

Security
API Token

The preferred authorization scheme for interacting with the Cloudflare API. Create a token.

Example:Authorization: Bearer Sn3lZJTBX6kkg7OdcBUAxOO963GEIyGQqnFTOFYY
API Email + API Key

The previous authorization scheme for interacting with the Cloudflare API, used in conjunction with a Global API key.

Example:X-Auth-Email: user@example.com

The previous authorization scheme for interacting with the Cloudflare API. When possible, use API tokens instead of Global API keys.

Example:X-Auth-Key: 144c9defac04969c7bfad8efaa8ea194
Accepted Permissions (at least one required)
Health Checks Write
ParametersExpand Collapse
params: PreviewCreateParams { zone_id, address, name, 11 more }
zone_id: string

Path param: Identifier

maxLength32
address: string

Body param: The hostname or IP address of the origin server to run health checks on.

name: string

Body param: A short name to identify the health check. Only alphanumeric characters, hyphens and underscores are allowed.

check_regions?: Array<CheckRegion> | null

Body param: A list of regions from which to run health checks. Null means Cloudflare will pick a default region.

One of the following:
"WNAM"
"ENAM"
"WEU"
"EEU"
"NSAM"
"SSAM"
"OC"
"ME"
"NAF"
"SAF"
"IN"
"SEAS"
"NEAS"
"ALL_REGIONS"
consecutive_fails?: number

Body param: The number of consecutive fails required from a health check before changing the health to unhealthy.

consecutive_successes?: number

Body param: The number of consecutive successes required from a health check before changing the health to healthy.

description?: string

Body param: A human-readable description of the health check.

http_config?: HTTPConfiguration { allow_insecure, expected_body, expected_codes, 5 more } | null

Body param: Parameters specific to an HTTP or HTTPS health check.

allow_insecure?: boolean

Do not validate the certificate when the health check uses HTTPS.

expected_body?: string

A case-insensitive sub-string to look for in the response body. If this string is not found, the origin will be marked as unhealthy.

expected_codes?: Array<string> | null

The expected HTTP response codes (e.g. "200") or code ranges (e.g. "2xx" for all codes starting with 2) of the health check.

follow_redirects?: boolean

Follow redirects if the origin returns a 3xx status code.

header?: Record<string, Array<string>> | null

The HTTP request headers to send in the health check. It is recommended you set a Host header by default. The User-Agent header cannot be overridden.

method?: "GET" | "HEAD"

The HTTP method to use for the health check.

One of the following:
"GET"
"HEAD"
path?: string

The endpoint path to health check against.

port?: number

Port number to connect to for the health check. Defaults to 80 if type is HTTP or 443 if type is HTTPS.

interval?: number

Body param: The interval between each health check. Shorter intervals may give quicker notifications if the origin status changes, but will increase load on the origin as we check from multiple locations.

retries?: number

Body param: The number of retries to attempt in case of a timeout before marking the origin as unhealthy. Retries are attempted immediately.

suspended?: boolean

Body param: If suspended, no health checks are sent to the origin.

tcp_config?: TCPConfiguration { method, port } | null

Body param: Parameters specific to TCP health check.

method?: "connection_established"

The TCP connection method to use for the health check.

port?: number

Port number to connect to for the health check. Defaults to 80.

timeout?: number

Body param: The timeout (in seconds) before marking the health check as failed.

type?: string

Body param: The protocol to use for the health check. Currently supported protocols are 'HTTP', 'HTTPS' and 'TCP'.

ReturnsExpand Collapse
Healthcheck { id, address, check_regions, 15 more }
id?: string

Identifier

maxLength32
address?: string

The hostname or IP address of the origin server to run health checks on.

check_regions?: Array<CheckRegion> | null

A list of regions from which to run health checks. Null means Cloudflare will pick a default region.

One of the following:
"WNAM"
"ENAM"
"WEU"
"EEU"
"NSAM"
"SSAM"
"OC"
"ME"
"NAF"
"SAF"
"IN"
"SEAS"
"NEAS"
"ALL_REGIONS"
consecutive_fails?: number

The number of consecutive fails required from a health check before changing the health to unhealthy.

consecutive_successes?: number

The number of consecutive successes required from a health check before changing the health to healthy.

created_on?: string
formatdate-time
description?: string

A human-readable description of the health check.

failure_reason?: string

The current failure reason if status is unhealthy.

http_config?: HTTPConfiguration { allow_insecure, expected_body, expected_codes, 5 more } | null

Parameters specific to an HTTP or HTTPS health check.

allow_insecure?: boolean

Do not validate the certificate when the health check uses HTTPS.

expected_body?: string

A case-insensitive sub-string to look for in the response body. If this string is not found, the origin will be marked as unhealthy.

expected_codes?: Array<string> | null

The expected HTTP response codes (e.g. "200") or code ranges (e.g. "2xx" for all codes starting with 2) of the health check.

follow_redirects?: boolean

Follow redirects if the origin returns a 3xx status code.

header?: Record<string, Array<string>> | null

The HTTP request headers to send in the health check. It is recommended you set a Host header by default. The User-Agent header cannot be overridden.

method?: "GET" | "HEAD"

The HTTP method to use for the health check.

One of the following:
"GET"
"HEAD"
path?: string

The endpoint path to health check against.

port?: number

Port number to connect to for the health check. Defaults to 80 if type is HTTP or 443 if type is HTTPS.

interval?: number

The interval between each health check. Shorter intervals may give quicker notifications if the origin status changes, but will increase load on the origin as we check from multiple locations.

modified_on?: string
formatdate-time
name?: string

A short name to identify the health check. Only alphanumeric characters, hyphens and underscores are allowed.

retries?: number

The number of retries to attempt in case of a timeout before marking the origin as unhealthy. Retries are attempted immediately.

status?: "unknown" | "healthy" | "unhealthy" | "suspended"

The current status of the origin server according to the health check.

One of the following:
"unknown"
"healthy"
"unhealthy"
"suspended"
suspended?: boolean

If suspended, no health checks are sent to the origin.

tcp_config?: TCPConfiguration { method, port } | null

Parameters specific to TCP health check.

method?: "connection_established"

The TCP connection method to use for the health check.

port?: number

Port number to connect to for the health check. Defaults to 80.

timeout?: number

The timeout (in seconds) before marking the health check as failed.

type?: string

The protocol to use for the health check. Currently supported protocols are 'HTTP', 'HTTPS' and 'TCP'.

Create Preview Health Check

import Cloudflare from 'cloudflare';

const client = new Cloudflare({
  apiToken: process.env['CLOUDFLARE_API_TOKEN'], // This is the default and can be omitted
});

const healthcheck = await client.healthchecks.previews.create({
  zone_id: '023e105f4ecef8ad9ca31a8372d0c353',
  address: 'www.example.com',
  name: 'server-1',
});

console.log(healthcheck.id);
{
  "errors": [
    {
      "code": 1000,
      "message": "message",
      "documentation_url": "documentation_url",
      "source": {
        "pointer": "pointer"
      }
    }
  ],
  "messages": [
    {
      "code": 1000,
      "message": "message",
      "documentation_url": "documentation_url",
      "source": {
        "pointer": "pointer"
      }
    }
  ],
  "result": {
    "id": "023e105f4ecef8ad9ca31a8372d0c353",
    "address": "www.example.com",
    "check_regions": [
      "WEU",
      "ENAM"
    ],
    "consecutive_fails": 0,
    "consecutive_successes": 0,
    "created_on": "2014-01-01T05:20:00.12345Z",
    "description": "Health check for www.example.com",
    "failure_reason": "",
    "http_config": {
      "allow_insecure": true,
      "expected_body": "success",
      "expected_codes": [
        "2xx",
        "302"
      ],
      "follow_redirects": true,
      "header": {
        "Host": [
          "example.com"
        ],
        "X-App-ID": [
          "abc123"
        ]
      },
      "method": "GET",
      "path": "/health",
      "port": 0
    },
    "interval": 0,
    "modified_on": "2014-01-01T05:20:00.12345Z",
    "name": "server-1",
    "retries": 0,
    "status": "healthy",
    "suspended": true,
    "tcp_config": {
      "method": "connection_established",
      "port": 0
    },
    "timeout": 0,
    "type": "HTTPS"
  },
  "success": true
}
Returns Examples
{
  "errors": [
    {
      "code": 1000,
      "message": "message",
      "documentation_url": "documentation_url",
      "source": {
        "pointer": "pointer"
      }
    }
  ],
  "messages": [
    {
      "code": 1000,
      "message": "message",
      "documentation_url": "documentation_url",
      "source": {
        "pointer": "pointer"
      }
    }
  ],
  "result": {
    "id": "023e105f4ecef8ad9ca31a8372d0c353",
    "address": "www.example.com",
    "check_regions": [
      "WEU",
      "ENAM"
    ],
    "consecutive_fails": 0,
    "consecutive_successes": 0,
    "created_on": "2014-01-01T05:20:00.12345Z",
    "description": "Health check for www.example.com",
    "failure_reason": "",
    "http_config": {
      "allow_insecure": true,
      "expected_body": "success",
      "expected_codes": [
        "2xx",
        "302"
      ],
      "follow_redirects": true,
      "header": {
        "Host": [
          "example.com"
        ],
        "X-App-ID": [
          "abc123"
        ]
      },
      "method": "GET",
      "path": "/health",
      "port": 0
    },
    "interval": 0,
    "modified_on": "2014-01-01T05:20:00.12345Z",
    "name": "server-1",
    "retries": 0,
    "status": "healthy",
    "suspended": true,
    "tcp_config": {
      "method": "connection_established",
      "port": 0
    },
    "timeout": 0,
    "type": "HTTPS"
  },
  "success": true
}