Setting custom domain to cloudflare pages project via API

Hello,
I’d like to set up a custom domain (alias) for my Cloudflare Pages project via API. As stated in docs, it’s not enough to just create a CNAME record (I’ve tried it and it results in 522 error being shown). Instead you should also go through the “Custom domains” flow on the Cloudflare pages project page. After I’ve done this, it started working fine.

Unfortunately I need to set the custom domain for a cloudflare pages project fully via API, but I’m not sure how am I able to do that, since apparently only using the DNS API is not enough?

Can someone please help me? Is there some hack/workaround I could do to make this work when setting only via API?

Thanks a lot, have a nice day.

Sorry that you found out the difference between a CNAME and a Custom Domain that way.

If you want to assign a Custom Domain with the API then you should be able to use this