Set Pages Subdomain with API

I am using github actions to set preview deployments on cloudflare. For example, branch cq3dkf will deploy to cq3dkf.my-app.pages.dev.

For reasons out of the scope of this question I am setting a custom CNAME record with a different top-level domain:

cq3dkf.myspecialdomain.com is an alias for cq3dkf.my-app.pages.dev

The custom top level domain is managed by Cloudflare DNS.

I am calling the following API endpoint

curl --request POST \
             --url https://api.cloudflare.com/client/v4/zones/<zone-id>/dns_records \
             --header 'Content-Type: application/json' \
              --header 'Authorization: Bearer <secret>' \
                  --data '{
                    "content": <pages url>,
                    "name": <custom url>,
                    "proxied": true,
                    "type": "CNAME",
                    "ttl": 1
              }'

However, this is not working. I receive a 522 error.

Is there any way that this can be achieved for Pages deployments using the cloudflare API? Am I missing something in configuration?

Based off Add a custom domain to a branch · Cloudflare Pages docs

You would need to add myspecialdomain.com as a custom domain to your pages project. I am not sure if it works at the commit level.

Yeah I was similarly disappointment need to poke around more maybe but it appears they only allow pages domains as subdomains of the main production pages domain . So it is not really possible to deploy many versions of a single pages project. essentially abusing the preview feature.

… It would be a nice feature though.

In theory you can add your third party subdomain with

then with your dns api add the cname to mygitrepo.pages.dev