Skip to main content

Overview

Cloudflare Pages is a JAMstack platform for frontend developers to collaborate and deploy websites. Use the Pages API to manage projects, deployments, and domains programmatically.

Initialize the client

import Cloudflare from 'cloudflare';

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

Projects

Manage Pages projects.

Create a project

Create a new Pages project.
const project = await client.pages.projects.create({
  account_id: '023e105f4ecef8ad9ca31a8372d0c353',
  name: 'my-pages-app',
  production_branch: 'main',
});
account_id
string
required
Account identifier
name
string
required
Project name
production_branch
string
required
The Git branch that will be used for production deployments
build_config
object
Build configuration settings
deployment_configs
object
Deployment configuration for production and preview environments
id
string
Project identifier
name
string
Project name
subdomain
string
The project’s *.pages.dev subdomain
created_on
string
When the project was created

List projects

Fetch all projects in an account.
// Automatically fetches more pages as needed
for await (const project of client.pages.projects.list({
  account_id: '023e105f4ecef8ad9ca31a8372d0c353',
})) {
  console.log(project);
}
account_id
string
required
Account identifier

Get a project

Fetch a specific project by name.
const project = await client.pages.projects.get(
  'this-is-my-project-01',
  { account_id: '023e105f4ecef8ad9ca31a8372d0c353' }
);

Update a project

Set new attributes for an existing project, including environment variables.
const response = await client.pages.projects.edit(
  'this-is-my-project-01',
  { 
    account_id: '023e105f4ecef8ad9ca31a8372d0c353',
    production_branch: 'main',
  }
);
production_branch
string
The Git branch for production deployments
deployment_configs
object
Environment-specific deployment configuration

Delete a project

Delete a project by name.
const project = await client.pages.projects.delete(
  'this-is-my-project-01',
  { account_id: '023e105f4ecef8ad9ca31a8372d0c353' }
);

Purge build cache

Purge the build cache for a project.
const response = await client.pages.projects.purgeBuildCache(
  'this-is-my-project-01',
  { account_id: '023e105f4ecef8ad9ca31a8372d0c353' }
);

Deployments

Manage Pages deployments for a project.
const deployments = client.pages.projects.deployments;
Available methods:

Create deployment

Create a new deployment.
const deployment = await client.pages.projects.deployments.create(
  'my-project',
  params
);

List deployments

List all deployments for a project.
const deployments = await client.pages.projects.deployments.list(
  'my-project',
  params
);

Get deployment

Get details of a specific deployment.
const deployment = await client.pages.projects.deployments.get(
  'my-project',
  deploymentId,
  params
);

Delete deployment

Delete a deployment.
await client.pages.projects.deployments.delete(
  'my-project',
  deploymentId,
  params
);

Retry deployment

Retry a failed deployment.
const deployment = await client.pages.projects.deployments.retry(
  'my-project',
  deploymentId,
  params
);

Rollback deployment

Rollback to a previous deployment.
const deployment = await client.pages.projects.deployments.rollback(
  'my-project',
  deploymentId,
  params
);

Domains

Manage custom domains for a project.
const domains = client.pages.projects.domains;
Available methods:
  • create() - Add a custom domain
  • list() - List all custom domains
  • get() - Get domain details
  • delete() - Remove a custom domain

Types

Project

id
string
Project identifier
name
string
Project name
subdomain
string
The *.pages.dev subdomain
production_branch
string
Git branch for production
created_on
string
Creation timestamp

Deployment

id
string
Deployment identifier
url
string
Deployment URL
environment
string
Deployment environment (production or preview)
created_on
string
When the deployment was created

Stage

Deployment stage information.
name
string
Stage name
status
string
Stage status

Build docs developers (and LLMs) love