Where to find API endpoints to create internal/external hostnames?

I have a Cloudflare tunnel setup to my home network for some personal self-hosted services. While learning my way around the dashboard, I decided to try to use the API to help make creating DNS entries faster. In my investigation, I learned how to manage DNS entries, but I could not figure out how to create "Public Hostname" entries via the API within my tunnel, and made the following observations: 1) If I create a hostname entry via the dashboard GUI, it'll automatically create a DNS CNAME entry, but the converse is not true 2) I can create DNS entries with a POST to https://api.cloudflare.com/api/v4/zones/{{CF-Zone-ID}}/dns_records, but I cannot figure out how do #1 via the API (create a hostname entry) 3) When viewing the network tab of the browser developer tools to try to reverse engineer it, the only thing I'm finding is the same POST above, though it uses dash.cloudflare.com/api, which I'm assuming is a different API for the dashboard vs. the raw API, which makes me think some functions are only available via the dashboard. The user-facing API URL is https://api.cloudflare.com/client/v4 I'd appreciate any guidance on how to do this (add a new tunnel public hostname/DNS mapping) programmatically, thanks!
No description
No description
C
Chaika40d ago
The nice interface today that exists for Cloudflare tunnels came a while after they were launched. It was first just local config (in yaml) and local tunnel management. So the endpoints aren't really nice. What the dash does is store the entire tunnel config in json and load it/save it back on each modification. You're looking for the configurations endpoint call. Here's the endpoint: https://developers.cloudflare.com/api/operations/cloudflare-tunnel-configuration-put-configuration
Cloudflare API Documentation
Interact with Cloudflare's products and services via the Cloudflare API
R
radakul40d ago
That is exactly what I was looking for, thank you so much for pointing me in the right direction. I wouldn't have ended up there organically, I don't think.
C
Chaika40d ago
Only your account can CNAME to tunnels belonging to your account. Once you CNAME to the tunnel, requests go down the tunnel, and then are processed by the local config, specifically the ingress part, to the right local service yea it's kind of messy lol, it PUTs the entire config back on each change Your pattern would have to be like: Post DNS Record CNAME -> Tunnel GET Tunnel Config ..Modify Tunnel config/add public hostname(s)/etc PUT back entire tunnel config, and on this action the tunnel will be automagically notified the config updated and know where to route the now incoming requests
R
radakul40d ago
Well, your explanation is very concise and well-explained, I really have no further questions right now. I'll play around with it and I'm sure it'll fit the bill. Thanks so much for a quick response! I posted on Reddit in /r/cloudflare but never got a single response 😦 This especially is super helpful - I'm not a programmer/developer, just like to tinker, and trying to figure out the flow of API's always trips me up since it's multiple calls that formulate a single flow. Thank you again. Is there a way to mark this solved? I see it just changed, thanks
C
Chaika40d ago
Under Edit Tags -> Solved, I did it for you
R
radakul40d ago
You're phenomenal
C
Chaika40d ago
yea, one nice thing about CF is the dashboard uses all the same APIs you use, so you can kind of easily reverse engineer it, makes up for the meh API Docs
R
radakul40d ago
Yup. I'm a network engineer by trade, so always comfortable looking in the developer tools network tab 🙂 feels like home.
C
Chaika40d ago
When you add a Public Hostname you should be able to see the DNS Record add and the configuration put, those are the two important ones
R
radakul40d ago
Noted, ty. You've just unblocked me, so I can get back to the fun stuff 🙂
C
Chaika40d ago
And to answer your third original question, the dash.cloudflare.com/api and api.cloudflare.com are generally the same API with the same endpoints but just different hostnames/initial path. The dash is Bot protected so you don't want to use it headless. Pretty much all the same endpoints are available on both. Some are undocumented in api.cf meaning they may change in the future but still work. The only ones that I can think of which are protected are a few like Registrar API (Enterprise only), Email Verification API (no bots) which exist in dash but not api.cf
Want results from more Discord servers?
Add your server
More Posts
third party github option for cloudflare pagesIs there a way I could have cf pages pull from forgejo?After clearing all caches, the svg images of 3 URLs cannot be opened.After clicking to clear all caches on cloudflare, the svg images of 3 URLs cannot be opened. Does anHelp setting up worker for discord botHello, I wanted to host a discord bot that embeds tiktok links in my friends server. I found this reRedirect not working when transforming via Workers onError eventHi folks, I have a worker that resizes images; everything works well except when the animated GIF ican i run --force here ?can i run --force here ?Workers KV get throws TypeError: Cannot read properties of undefined (reading 'get')My wrangler.toml file looks like this: ``` kv_namespaces = [ { binding = "BH_API_KEYS", id = "xxxPaid for the Services.Paid for support, my site is under DDOs attacks I would like a dev to help me resolve this issue. passh over cloudlare tunnel with iPhoneHi, I successfully got an ssh connection through a cloudflare tunnel on windows but it worked becausView bandwidth usage by pages website?Is there any way to see how much bandwidth a pages project has used?Exporting WAF Logs on Business planIs it possible to use the API to export the WAF logs and then i can parse and import it to an externWorker Loop and error because or External rendering serviceI face an issue... I use a worker that loads a page on an external site but I see a strange Loop comContacting by chat impossible or nightmare?The support system is not showing any option accessing to the live chat.... Can someone help me or gFeature Request: Route Zone LinkA small dashboard feature that would make things a bit more seamless would be adding a link to the rpricing of web3?Hi guys, I am trying to find the pricing of the ethereum web3 gateway. Since it's a usage-based billWebsite domain stuck at verifying but subdomains workingI have a Pages project and I'm trying to add a domain to it. So the site has been added under WebsitStreaming video via tunnelsI read the blogpost on the ToS changes and I'm having trouble discerning whether or not hosting someCan I use CF CDN to cache my images in CF imagesCan I use CF CDN to cache my images in CF images?Can we use `service` bindings withCan we use `service` bindings with `getRequestContext()`? I am trying to add it in `wrangler.toml` b"[Error: Network connection lost.]"I have a KV - which I will be used for keeping track of domains, I have assigned it to the Worker, aPages Inactive (ErroHi everyone, I have a little problem, when adding a custom domain to my page it shows Inactive (Erro