How to add a custom domain to a Cloudflare Pages project by wrangler cli?

For Workers & Pages, what is the name of the domain?

minimal.site

What is the error message?

[ERROR] Unknown arguments: project, domain, testing1234.minimal.site

What is the issue or error you’re encountering

Cannot add custom domain by wrangler cli

What steps have you taken to resolve the issue?

I would like to add a custom domain to a Cloudflare Pages project by wrangler cli, however, according to the AI’s answer of Cloudflare itself, the command would be npx wrangler pages domain testing1234.minimal.site --project minimal-site-testing1234, but it doesn’t work, and I got the error message says ✘ [ERROR] Unknown arguments: project, domain, testing1234.minimal.site.

Gemini says Cloudflare Pages doesn’t support such approach, but Grok and ChatGPT give me similar approaches like the command above, none of them works.

Does anyone have any experience on this? Thanks in advance!

For Workers & Pages, what is the name of the domain?

minimal.site

What is the error message?

[ERROR] Unknown arguments: project, domain, testing1234.minimal.site

What is the issue or error you’re encountering

Cannot add custom domain by wrangler cli

What are the steps to reproduce the issue?

Trying to add a custom domain to a Pages project by npx wrangler pages domain testing1234.minimal.site --project minimal-site-testing1234 which according to the answer by Cloudflare AI itself, but get error message says ✘ [ERROR] Unknown arguments: project, domain, testing1234.minimal.site.

Does anyone have expression on this? Add a custom domain to a Pages project by wrangler cli but NOT the dashboard.

Thanks in advanced!

AI is dumb, it’s just not a wrangler command at all.
The full list of commands is at:

You could use the API:

Thank you @Chaika! But, I added a custom domain by the Restful API, however, it keeps “Verifying” for over 2 hour already. And I tried to add two other custom domains on the dashboard, both turned to “Active” in 2 minutes.

await fetch(
  `https://api.cloudflare.com/client/v4/accounts/${process.env.CLOUDFLARE_ACCOUNT_ID}/pages/projects/${cloudflareProjectName}/domains`,
  {
    method: "POST",
    headers: {
      "Content-Type": "application/json",
      "X-Auth-Email": process.env.CLOUDFLARE_AUTH_EMAIL,
      "X-Auth-Key": process.env.CLOUDFLARE_API_KEY,
    },
    body: JSON.stringify({ name: customDomain }),
  }
);


testing1234.minimal.site was added by API and keeps “Verifying”, and there’s no other clue from the API document. Did I miss anything?

You need to add the CNAME to your Pages Website. The UI normally does it for you, but since you’re using the API to add the domain, you don’t get all the nice UI magic.

It just needs to be a proxied CNAME. You can look at your other active custom domains as reference, the CNAME Target is your Pages Subdomain, which you can also grab via Get Project Cloudflare API | Pages › Projects › Get Project subdomain field.

Great! Even though manually operation on UI is not an option to my project, inspired by your answer, I add a DNS record according to https://developers.cloudflare.com/api/resources/dns/subresources/records/methods/create, and it works. Thank you so much @Chaika !

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.