Skip to content

Conversation

@jose-ledesma
Copy link
Collaborator

Add custom hostnames usage
I'm still researching if we can also report the current quota

cloudflare.go Outdated
Comment on lines 995 to 1001
// Use the REST API directly since the SDK might not have custom hostnames support
// We only need the count, so we request 1 item per page
req, err := http.NewRequestWithContext(ctx, http.MethodGet,
fmt.Sprintf("https://api.cloudflare.com/client/v4/zones/%s/custom_hostnames?per_page=1", zoneID), nil)
if err != nil {
return 0, fmt.Errorf("failed to create request: %w", err)
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is possible to use the SDK. It's just kind of hidden:

rep, err := cfclient.CustomHostnames.List(ctx, cfcustomhostnames.CustomHostnameListParams{
		ZoneID:  cf.F(zone.ID),
		PerPage: cf.F(1.0),
})
rep.ResultInfo.JSON.ExtraFields["total_count"].Raw()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants