How to Delete an IP from a Cloudflare IP list in Go?

2 weeks ago 10
ARTICLE AD BOX

How do you delete a single item from an IP list in Cloudflare using Go?

Cloudflare has a feature where it stores lists of IPs, hostnames, or ASNs to be used in formulas. The web UI for this is in account -> Manage Account -> Settings -> Lists

I'm trying to write Go lang code that deletes a single item from one of these lists. The list item has an ID stored in the variable listID.

Here's my attempt at doing this:

item, err = client.Rules.Lists.Items.Delete( context.TODO(), listID, rules.ListItemDeleteParams{ AccountID: cloudflare.F(accountID), Items: cloudflare.F( []rules.ListItemDeleteParamsItem{{ID: cloudflare.F(itemID)}}, ), Items: cloudflare.F( []rules.ListItemDeleteParamsItem{ {ID: cloudflare.F(itemID)}, }, ), }, )

Sadly this gets the following error:

filename.go:222:39: unknown field ID in struct literal of type rules.ListItemDeleteParamsItem

For comparison, here is working code that creates an item in an pre-existing list:

item, err = s.client.Rules.Lists.Items.New( context.TODO(), listID, rules.ListItemNewParams{ AccountID: cloudflare.F(accountID), Body: []rules.ListItemNewParamsBodyUnion{rules.ListItemNewParamsBodyListsListItemIPComment{ IP: cloudflare.F(newKey), Comment: cloudflare.F(newComment), }}, }, )

I suspect that this may be a bug in the Cloudflare SDK because the field Items is of type param.Field[[]ListItemDeleteParamsItem] which does not include a field "ID". Nor does the struct ListItemDeleteParamsItem include a field ID.

Read Entire Article