Skip to main content

Overview

Magic Transit provides network-level DDoS protection and traffic acceleration for your entire network. Use the Magic Transit API to manage routes, tunnels, sites, and network monitoring.

Initialize the client

import Cloudflare from 'cloudflare';

const client = new Cloudflare({
  apiToken: 'your-api-token',
});

Resources

The Magic Transit API provides the following sub-resources:

Routes

Manage Magic static routes for traffic routing.

Create a route

Creates a new Magic static route.
const route = await client.magicTransit.routes.create({
  account_id: '023e105f4ecef8ad9ca31a8372d0c353',
  nexthop: '203.0.113.1',
  prefix: '192.0.2.0/24',
  priority: 0,
});
account_id
string
required
Account identifier
nexthop
string
required
The next hop IP address for this route
prefix
string
required
IP prefix in CIDR notation
priority
number
required
Route priority (lower values have higher priority)

Update a route

Update a specific Magic static route.
const route = await client.magicTransit.routes.update(
  '023e105f4ecef8ad9ca31a8372d0c353',
  {
    account_id: '023e105f4ecef8ad9ca31a8372d0c353',
    nexthop: '203.0.113.1',
    prefix: '192.0.2.0/24',
    priority: 0,
  }
);

List routes

List all Magic static routes.
const routes = await client.magicTransit.routes.list({
  account_id: '023e105f4ecef8ad9ca31a8372d0c353',
});

Delete a route

Disable and remove a specific Magic static route.
const route = await client.magicTransit.routes.delete(
  '023e105f4ecef8ad9ca31a8372d0c353',
  { account_id: '023e105f4ecef8ad9ca31a8372d0c353' }
);

GRE tunnels

Manage Generic Routing Encapsulation (GRE) tunnels for Magic Transit.
const greTunnels = client.magicTransit.greTunnels;
Available methods:
  • create() - Create a new GRE tunnel
  • update() - Update an existing GRE tunnel
  • list() - List all GRE tunnels
  • delete() - Delete a GRE tunnel
  • get() - Get details of a specific GRE tunnel
  • bulkUpdate() - Update multiple GRE tunnels at once

IPsec tunnels

Manage IPsec tunnels for Magic Transit.
const ipsecTunnels = client.magicTransit.ipsecTunnels;
Available methods:
  • create() - Create a new IPsec tunnel
  • update() - Update an existing IPsec tunnel
  • list() - List all IPsec tunnels
  • delete() - Delete an IPsec tunnel
  • get() - Get details of a specific IPsec tunnel
  • pskGenerate() - Generate a pre-shared key for IPsec tunnel

Sites

Manage Magic Transit sites with LAN/WAN configuration.
const sites = client.magicTransit.sites;
Available methods:
  • create() - Create a new site
  • update() - Update an existing site
  • list() - List all sites
  • delete() - Delete a site
  • get() - Get details of a specific site

Connectors

Manage Magic Connector instances for site connectivity.
const connectors = client.magicTransit.connectors;

PCAPs

Capture and analyze network packet data.
const pcaps = client.magicTransit.pcaps;
Available methods:
  • create() - Start a new packet capture
  • list() - List all packet captures
  • get() - Get details of a specific capture
  • stop() - Stop an ongoing packet capture

CF Interconnects

Manage Cloudflare Interconnects for Magic Transit.
const cfInterconnects = client.magicTransit.cfInterconnects;

Apps

Manage Magic Transit application configurations.
const apps = client.magicTransit.apps;

Types

HealthCheck

Configuration for tunnel health checks.
enabled
boolean
Determines whether to run health checks for a tunnel
rate
'low' | 'mid' | 'high'
How frequently the health check runs (default: ‘mid’)
type
'reply' | 'request'
The type of health check to run (default: ‘reply’)
target
string | object
The destination address for request-type health checks

Build docs developers (and LLMs) love