# User ## User Details `client.User.Get(ctx) (*UserGetResponse, error)` **get** `/user` User Details ### Returns - `type UserGetResponse struct{…}` - `ID string` Identifier of the user. - `Betas []string` Lists the betas that the user is participating in. - `Country string` The country in which the user lives. - `FirstName string` User's first name - `HasBusinessZones bool` Indicates whether user has any business zones - `HasEnterpriseZones bool` Indicates whether user has any enterprise zones - `HasProZones bool` Indicates whether user has any pro zones - `LastName string` User's last name - `Organizations []Organization` - `ID string` Identifier - `Name string` Organization name. - `Permissions []Permission` Access permissions for this User. - `Roles []string` List of roles that a user has within an organization. - `Status Status` Whether the user is a member of the organization or has an invitation pending. - `const StatusMember Status = "member"` - `const StatusInvited Status = "invited"` - `Suspended bool` Indicates whether user has been suspended - `Telephone string` User's telephone number - `TwoFactorAuthenticationEnabled bool` Indicates whether two-factor authentication is enabled for the user account. Does not apply to API authentication. - `TwoFactorAuthenticationLocked bool` Indicates whether two-factor authentication is required by one of the accounts that the user is a member of. - `Zipcode string` The zipcode or postal code where the user lives. ### Example ```go package main import ( "context" "fmt" "github.com/cloudflare/cloudflare-go" "github.com/cloudflare/cloudflare-go/option" ) func main() { client := cloudflare.NewClient( option.WithAPIKey("144c9defac04969c7bfad8efaa8ea194"), option.WithAPIEmail("user@example.com"), ) user, err := client.User.Get(context.TODO()) if err != nil { panic(err.Error()) } fmt.Printf("%+v\n", user.ID) } ``` #### Response ```json { "errors": [ { "code": 1000, "message": "message", "documentation_url": "documentation_url", "source": { "pointer": "pointer" } } ], "messages": [ { "code": 1000, "message": "message", "documentation_url": "documentation_url", "source": { "pointer": "pointer" } } ], "success": true, "result": { "id": "6d7f2f5f5b1d4a0e9081fdc98d432fd1", "betas": [ "zone_level_access_beta" ], "country": "US", "first_name": "John", "has_business_zones": true, "has_enterprise_zones": true, "has_pro_zones": true, "last_name": "Appleseed", "organizations": [ { "id": "023e105f4ecef8ad9ca31a8372d0c353", "name": "Cloudflare, Inc.", "permissions": [ "#zones:read" ], "roles": [ "All Privileges - Super Administrator" ], "status": "member" } ], "suspended": true, "telephone": "+1 123-123-1234", "two_factor_authentication_enabled": true, "two_factor_authentication_locked": true, "zipcode": "12345" } } ``` ## Edit User `client.User.Edit(ctx, body) (*UserEditResponse, error)` **patch** `/user` Edit part of your user details. ### Parameters - `body UserEditParams` - `Country param.Field[string]` The country in which the user lives. - `FirstName param.Field[string]` User's first name - `LastName param.Field[string]` User's last name - `Telephone param.Field[string]` User's telephone number - `Zipcode param.Field[string]` The zipcode or postal code where the user lives. ### Returns - `type UserEditResponse struct{…}` - `ID string` Identifier of the user. - `Betas []string` Lists the betas that the user is participating in. - `Country string` The country in which the user lives. - `FirstName string` User's first name - `HasBusinessZones bool` Indicates whether user has any business zones - `HasEnterpriseZones bool` Indicates whether user has any enterprise zones - `HasProZones bool` Indicates whether user has any pro zones - `LastName string` User's last name - `Organizations []Organization` - `ID string` Identifier - `Name string` Organization name. - `Permissions []Permission` Access permissions for this User. - `Roles []string` List of roles that a user has within an organization. - `Status Status` Whether the user is a member of the organization or has an invitation pending. - `const StatusMember Status = "member"` - `const StatusInvited Status = "invited"` - `Suspended bool` Indicates whether user has been suspended - `Telephone string` User's telephone number - `TwoFactorAuthenticationEnabled bool` Indicates whether two-factor authentication is enabled for the user account. Does not apply to API authentication. - `TwoFactorAuthenticationLocked bool` Indicates whether two-factor authentication is required by one of the accounts that the user is a member of. - `Zipcode string` The zipcode or postal code where the user lives. ### Example ```go package main import ( "context" "fmt" "github.com/cloudflare/cloudflare-go" "github.com/cloudflare/cloudflare-go/option" "github.com/cloudflare/cloudflare-go/user" ) func main() { client := cloudflare.NewClient( option.WithAPIToken("Sn3lZJTBX6kkg7OdcBUAxOO963GEIyGQqnFTOFYY"), ) response, err := client.User.Edit(context.TODO(), user.UserEditParams{ }) if err != nil { panic(err.Error()) } fmt.Printf("%+v\n", response.ID) } ``` #### Response ```json { "errors": [ { "code": 1000, "message": "message", "documentation_url": "documentation_url", "source": { "pointer": "pointer" } } ], "messages": [ { "code": 1000, "message": "message", "documentation_url": "documentation_url", "source": { "pointer": "pointer" } } ], "success": true, "result": { "id": "6d7f2f5f5b1d4a0e9081fdc98d432fd1", "betas": [ "zone_level_access_beta" ], "country": "US", "first_name": "John", "has_business_zones": true, "has_enterprise_zones": true, "has_pro_zones": true, "last_name": "Appleseed", "organizations": [ { "id": "023e105f4ecef8ad9ca31a8372d0c353", "name": "Cloudflare, Inc.", "permissions": [ "#zones:read" ], "roles": [ "All Privileges - Super Administrator" ], "status": "member" } ], "suspended": true, "telephone": "+1 123-123-1234", "two_factor_authentication_enabled": true, "two_factor_authentication_locked": true, "zipcode": "12345" } } ``` # Audit Logs ## Get user audit logs `client.User.AuditLogs.List(ctx, query) (*V4PagePaginationArray[AuditLog], error)` **get** `/user/audit_logs` Gets a list of audit logs for a user account. Can be filtered by who made the change, on which zone, and the timeframe of the change. ### Parameters - `query AuditLogListParams` - `ID param.Field[string]` Finds a specific log by its ID. - `Action param.Field[AuditLogListParamsAction]` - `Type string` Filters by the action type. - `Actor param.Field[AuditLogListParamsActor]` - `Email string` Filters by the email address of the actor that made the change. - `IP string` Filters by the IP address of the request that made the change by specific IP address or valid CIDR Range. - `Before param.Field[AuditLogListParamsBeforeUnion]` Limits the returned results to logs older than the specified date. A `full-date` that conforms to RFC3339. - `UnionTime` - `UnionTime` - `Direction param.Field[AuditLogListParamsDirection]` Changes the direction of the chronological sorting. - `const AuditLogListParamsDirectionDesc AuditLogListParamsDirection = "desc"` - `const AuditLogListParamsDirectionAsc AuditLogListParamsDirection = "asc"` - `Export param.Field[bool]` Indicates that this request is an export of logs in CSV format. - `HideUserLogs param.Field[bool]` Indicates whether or not to hide user level audit logs. - `Page param.Field[float64]` Defines which page of results to return. - `PerPage param.Field[float64]` Sets the number of results to return per page. - `Since param.Field[AuditLogListParamsSinceUnion]` Limits the returned results to logs newer than the specified date. A `full-date` that conforms to RFC3339. - `UnionTime` - `UnionTime` - `Zone param.Field[AuditLogListParamsZone]` - `Name string` Filters by the name of the zone associated to the change. ### Returns - `type AuditLog struct{…}` - `ID string` A string that uniquely identifies the audit log. - `Action AuditLogAction` - `Result bool` A boolean that indicates if the action attempted was successful. - `Type string` A short string that describes the action that was performed. - `Actor AuditLogActor` - `ID string` The ID of the actor that performed the action. If a user performed the action, this will be their User ID. - `Email string` The email of the user that performed the action. - `IP string` The IP address of the request that performed the action. - `Type AuditLogActorType` The type of actor, whether a User, Cloudflare Admin, or an Automated System. - `const AuditLogActorTypeUser AuditLogActorType = "user"` - `const AuditLogActorTypeAdmin AuditLogActorType = "admin"` - `const AuditLogActorTypeCloudflare AuditLogActorType = "Cloudflare"` - `Interface string` The source of the event. - `Metadata unknown` An object which can lend more context to the action being logged. This is a flexible value and varies between different actions. - `NewValue string` The new value of the resource that was modified. - `OldValue string` The value of the resource before it was modified. - `Owner AuditLogOwner` - `ID string` Identifier - `Resource AuditLogResource` - `ID string` An identifier for the resource that was affected by the action. - `Type string` A short string that describes the resource that was affected by the action. - `When Time` A UTC RFC3339 timestamp that specifies when the action being logged occured. ### Example ```go package main import ( "context" "fmt" "github.com/cloudflare/cloudflare-go" "github.com/cloudflare/cloudflare-go/option" "github.com/cloudflare/cloudflare-go/user" ) func main() { client := cloudflare.NewClient( option.WithAPIToken("Sn3lZJTBX6kkg7OdcBUAxOO963GEIyGQqnFTOFYY"), ) page, err := client.User.AuditLogs.List(context.TODO(), user.AuditLogListParams{ }) if err != nil { panic(err.Error()) } fmt.Printf("%+v\n", page) } ``` #### Response ```json { "errors": [ { "code": 1000, "message": "message", "documentation_url": "documentation_url", "source": { "pointer": "pointer" } } ], "messages": [ { "code": 1000, "message": "message", "documentation_url": "documentation_url", "source": { "pointer": "pointer" } } ], "result": [ { "id": "d5b0f326-1232-4452-8858-1089bd7168ef", "action": { "result": true, "type": "change_setting" }, "actor": { "id": "f6b5de0326bb5182b8a4840ee01ec774", "email": "michelle@example.com", "ip": "198.41.129.166", "type": "user" }, "interface": "API", "metadata": { "name": "security_level", "type": "firewall", "value": "high", "zone_name": "example.com" }, "newValue": "low", "oldValue": "high", "owner": { "id": "023e105f4ecef8ad9ca31a8372d0c353" }, "resource": { "id": "023e105f4ecef8ad9ca31a8372d0c353", "type": "zone" }, "when": "2017-04-26T17:31:07Z" } ], "success": true } ``` # Billing # History ## Billing History Details `client.User.Billing.History.List(ctx, query) (*V4PagePaginationArray[BillingHistory], error)` **get** `/user/billing/history` Accesses your billing history object. ### Parameters - `query BillingHistoryListParams` - `Action param.Field[string]` The billing item action. - `OccurredAt param.Field[Time]` When the billing item was created. - `Order param.Field[BillingHistoryListParamsOrder]` Field to order billing history by. - `const BillingHistoryListParamsOrderType BillingHistoryListParamsOrder = "type"` - `const BillingHistoryListParamsOrderOccurredAt BillingHistoryListParamsOrder = "occurred_at"` - `const BillingHistoryListParamsOrderAction BillingHistoryListParamsOrder = "action"` - `Page param.Field[float64]` Page number of paginated results. - `PerPage param.Field[float64]` Number of items per page. - `Type param.Field[string]` The billing item type. ### Returns - `type BillingHistory struct{…}` - `ID string` Billing item identifier tag. - `Action string` The billing item action. - `Amount float64` The amount associated with this billing item. - `Currency string` The monetary unit in which pricing information is displayed. - `Description string` The billing item description. - `OccurredAt Time` When the billing item was created. - `Type string` The billing item type. - `Zone BillingHistoryZone` - `Name string` ### Example ```go package main import ( "context" "fmt" "github.com/cloudflare/cloudflare-go" "github.com/cloudflare/cloudflare-go/option" "github.com/cloudflare/cloudflare-go/user" ) func main() { client := cloudflare.NewClient( option.WithAPIToken("Sn3lZJTBX6kkg7OdcBUAxOO963GEIyGQqnFTOFYY"), ) page, err := client.User.Billing.History.List(context.TODO(), user.BillingHistoryListParams{ }) if err != nil { panic(err.Error()) } fmt.Printf("%+v\n", page) } ``` #### Response ```json { "errors": [ { "code": 1000, "message": "message", "documentation_url": "documentation_url", "source": { "pointer": "pointer" } } ], "messages": [ { "code": 1000, "message": "message", "documentation_url": "documentation_url", "source": { "pointer": "pointer" } } ], "result": [ { "id": "b69a9f3492637782896352daae219e7d", "action": "subscription", "amount": 20.99, "currency": "USD", "description": "The billing item description", "occurred_at": "2014-03-01T12:21:59.3456Z", "type": "charge", "zone": { "name": "name" } } ], "success": true, "result_info": { "count": 1, "page": 1, "per_page": 20, "total_count": 2000 } } ``` ## Domain Types ### Billing History - `type BillingHistory struct{…}` - `ID string` Billing item identifier tag. - `Action string` The billing item action. - `Amount float64` The amount associated with this billing item. - `Currency string` The monetary unit in which pricing information is displayed. - `Description string` The billing item description. - `OccurredAt Time` When the billing item was created. - `Type string` The billing item type. - `Zone BillingHistoryZone` - `Name string` # Profile ## Billing Profile Details `client.User.Billing.Profile.Get(ctx) (*BillingProfileGetResponse, error)` **get** `/user/billing/profile` Accesses your billing profile object. ### Returns - `type BillingProfileGetResponse struct{…}` - `ID string` Billing item identifier tag. - `AccountType string` - `Address string` - `Address2 string` - `Balance string` - `CardExpiryMonth int64` - `CardExpiryYear int64` - `CardNumber string` - `City string` - `Company string` - `Country string` - `CreatedOn Time` - `DeviceData string` - `EditedOn Time` - `EnterpriseBillingEmail string` - `EnterprisePrimaryEmail string` - `FirstName string` - `IsPartner bool` - `LastName string` - `NextBillDate Time` - `PaymentAddress string` - `PaymentAddress2 string` - `PaymentCity string` - `PaymentCountry string` - `PaymentEmail string` - `PaymentFirstName string` - `PaymentGateway string` - `PaymentLastName string` - `PaymentNonce string` - `PaymentState string` - `PaymentZipcode string` - `PrimaryEmail string` - `State string` - `TaxIDType string` - `Telephone string` - `UseLegacy bool` - `ValidationCode string` - `Vat string` - `Zipcode string` ### Example ```go package main import ( "context" "fmt" "github.com/cloudflare/cloudflare-go" "github.com/cloudflare/cloudflare-go/option" ) func main() { client := cloudflare.NewClient( option.WithAPIToken("Sn3lZJTBX6kkg7OdcBUAxOO963GEIyGQqnFTOFYY"), ) profile, err := client.User.Billing.Profile.Get(context.TODO()) if err != nil { panic(err.Error()) } fmt.Printf("%+v\n", profile.ID) } ``` #### Response ```json { "errors": [ { "code": 1000, "message": "message", "documentation_url": "documentation_url", "source": { "pointer": "pointer" } } ], "messages": [ { "code": 1000, "message": "message", "documentation_url": "documentation_url", "source": { "pointer": "pointer" } } ], "result": { "id": "b69a9f3492637782896352daae219e7d", "account_type": "type", "address": "123 Main Street", "address2": "Apt 1", "balance": "0", "card_expiry_month": 12, "card_expiry_year": 2099, "card_number": "4242424242424242", "city": "Anytown", "company": "Company", "country": "Anycountry", "created_on": "2014-03-01T12:21:59.3456Z", "device_data": "sample_data", "edited_on": "2014-03-01T12:21:59.3456Z", "enterprise_billing_email": "johndoe@gmail.com", "enterprise_primary_email": "johndoe@gmail.com", "first_name": "John", "is_partner": false, "last_name": "Doe", "next_bill_date": "2014-03-01T12:21:59.3456Z", "payment_address": "123 Main Street", "payment_address2": "Apt 1", "payment_city": "Anytown", "payment_country": "Anycountry", "payment_email": "johndoe@gmail.com", "payment_first_name": "John", "payment_gateway": "gateway", "payment_last_name": "Doe", "payment_nonce": "abc123", "payment_state": "state", "payment_zipcode": "12345", "primary_email": "johndoe@gmail.com", "state": "AnyState", "tax_id_type": "type", "telephone": "1234567899", "use_legacy": false, "validation_code": "1111", "vat": "GB123456789", "zipcode": "12345" }, "success": true } ``` # Invites ## List Invitations `client.User.Invites.List(ctx) (*SinglePage[Invite], error)` **get** `/user/invites` Lists all invitations associated with my user. ### Returns - `type Invite struct{…}` - `InvitedMemberID string` ID of the user to add to the organization. - `OrganizationID string` ID of the organization the user will be added to. - `ID string` Invite identifier tag. - `ExpiresOn Time` When the invite is no longer active. - `InvitedBy string` The email address of the user who created the invite. - `InvitedMemberEmail string` Email address of the user to add to the organization. - `InvitedOn Time` When the invite was sent. - `OrganizationIsEnforcingTwofactor bool` - `OrganizationName string` Organization name. - `Roles []string` List of role names the membership has for this account. - `Status InviteStatus` Current status of the invitation. - `const InviteStatusPending InviteStatus = "pending"` - `const InviteStatusAccepted InviteStatus = "accepted"` - `const InviteStatusRejected InviteStatus = "rejected"` - `const InviteStatusExpired InviteStatus = "expired"` ### Example ```go package main import ( "context" "fmt" "github.com/cloudflare/cloudflare-go" "github.com/cloudflare/cloudflare-go/option" ) func main() { client := cloudflare.NewClient( option.WithAPIKey("144c9defac04969c7bfad8efaa8ea194"), option.WithAPIEmail("user@example.com"), ) page, err := client.User.Invites.List(context.TODO()) if err != nil { panic(err.Error()) } fmt.Printf("%+v\n", page) } ``` #### Response ```json { "errors": [ { "code": 1000, "message": "message", "documentation_url": "documentation_url", "source": { "pointer": "pointer" } } ], "messages": [ { "code": 1000, "message": "message", "documentation_url": "documentation_url", "source": { "pointer": "pointer" } } ], "success": true, "result": [ { "invited_member_id": "5a7805061c76ada191ed06f989cc3dac", "organization_id": "5a7805061c76ada191ed06f989cc3dac", "id": "4f5f0c14a2a41d5063dd301b2f829f04", "expires_on": "2014-01-01T05:20:00Z", "invited_by": "user@example.com", "invited_member_email": "user@example.com", "invited_on": "2014-01-01T05:20:00Z", "organization_is_enforcing_twofactor": true, "organization_name": "Cloudflare, Inc.", "roles": [ "Account Administrator" ], "status": "accepted" } ], "result_info": { "count": 1, "page": 1, "per_page": 20, "total_count": 2000 } } ``` ## Invitation Details `client.User.Invites.Get(ctx, inviteID) (*Invite, error)` **get** `/user/invites/{invite_id}` Gets the details of an invitation. ### Parameters - `inviteID string` Invite identifier tag. ### Returns - `type Invite struct{…}` - `InvitedMemberID string` ID of the user to add to the organization. - `OrganizationID string` ID of the organization the user will be added to. - `ID string` Invite identifier tag. - `ExpiresOn Time` When the invite is no longer active. - `InvitedBy string` The email address of the user who created the invite. - `InvitedMemberEmail string` Email address of the user to add to the organization. - `InvitedOn Time` When the invite was sent. - `OrganizationIsEnforcingTwofactor bool` - `OrganizationName string` Organization name. - `Roles []string` List of role names the membership has for this account. - `Status InviteStatus` Current status of the invitation. - `const InviteStatusPending InviteStatus = "pending"` - `const InviteStatusAccepted InviteStatus = "accepted"` - `const InviteStatusRejected InviteStatus = "rejected"` - `const InviteStatusExpired InviteStatus = "expired"` ### Example ```go package main import ( "context" "fmt" "github.com/cloudflare/cloudflare-go" "github.com/cloudflare/cloudflare-go/option" ) func main() { client := cloudflare.NewClient( option.WithAPIKey("144c9defac04969c7bfad8efaa8ea194"), option.WithAPIEmail("user@example.com"), ) invite, err := client.User.Invites.Get(context.TODO(), "4f5f0c14a2a41d5063dd301b2f829f04") if err != nil { panic(err.Error()) } fmt.Printf("%+v\n", invite.InvitedMemberID) } ``` #### Response ```json { "errors": [ { "code": 1000, "message": "message", "documentation_url": "documentation_url", "source": { "pointer": "pointer" } } ], "messages": [ { "code": 1000, "message": "message", "documentation_url": "documentation_url", "source": { "pointer": "pointer" } } ], "success": true, "result": { "invited_member_id": "5a7805061c76ada191ed06f989cc3dac", "organization_id": "5a7805061c76ada191ed06f989cc3dac", "id": "4f5f0c14a2a41d5063dd301b2f829f04", "expires_on": "2014-01-01T05:20:00Z", "invited_by": "user@example.com", "invited_member_email": "user@example.com", "invited_on": "2014-01-01T05:20:00Z", "organization_is_enforcing_twofactor": true, "organization_name": "Cloudflare, Inc.", "roles": [ "Account Administrator" ], "status": "accepted" } } ``` ## Respond to Invitation `client.User.Invites.Edit(ctx, inviteID, body) (*Invite, error)` **patch** `/user/invites/{invite_id}` Responds to an invitation. ### Parameters - `inviteID string` Invite identifier tag. - `body InviteEditParams` - `Status param.Field[InviteEditParamsStatus]` Status of your response to the invitation (rejected or accepted). - `const InviteEditParamsStatusAccepted InviteEditParamsStatus = "accepted"` - `const InviteEditParamsStatusRejected InviteEditParamsStatus = "rejected"` ### Returns - `type Invite struct{…}` - `InvitedMemberID string` ID of the user to add to the organization. - `OrganizationID string` ID of the organization the user will be added to. - `ID string` Invite identifier tag. - `ExpiresOn Time` When the invite is no longer active. - `InvitedBy string` The email address of the user who created the invite. - `InvitedMemberEmail string` Email address of the user to add to the organization. - `InvitedOn Time` When the invite was sent. - `OrganizationIsEnforcingTwofactor bool` - `OrganizationName string` Organization name. - `Roles []string` List of role names the membership has for this account. - `Status InviteStatus` Current status of the invitation. - `const InviteStatusPending InviteStatus = "pending"` - `const InviteStatusAccepted InviteStatus = "accepted"` - `const InviteStatusRejected InviteStatus = "rejected"` - `const InviteStatusExpired InviteStatus = "expired"` ### Example ```go package main import ( "context" "fmt" "github.com/cloudflare/cloudflare-go" "github.com/cloudflare/cloudflare-go/option" "github.com/cloudflare/cloudflare-go/user" ) func main() { client := cloudflare.NewClient( option.WithAPIKey("144c9defac04969c7bfad8efaa8ea194"), option.WithAPIEmail("user@example.com"), ) invite, err := client.User.Invites.Edit( context.TODO(), "4f5f0c14a2a41d5063dd301b2f829f04", user.InviteEditParams{ Status: cloudflare.F(user.InviteEditParamsStatusAccepted), }, ) if err != nil { panic(err.Error()) } fmt.Printf("%+v\n", invite.InvitedMemberID) } ``` #### Response ```json { "errors": [ { "code": 1000, "message": "message", "documentation_url": "documentation_url", "source": { "pointer": "pointer" } } ], "messages": [ { "code": 1000, "message": "message", "documentation_url": "documentation_url", "source": { "pointer": "pointer" } } ], "success": true, "result": { "invited_member_id": "5a7805061c76ada191ed06f989cc3dac", "organization_id": "5a7805061c76ada191ed06f989cc3dac", "id": "4f5f0c14a2a41d5063dd301b2f829f04", "expires_on": "2014-01-01T05:20:00Z", "invited_by": "user@example.com", "invited_member_email": "user@example.com", "invited_on": "2014-01-01T05:20:00Z", "organization_is_enforcing_twofactor": true, "organization_name": "Cloudflare, Inc.", "roles": [ "Account Administrator" ], "status": "accepted" } } ``` ## Domain Types ### Invite - `type Invite struct{…}` - `InvitedMemberID string` ID of the user to add to the organization. - `OrganizationID string` ID of the organization the user will be added to. - `ID string` Invite identifier tag. - `ExpiresOn Time` When the invite is no longer active. - `InvitedBy string` The email address of the user who created the invite. - `InvitedMemberEmail string` Email address of the user to add to the organization. - `InvitedOn Time` When the invite was sent. - `OrganizationIsEnforcingTwofactor bool` - `OrganizationName string` Organization name. - `Roles []string` List of role names the membership has for this account. - `Status InviteStatus` Current status of the invitation. - `const InviteStatusPending InviteStatus = "pending"` - `const InviteStatusAccepted InviteStatus = "accepted"` - `const InviteStatusRejected InviteStatus = "rejected"` - `const InviteStatusExpired InviteStatus = "expired"` # Organizations ## List Organizations `client.User.Organizations.List(ctx, query) (*V4PagePaginationArray[Organization], error)` **get** `/user/organizations` Lists organizations the user is associated with. ### Parameters - `query OrganizationListParams` - `Direction param.Field[OrganizationListParamsDirection]` Direction to order organizations. - `const OrganizationListParamsDirectionAsc OrganizationListParamsDirection = "asc"` - `const OrganizationListParamsDirectionDesc OrganizationListParamsDirection = "desc"` - `Match param.Field[OrganizationListParamsMatch]` Whether to match all search requirements or at least one (any). - `const OrganizationListParamsMatchAny OrganizationListParamsMatch = "any"` - `const OrganizationListParamsMatchAll OrganizationListParamsMatch = "all"` - `Name param.Field[string]` Organization name. - `Order param.Field[OrganizationListParamsOrder]` Field to order organizations by. - `const OrganizationListParamsOrderID OrganizationListParamsOrder = "id"` - `const OrganizationListParamsOrderName OrganizationListParamsOrder = "name"` - `const OrganizationListParamsOrderStatus OrganizationListParamsOrder = "status"` - `Page param.Field[float64]` Page number of paginated results. - `PerPage param.Field[float64]` Number of organizations per page. - `Status param.Field[OrganizationListParamsStatus]` Whether the user is a member of the organization or has an inivitation pending. - `const OrganizationListParamsStatusMember OrganizationListParamsStatus = "member"` - `const OrganizationListParamsStatusInvited OrganizationListParamsStatus = "invited"` ### Returns - `type Organization struct{…}` - `ID string` Identifier - `Name string` Organization name. - `Permissions []Permission` Access permissions for this User. - `Roles []string` List of roles that a user has within an organization. - `Status Status` Whether the user is a member of the organization or has an invitation pending. - `const StatusMember Status = "member"` - `const StatusInvited Status = "invited"` ### Example ```go package main import ( "context" "fmt" "github.com/cloudflare/cloudflare-go" "github.com/cloudflare/cloudflare-go/option" "github.com/cloudflare/cloudflare-go/user" ) func main() { client := cloudflare.NewClient( option.WithAPIKey("144c9defac04969c7bfad8efaa8ea194"), option.WithAPIEmail("user@example.com"), ) page, err := client.User.Organizations.List(context.TODO(), user.OrganizationListParams{ }) if err != nil { panic(err.Error()) } fmt.Printf("%+v\n", page) } ``` #### Response ```json { "errors": [ { "code": 1000, "message": "message", "documentation_url": "documentation_url", "source": { "pointer": "pointer" } } ], "messages": [ { "code": 1000, "message": "message", "documentation_url": "documentation_url", "source": { "pointer": "pointer" } } ], "success": true, "result": [ { "id": "023e105f4ecef8ad9ca31a8372d0c353", "name": "Cloudflare, Inc.", "permissions": [ "#zones:read" ], "roles": [ "All Privileges - Super Administrator" ], "status": "member" } ], "result_info": { "count": 1, "page": 1, "per_page": 20, "total_count": 2000 } } ``` ## Organization Details `client.User.Organizations.Get(ctx, organizationID) (*OrganizationGetResponse, error)` **get** `/user/organizations/{organization_id}` Gets a specific organization the user is associated with. ### Parameters - `organizationID string` Identifier ### Returns - `type OrganizationGetResponse interface{…}` ### Example ```go package main import ( "context" "fmt" "github.com/cloudflare/cloudflare-go" "github.com/cloudflare/cloudflare-go/option" ) func main() { client := cloudflare.NewClient( option.WithAPIKey("144c9defac04969c7bfad8efaa8ea194"), option.WithAPIEmail("user@example.com"), ) organization, err := client.User.Organizations.Get(context.TODO(), "023e105f4ecef8ad9ca31a8372d0c353") if err != nil { panic(err.Error()) } fmt.Printf("%+v\n", organization) } ``` #### Response ```json { "errors": [ { "code": 1000, "message": "message", "documentation_url": "documentation_url", "source": { "pointer": "pointer" } } ], "messages": [ { "code": 1000, "message": "message", "documentation_url": "documentation_url", "source": { "pointer": "pointer" } } ], "success": true, "result": {} } ``` ## Leave Organization `client.User.Organizations.Delete(ctx, organizationID) (*OrganizationDeleteResponse, error)` **delete** `/user/organizations/{organization_id}` Removes association to an organization. ### Parameters - `organizationID string` Identifier ### Returns - `type OrganizationDeleteResponse struct{…}` - `ID string` Identifier ### Example ```go package main import ( "context" "fmt" "github.com/cloudflare/cloudflare-go" "github.com/cloudflare/cloudflare-go/option" ) func main() { client := cloudflare.NewClient( option.WithAPIKey("144c9defac04969c7bfad8efaa8ea194"), option.WithAPIEmail("user@example.com"), ) organization, err := client.User.Organizations.Delete(context.TODO(), "023e105f4ecef8ad9ca31a8372d0c353") if err != nil { panic(err.Error()) } fmt.Printf("%+v\n", organization.ID) } ``` #### Response ```json { "id": "023e105f4ecef8ad9ca31a8372d0c353" } ``` ## Domain Types ### Organization - `type Organization struct{…}` - `ID string` Identifier - `Name string` Organization name. - `Permissions []Permission` Access permissions for this User. - `Roles []string` List of roles that a user has within an organization. - `Status Status` Whether the user is a member of the organization or has an invitation pending. - `const StatusMember Status = "member"` - `const StatusInvited Status = "invited"` # Subscriptions ## Get User Subscriptions `client.User.Subscriptions.Get(ctx) (*SinglePage[Subscription], error)` **get** `/user/subscriptions` Lists all of a user's subscriptions. ### Returns - `type Subscription struct{…}` - `ID string` Subscription identifier tag. - `Currency string` The monetary unit in which pricing information is displayed. - `CurrentPeriodEnd Time` The end of the current period and also when the next billing is due. - `CurrentPeriodStart Time` When the current billing period started. May match initial_period_start if this is the first period. - `Frequency SubscriptionFrequency` How often the subscription is renewed automatically. - `const SubscriptionFrequencyWeekly SubscriptionFrequency = "weekly"` - `const SubscriptionFrequencyMonthly SubscriptionFrequency = "monthly"` - `const SubscriptionFrequencyQuarterly SubscriptionFrequency = "quarterly"` - `const SubscriptionFrequencyYearly SubscriptionFrequency = "yearly"` - `Price float64` The price of the subscription that will be billed, in US dollars. - `RatePlan RatePlan` The rate plan applied to the subscription. - `ID RatePlanID` The ID of the rate plan. - `const RatePlanIDFree RatePlanID = "free"` - `const RatePlanIDLite RatePlanID = "lite"` - `const RatePlanIDPro RatePlanID = "pro"` - `const RatePlanIDProPlus RatePlanID = "pro_plus"` - `const RatePlanIDBusiness RatePlanID = "business"` - `const RatePlanIDEnterprise RatePlanID = "enterprise"` - `const RatePlanIDPartnersFree RatePlanID = "partners_free"` - `const RatePlanIDPartnersPro RatePlanID = "partners_pro"` - `const RatePlanIDPartnersBusiness RatePlanID = "partners_business"` - `const RatePlanIDPartnersEnterprise RatePlanID = "partners_enterprise"` - `Currency string` The currency applied to the rate plan subscription. - `ExternallyManaged bool` Whether this rate plan is managed externally from Cloudflare. - `IsContract bool` Whether a rate plan is enterprise-based (or newly adopted term contract). - `PublicName string` The full name of the rate plan. - `Scope string` The scope that this rate plan applies to. - `Sets []string` The list of sets this rate plan applies to. Returns array of strings. - `State SubscriptionState` The state that the subscription is in. - `const SubscriptionStateTrial SubscriptionState = "Trial"` - `const SubscriptionStateProvisioned SubscriptionState = "Provisioned"` - `const SubscriptionStatePaid SubscriptionState = "Paid"` - `const SubscriptionStateAwaitingPayment SubscriptionState = "AwaitingPayment"` - `const SubscriptionStateCancelled SubscriptionState = "Cancelled"` - `const SubscriptionStateFailed SubscriptionState = "Failed"` - `const SubscriptionStateExpired SubscriptionState = "Expired"` ### Example ```go package main import ( "context" "fmt" "github.com/cloudflare/cloudflare-go" "github.com/cloudflare/cloudflare-go/option" ) func main() { client := cloudflare.NewClient( option.WithAPIToken("Sn3lZJTBX6kkg7OdcBUAxOO963GEIyGQqnFTOFYY"), ) page, err := client.User.Subscriptions.Get(context.TODO()) if err != nil { panic(err.Error()) } fmt.Printf("%+v\n", page) } ``` #### Response ```json { "errors": [ { "code": 1000, "message": "message", "documentation_url": "documentation_url", "source": { "pointer": "pointer" } } ], "messages": [ { "code": 1000, "message": "message", "documentation_url": "documentation_url", "source": { "pointer": "pointer" } } ], "result": [ { "id": "506e3185e9c882d175a2d0cb0093d9f2", "currency": "USD", "current_period_end": "2014-03-31T12:20:00Z", "current_period_start": "2014-05-11T12:20:00Z", "frequency": "monthly", "price": 20, "rate_plan": { "id": "free", "currency": "USD", "externally_managed": false, "is_contract": false, "public_name": "Business Plan", "scope": "zone", "sets": [ "string" ] }, "state": "Paid" } ], "success": true, "result_info": { "count": 1, "page": 1, "per_page": 20, "total_count": 2000 } } ``` ## Update User Subscription `client.User.Subscriptions.Update(ctx, identifier, body) (*unknown, error)` **put** `/user/subscriptions/{identifier}` Updates a user's subscriptions. ### Parameters - `identifier string` Subscription identifier tag. - `body SubscriptionUpdateParams` - `Subscription param.Field[Subscription]` ### Returns - `type SubscriptionUpdateResponseEnvelopeResult interface{…}` - `unknown` ### Example ```go package main import ( "context" "fmt" "github.com/cloudflare/cloudflare-go" "github.com/cloudflare/cloudflare-go/option" "github.com/cloudflare/cloudflare-go/shared" "github.com/cloudflare/cloudflare-go/user" ) func main() { client := cloudflare.NewClient( option.WithAPIToken("Sn3lZJTBX6kkg7OdcBUAxOO963GEIyGQqnFTOFYY"), ) subscription, err := client.User.Subscriptions.Update( context.TODO(), "506e3185e9c882d175a2d0cb0093d9f2", user.SubscriptionUpdateParams{ Subscription: shared.SubscriptionParam{ }, }, ) if err != nil { panic(err.Error()) } fmt.Printf("%+v\n", subscription) } ``` #### Response ```json { "errors": [ { "code": 1000, "message": "message", "documentation_url": "documentation_url", "source": { "pointer": "pointer" } } ], "messages": [ { "code": 1000, "message": "message", "documentation_url": "documentation_url", "source": { "pointer": "pointer" } } ], "result": {}, "success": true } ``` ## Delete User Subscription `client.User.Subscriptions.Delete(ctx, identifier) (*SubscriptionDeleteResponse, error)` **delete** `/user/subscriptions/{identifier}` Deletes a user's subscription. ### Parameters - `identifier string` Subscription identifier tag. ### Returns - `type SubscriptionDeleteResponse struct{…}` - `SubscriptionID string` Subscription identifier tag. ### Example ```go package main import ( "context" "fmt" "github.com/cloudflare/cloudflare-go" "github.com/cloudflare/cloudflare-go/option" ) func main() { client := cloudflare.NewClient( option.WithAPIToken("Sn3lZJTBX6kkg7OdcBUAxOO963GEIyGQqnFTOFYY"), ) subscription, err := client.User.Subscriptions.Delete(context.TODO(), "506e3185e9c882d175a2d0cb0093d9f2") if err != nil { panic(err.Error()) } fmt.Printf("%+v\n", subscription.SubscriptionID) } ``` #### Response ```json { "subscription_id": "506e3185e9c882d175a2d0cb0093d9f2" } ``` # Tokens ## List Tokens `client.User.Tokens.List(ctx, query) (*V4PagePaginationArray[Token], error)` **get** `/user/tokens` List all access tokens you created. ### Parameters - `query TokenListParams` - `Direction param.Field[TokenListParamsDirection]` Direction to order results. - `const TokenListParamsDirectionAsc TokenListParamsDirection = "asc"` - `const TokenListParamsDirectionDesc TokenListParamsDirection = "desc"` - `Page param.Field[float64]` Page number of paginated results. - `PerPage param.Field[float64]` Maximum number of results per page. ### Returns - `type Token struct{…}` - `ID string` Token identifier tag. - `Condition TokenCondition` - `RequestIP TokenConditionRequestIP` Client IP restrictions. - `In []TokenConditionCIDRList` List of IPv4/IPv6 CIDR addresses. - `NotIn []TokenConditionCIDRList` List of IPv4/IPv6 CIDR addresses. - `ExpiresOn Time` The expiration time on or after which the JWT MUST NOT be accepted for processing. - `IssuedOn Time` The time on which the token was created. - `LastUsedOn Time` Last time the token was used. - `ModifiedOn Time` Last time the token was modified. - `Name string` Token name. - `NotBefore Time` The time before which the token MUST NOT be accepted for processing. - `Policies []TokenPolicy` List of access policies assigned to the token. - `ID string` Policy identifier. - `Effect TokenPolicyEffect` Allow or deny operations against the resources. - `const TokenPolicyEffectAllow TokenPolicyEffect = "allow"` - `const TokenPolicyEffectDeny TokenPolicyEffect = "deny"` - `PermissionGroups []TokenPolicyPermissionGroup` A set of permission groups that are specified to the policy. - `ID string` Identifier of the permission group. - `Meta TokenPolicyPermissionGroupsMeta` Attributes associated to the permission group. - `Key string` - `Value string` - `Name string` Name of the permission group. - `Resources TokenPolicyResourcesUnion` A list of resource names that the policy applies to. - `type TokenPolicyResourcesIAMResourcesTypeObjectString map[string, string]` Map of simple string resource permissions - `type TokenPolicyResourcesIAMResourcesTypeObjectNested map[string, map[string, string]]` Map of nested resource permissions - `Status TokenStatus` Status of the token. - `const TokenStatusActive TokenStatus = "active"` - `const TokenStatusDisabled TokenStatus = "disabled"` - `const TokenStatusExpired TokenStatus = "expired"` ### Example ```go package main import ( "context" "fmt" "github.com/cloudflare/cloudflare-go" "github.com/cloudflare/cloudflare-go/option" "github.com/cloudflare/cloudflare-go/user" ) func main() { client := cloudflare.NewClient( option.WithAPIToken("Sn3lZJTBX6kkg7OdcBUAxOO963GEIyGQqnFTOFYY"), ) page, err := client.User.Tokens.List(context.TODO(), user.TokenListParams{ }) if err != nil { panic(err.Error()) } fmt.Printf("%+v\n", page) } ``` #### Response ```json { "errors": [ { "code": 1000, "message": "message", "documentation_url": "documentation_url", "source": { "pointer": "pointer" } } ], "messages": [ { "code": 1000, "message": "message", "documentation_url": "documentation_url", "source": { "pointer": "pointer" } } ], "success": true, "result": [ { "id": "ed17574386854bf78a67040be0a770b0", "condition": { "request_ip": { "in": [ "123.123.123.0/24", "2606:4700::/32" ], "not_in": [ "123.123.123.100/24", "2606:4700:4700::/48" ] } }, "expires_on": "2020-01-01T00:00:00Z", "issued_on": "2018-07-01T05:20:00Z", "last_used_on": "2020-01-02T12:34:00Z", "modified_on": "2018-07-02T05:20:00Z", "name": "readonly token", "not_before": "2018-07-01T05:20:00Z", "policies": [ { "id": "f267e341f3dd4697bd3b9f71dd96247f", "effect": "allow", "permission_groups": [ { "id": "c8fed203ed3043cba015a93ad1616f1f", "meta": { "key": "key", "value": "value" }, "name": "Zone Read" }, { "id": "82e64a83756745bbbb1c9c2701bf816b", "meta": { "key": "key", "value": "value" }, "name": "Magic Network Monitoring" } ], "resources": { "foo": "string" } } ], "status": "active" } ], "result_info": { "count": 1, "page": 1, "per_page": 20, "total_count": 2000 } } ``` ## Token Details `client.User.Tokens.Get(ctx, tokenID) (*Token, error)` **get** `/user/tokens/{token_id}` Get information about a specific token. ### Parameters - `tokenID string` Token identifier tag. ### Returns - `type Token struct{…}` - `ID string` Token identifier tag. - `Condition TokenCondition` - `RequestIP TokenConditionRequestIP` Client IP restrictions. - `In []TokenConditionCIDRList` List of IPv4/IPv6 CIDR addresses. - `NotIn []TokenConditionCIDRList` List of IPv4/IPv6 CIDR addresses. - `ExpiresOn Time` The expiration time on or after which the JWT MUST NOT be accepted for processing. - `IssuedOn Time` The time on which the token was created. - `LastUsedOn Time` Last time the token was used. - `ModifiedOn Time` Last time the token was modified. - `Name string` Token name. - `NotBefore Time` The time before which the token MUST NOT be accepted for processing. - `Policies []TokenPolicy` List of access policies assigned to the token. - `ID string` Policy identifier. - `Effect TokenPolicyEffect` Allow or deny operations against the resources. - `const TokenPolicyEffectAllow TokenPolicyEffect = "allow"` - `const TokenPolicyEffectDeny TokenPolicyEffect = "deny"` - `PermissionGroups []TokenPolicyPermissionGroup` A set of permission groups that are specified to the policy. - `ID string` Identifier of the permission group. - `Meta TokenPolicyPermissionGroupsMeta` Attributes associated to the permission group. - `Key string` - `Value string` - `Name string` Name of the permission group. - `Resources TokenPolicyResourcesUnion` A list of resource names that the policy applies to. - `type TokenPolicyResourcesIAMResourcesTypeObjectString map[string, string]` Map of simple string resource permissions - `type TokenPolicyResourcesIAMResourcesTypeObjectNested map[string, map[string, string]]` Map of nested resource permissions - `Status TokenStatus` Status of the token. - `const TokenStatusActive TokenStatus = "active"` - `const TokenStatusDisabled TokenStatus = "disabled"` - `const TokenStatusExpired TokenStatus = "expired"` ### Example ```go package main import ( "context" "fmt" "github.com/cloudflare/cloudflare-go" "github.com/cloudflare/cloudflare-go/option" ) func main() { client := cloudflare.NewClient( option.WithAPIToken("Sn3lZJTBX6kkg7OdcBUAxOO963GEIyGQqnFTOFYY"), ) token, err := client.User.Tokens.Get(context.TODO(), "ed17574386854bf78a67040be0a770b0") if err != nil { panic(err.Error()) } fmt.Printf("%+v\n", token.ID) } ``` #### Response ```json { "errors": [ { "code": 1000, "message": "message", "documentation_url": "documentation_url", "source": { "pointer": "pointer" } } ], "messages": [ { "code": 1000, "message": "message", "documentation_url": "documentation_url", "source": { "pointer": "pointer" } } ], "success": true, "result": { "id": "ed17574386854bf78a67040be0a770b0", "condition": { "request_ip": { "in": [ "123.123.123.0/24", "2606:4700::/32" ], "not_in": [ "123.123.123.100/24", "2606:4700:4700::/48" ] } }, "expires_on": "2020-01-01T00:00:00Z", "issued_on": "2018-07-01T05:20:00Z", "last_used_on": "2020-01-02T12:34:00Z", "modified_on": "2018-07-02T05:20:00Z", "name": "readonly token", "not_before": "2018-07-01T05:20:00Z", "policies": [ { "id": "f267e341f3dd4697bd3b9f71dd96247f", "effect": "allow", "permission_groups": [ { "id": "c8fed203ed3043cba015a93ad1616f1f", "meta": { "key": "key", "value": "value" }, "name": "Zone Read" }, { "id": "82e64a83756745bbbb1c9c2701bf816b", "meta": { "key": "key", "value": "value" }, "name": "Magic Network Monitoring" } ], "resources": { "foo": "string" } } ], "status": "active" } } ``` ## Create Token `client.User.Tokens.New(ctx, body) (*TokenNewResponse, error)` **post** `/user/tokens` Create a new access token. ### Parameters - `body TokenNewParams` - `Name param.Field[string]` Token name. - `Policies param.Field[[]TokenPolicy]` List of access policies assigned to the token. - `ID string` Policy identifier. - `Effect TokenPolicyEffect` Allow or deny operations against the resources. - `const TokenPolicyEffectAllow TokenPolicyEffect = "allow"` - `const TokenPolicyEffectDeny TokenPolicyEffect = "deny"` - `PermissionGroups []TokenPolicyPermissionGroup` A set of permission groups that are specified to the policy. - `ID string` Identifier of the permission group. - `Meta TokenPolicyPermissionGroupsMeta` Attributes associated to the permission group. - `Key string` - `Value string` - `Name string` Name of the permission group. - `Resources TokenPolicyResourcesUnion` A list of resource names that the policy applies to. - `type TokenPolicyResourcesIAMResourcesTypeObjectString map[string, string]` Map of simple string resource permissions - `type TokenPolicyResourcesIAMResourcesTypeObjectNested map[string, map[string, string]]` Map of nested resource permissions - `Condition param.Field[TokenNewParamsCondition]` - `RequestIP TokenNewParamsConditionRequestIP` Client IP restrictions. - `In []TokenConditionCIDRList` List of IPv4/IPv6 CIDR addresses. - `NotIn []TokenConditionCIDRList` List of IPv4/IPv6 CIDR addresses. - `ExpiresOn param.Field[Time]` The expiration time on or after which the JWT MUST NOT be accepted for processing. - `NotBefore param.Field[Time]` The time before which the token MUST NOT be accepted for processing. ### Returns - `type TokenNewResponse struct{…}` - `ID string` Token identifier tag. - `Condition TokenNewResponseCondition` - `RequestIP TokenNewResponseConditionRequestIP` Client IP restrictions. - `In []TokenConditionCIDRList` List of IPv4/IPv6 CIDR addresses. - `NotIn []TokenConditionCIDRList` List of IPv4/IPv6 CIDR addresses. - `ExpiresOn Time` The expiration time on or after which the JWT MUST NOT be accepted for processing. - `IssuedOn Time` The time on which the token was created. - `LastUsedOn Time` Last time the token was used. - `ModifiedOn Time` Last time the token was modified. - `Name string` Token name. - `NotBefore Time` The time before which the token MUST NOT be accepted for processing. - `Policies []TokenPolicy` List of access policies assigned to the token. - `ID string` Policy identifier. - `Effect TokenPolicyEffect` Allow or deny operations against the resources. - `const TokenPolicyEffectAllow TokenPolicyEffect = "allow"` - `const TokenPolicyEffectDeny TokenPolicyEffect = "deny"` - `PermissionGroups []TokenPolicyPermissionGroup` A set of permission groups that are specified to the policy. - `ID string` Identifier of the permission group. - `Meta TokenPolicyPermissionGroupsMeta` Attributes associated to the permission group. - `Key string` - `Value string` - `Name string` Name of the permission group. - `Resources TokenPolicyResourcesUnion` A list of resource names that the policy applies to. - `type TokenPolicyResourcesIAMResourcesTypeObjectString map[string, string]` Map of simple string resource permissions - `type TokenPolicyResourcesIAMResourcesTypeObjectNested map[string, map[string, string]]` Map of nested resource permissions - `Status TokenNewResponseStatus` Status of the token. - `const TokenNewResponseStatusActive TokenNewResponseStatus = "active"` - `const TokenNewResponseStatusDisabled TokenNewResponseStatus = "disabled"` - `const TokenNewResponseStatusExpired TokenNewResponseStatus = "expired"` - `Value TokenValue` The token value. ### Example ```go package main import ( "context" "fmt" "github.com/cloudflare/cloudflare-go" "github.com/cloudflare/cloudflare-go/option" "github.com/cloudflare/cloudflare-go/shared" "github.com/cloudflare/cloudflare-go/user" ) func main() { client := cloudflare.NewClient( option.WithAPIToken("Sn3lZJTBX6kkg7OdcBUAxOO963GEIyGQqnFTOFYY"), ) token, err := client.User.Tokens.New(context.TODO(), user.TokenNewParams{ Name: cloudflare.F("readonly token"), Policies: cloudflare.F([]shared.TokenPolicyParam{shared.TokenPolicyParam{ Effect: cloudflare.F(shared.TokenPolicyEffectAllow), PermissionGroups: cloudflare.F([]shared.TokenPolicyPermissionGroupParam{shared.TokenPolicyPermissionGroupParam{ ID: cloudflare.F("c8fed203ed3043cba015a93ad1616f1f"), }, shared.TokenPolicyPermissionGroupParam{ ID: cloudflare.F("82e64a83756745bbbb1c9c2701bf816b"), }}), Resources: cloudflare.F[shared.TokenPolicyResourcesUnionParam](shared.TokenPolicyResourcesIAMResourcesTypeObjectStringParam(map[string]string{ "foo": "string", })), }}), }) if err != nil { panic(err.Error()) } fmt.Printf("%+v\n", token.ID) } ``` #### Response ```json { "errors": [ { "code": 1000, "message": "message", "documentation_url": "documentation_url", "source": { "pointer": "pointer" } } ], "messages": [ { "code": 1000, "message": "message", "documentation_url": "documentation_url", "source": { "pointer": "pointer" } } ], "success": true, "result": { "id": "ed17574386854bf78a67040be0a770b0", "condition": { "request_ip": { "in": [ "123.123.123.0/24", "2606:4700::/32" ], "not_in": [ "123.123.123.100/24", "2606:4700:4700::/48" ] } }, "expires_on": "2020-01-01T00:00:00Z", "issued_on": "2018-07-01T05:20:00Z", "last_used_on": "2020-01-02T12:34:00Z", "modified_on": "2018-07-02T05:20:00Z", "name": "readonly token", "not_before": "2018-07-01T05:20:00Z", "policies": [ { "id": "f267e341f3dd4697bd3b9f71dd96247f", "effect": "allow", "permission_groups": [ { "id": "c8fed203ed3043cba015a93ad1616f1f", "meta": { "key": "key", "value": "value" }, "name": "Zone Read" }, { "id": "82e64a83756745bbbb1c9c2701bf816b", "meta": { "key": "key", "value": "value" }, "name": "Magic Network Monitoring" } ], "resources": { "foo": "string" } } ], "status": "active", "value": "8M7wS6hCpXVc-DoRnPPY_UCWPgy8aea4Wy6kCe5T" } } ``` ## Update Token `client.User.Tokens.Update(ctx, tokenID, body) (*Token, error)` **put** `/user/tokens/{token_id}` Update an existing token. ### Parameters - `tokenID string` Token identifier tag. - `body TokenUpdateParams` - `Token param.Field[Token]` ### Returns - `type Token struct{…}` - `ID string` Token identifier tag. - `Condition TokenCondition` - `RequestIP TokenConditionRequestIP` Client IP restrictions. - `In []TokenConditionCIDRList` List of IPv4/IPv6 CIDR addresses. - `NotIn []TokenConditionCIDRList` List of IPv4/IPv6 CIDR addresses. - `ExpiresOn Time` The expiration time on or after which the JWT MUST NOT be accepted for processing. - `IssuedOn Time` The time on which the token was created. - `LastUsedOn Time` Last time the token was used. - `ModifiedOn Time` Last time the token was modified. - `Name string` Token name. - `NotBefore Time` The time before which the token MUST NOT be accepted for processing. - `Policies []TokenPolicy` List of access policies assigned to the token. - `ID string` Policy identifier. - `Effect TokenPolicyEffect` Allow or deny operations against the resources. - `const TokenPolicyEffectAllow TokenPolicyEffect = "allow"` - `const TokenPolicyEffectDeny TokenPolicyEffect = "deny"` - `PermissionGroups []TokenPolicyPermissionGroup` A set of permission groups that are specified to the policy. - `ID string` Identifier of the permission group. - `Meta TokenPolicyPermissionGroupsMeta` Attributes associated to the permission group. - `Key string` - `Value string` - `Name string` Name of the permission group. - `Resources TokenPolicyResourcesUnion` A list of resource names that the policy applies to. - `type TokenPolicyResourcesIAMResourcesTypeObjectString map[string, string]` Map of simple string resource permissions - `type TokenPolicyResourcesIAMResourcesTypeObjectNested map[string, map[string, string]]` Map of nested resource permissions - `Status TokenStatus` Status of the token. - `const TokenStatusActive TokenStatus = "active"` - `const TokenStatusDisabled TokenStatus = "disabled"` - `const TokenStatusExpired TokenStatus = "expired"` ### Example ```go package main import ( "context" "fmt" "github.com/cloudflare/cloudflare-go" "github.com/cloudflare/cloudflare-go/option" "github.com/cloudflare/cloudflare-go/shared" "github.com/cloudflare/cloudflare-go/user" ) func main() { client := cloudflare.NewClient( option.WithAPIToken("Sn3lZJTBX6kkg7OdcBUAxOO963GEIyGQqnFTOFYY"), ) token, err := client.User.Tokens.Update( context.TODO(), "ed17574386854bf78a67040be0a770b0", user.TokenUpdateParams{ Token: shared.TokenParam{ Name: cloudflare.F("readonly token"), Policies: cloudflare.F([]shared.TokenPolicyParam{shared.TokenPolicyParam{ Effect: cloudflare.F(shared.TokenPolicyEffectAllow), PermissionGroups: cloudflare.F([]shared.TokenPolicyPermissionGroupParam{shared.TokenPolicyPermissionGroupParam{ ID: cloudflare.F("c8fed203ed3043cba015a93ad1616f1f"), }, shared.TokenPolicyPermissionGroupParam{ ID: cloudflare.F("82e64a83756745bbbb1c9c2701bf816b"), }}), Resources: cloudflare.F[shared.TokenPolicyResourcesUnionParam](shared.TokenPolicyResourcesIAMResourcesTypeObjectStringParam(map[string]string{ "foo": "string", })), }}), }, }, ) if err != nil { panic(err.Error()) } fmt.Printf("%+v\n", token.ID) } ``` #### Response ```json { "errors": [ { "code": 1000, "message": "message", "documentation_url": "documentation_url", "source": { "pointer": "pointer" } } ], "messages": [ { "code": 1000, "message": "message", "documentation_url": "documentation_url", "source": { "pointer": "pointer" } } ], "success": true, "result": { "id": "ed17574386854bf78a67040be0a770b0", "condition": { "request_ip": { "in": [ "123.123.123.0/24", "2606:4700::/32" ], "not_in": [ "123.123.123.100/24", "2606:4700:4700::/48" ] } }, "expires_on": "2020-01-01T00:00:00Z", "issued_on": "2018-07-01T05:20:00Z", "last_used_on": "2020-01-02T12:34:00Z", "modified_on": "2018-07-02T05:20:00Z", "name": "readonly token", "not_before": "2018-07-01T05:20:00Z", "policies": [ { "id": "f267e341f3dd4697bd3b9f71dd96247f", "effect": "allow", "permission_groups": [ { "id": "c8fed203ed3043cba015a93ad1616f1f", "meta": { "key": "key", "value": "value" }, "name": "Zone Read" }, { "id": "82e64a83756745bbbb1c9c2701bf816b", "meta": { "key": "key", "value": "value" }, "name": "Magic Network Monitoring" } ], "resources": { "foo": "string" } } ], "status": "active" } } ``` ## Delete Token `client.User.Tokens.Delete(ctx, tokenID) (*TokenDeleteResponse, error)` **delete** `/user/tokens/{token_id}` Destroy a token. ### Parameters - `tokenID string` Token identifier tag. ### Returns - `type TokenDeleteResponse struct{…}` - `ID string` Identifier ### Example ```go package main import ( "context" "fmt" "github.com/cloudflare/cloudflare-go" "github.com/cloudflare/cloudflare-go/option" ) func main() { client := cloudflare.NewClient( option.WithAPIToken("Sn3lZJTBX6kkg7OdcBUAxOO963GEIyGQqnFTOFYY"), ) token, err := client.User.Tokens.Delete(context.TODO(), "ed17574386854bf78a67040be0a770b0") if err != nil { panic(err.Error()) } fmt.Printf("%+v\n", token.ID) } ``` #### Response ```json { "errors": [ { "code": 1000, "message": "message", "documentation_url": "documentation_url", "source": { "pointer": "pointer" } } ], "messages": [ { "code": 1000, "message": "message", "documentation_url": "documentation_url", "source": { "pointer": "pointer" } } ], "success": true, "result": { "id": "023e105f4ecef8ad9ca31a8372d0c353" } } ``` ## Verify Token `client.User.Tokens.Verify(ctx) (*TokenVerifyResponse, error)` **get** `/user/tokens/verify` Test whether a token works. ### Returns - `type TokenVerifyResponse struct{…}` - `ID string` Token identifier tag. - `Status TokenVerifyResponseStatus` Status of the token. - `const TokenVerifyResponseStatusActive TokenVerifyResponseStatus = "active"` - `const TokenVerifyResponseStatusDisabled TokenVerifyResponseStatus = "disabled"` - `const TokenVerifyResponseStatusExpired TokenVerifyResponseStatus = "expired"` - `ExpiresOn Time` The expiration time on or after which the JWT MUST NOT be accepted for processing. - `NotBefore Time` The time before which the token MUST NOT be accepted for processing. ### Example ```go package main import ( "context" "fmt" "github.com/cloudflare/cloudflare-go" "github.com/cloudflare/cloudflare-go/option" ) func main() { client := cloudflare.NewClient( option.WithAPIToken("Sn3lZJTBX6kkg7OdcBUAxOO963GEIyGQqnFTOFYY"), ) response, err := client.User.Tokens.Verify(context.TODO()) if err != nil { panic(err.Error()) } fmt.Printf("%+v\n", response.ID) } ``` #### Response ```json { "errors": [ { "code": 1000, "message": "message", "documentation_url": "documentation_url", "source": { "pointer": "pointer" } } ], "messages": [ { "code": 1000, "message": "message", "documentation_url": "documentation_url", "source": { "pointer": "pointer" } } ], "success": true, "result": { "id": "ed17574386854bf78a67040be0a770b0", "status": "active", "expires_on": "2020-01-01T00:00:00Z", "not_before": "2018-07-01T05:20:00Z" } } ``` # Permission Groups ## List Token Permission Groups `client.User.Tokens.PermissionGroups.List(ctx, query) (*SinglePage[TokenPermissionGroupListResponse], error)` **get** `/user/tokens/permission_groups` Find all available permission groups for API Tokens ### Parameters - `query TokenPermissionGroupListParams` - `Name param.Field[string]` Filter by the name of the permission group. The value must be URL-encoded. - `Scope param.Field[string]` Filter by the scope of the permission group. The value must be URL-encoded. ### Returns - `type TokenPermissionGroupListResponse struct{…}` - `ID string` Public ID. - `Name string` Permission Group Name - `Scopes []TokenPermissionGroupListResponseScope` Resources to which the Permission Group is scoped - `const TokenPermissionGroupListResponseScopeComCloudflareAPIAccount TokenPermissionGroupListResponseScope = "com.cloudflare.api.account"` - `const TokenPermissionGroupListResponseScopeComCloudflareAPIAccountZone TokenPermissionGroupListResponseScope = "com.cloudflare.api.account.zone"` - `const TokenPermissionGroupListResponseScopeComCloudflareAPIUser TokenPermissionGroupListResponseScope = "com.cloudflare.api.user"` - `const TokenPermissionGroupListResponseScopeComCloudflareEdgeR2Bucket TokenPermissionGroupListResponseScope = "com.cloudflare.edge.r2.bucket"` ### Example ```go package main import ( "context" "fmt" "github.com/cloudflare/cloudflare-go" "github.com/cloudflare/cloudflare-go/option" "github.com/cloudflare/cloudflare-go/user" ) func main() { client := cloudflare.NewClient( option.WithAPIToken("Sn3lZJTBX6kkg7OdcBUAxOO963GEIyGQqnFTOFYY"), ) page, err := client.User.Tokens.PermissionGroups.List(context.TODO(), user.TokenPermissionGroupListParams{ }) if err != nil { panic(err.Error()) } fmt.Printf("%+v\n", page) } ``` #### Response ```json { "errors": [ { "code": 1000, "message": "message", "documentation_url": "documentation_url", "source": { "pointer": "pointer" } } ], "messages": [ { "code": 1000, "message": "message", "documentation_url": "documentation_url", "source": { "pointer": "pointer" } } ], "success": true, "result": [ { "id": "7cf72faf220841aabcfdfab81c43c4f6", "name": "Billing Read", "scopes": [ "com.cloudflare.api.account" ] }, { "id": "9d24387c6e8544e2bc4024a03991339f", "name": "Load Balancing: Monitors and Pools Read", "scopes": [ "com.cloudflare.api.account" ] }, { "id": "d2a1802cc9a34e30852f8b33869b2f3c", "name": "Load Balancing: Monitors and Pools Write", "scopes": [ "com.cloudflare.api.account" ] }, { "id": "8b47d2786a534c08a1f94ee8f9f599ef", "name": "Workers KV Storage Read", "scopes": [ "com.cloudflare.api.account" ] }, { "id": "f7f0eda5697f475c90846e879bab8666", "name": "Workers KV Storage Write", "scopes": [ "com.cloudflare.api.account" ] }, { "id": "1a71c399035b4950a1bd1466bbe4f420", "name": "Workers Scripts Read", "scopes": [ "com.cloudflare.api.account" ] }, { "id": "e086da7e2179491d91ee5f35b3ca210a", "name": "Workers Scripts Write", "scopes": [ "com.cloudflare.api.account" ] } ], "result_info": { "count": 1, "page": 1, "per_page": 20, "total_count": 2000 } } ``` # Value ## Roll Token `client.User.Tokens.Value.Update(ctx, tokenID, body) (*TokenValue, error)` **put** `/user/tokens/{token_id}/value` Roll the token secret. ### Parameters - `tokenID string` Token identifier tag. - `body TokenValueUpdateParams` - `Body param.Field[unknown]` ### Returns - `type TokenValue string` The token value. ### Example ```go package main import ( "context" "fmt" "github.com/cloudflare/cloudflare-go" "github.com/cloudflare/cloudflare-go/option" "github.com/cloudflare/cloudflare-go/user" ) func main() { client := cloudflare.NewClient( option.WithAPIToken("Sn3lZJTBX6kkg7OdcBUAxOO963GEIyGQqnFTOFYY"), ) tokenValue, err := client.User.Tokens.Value.Update( context.TODO(), "ed17574386854bf78a67040be0a770b0", user.TokenValueUpdateParams{ Body: map[string]interface{}{ }, }, ) if err != nil { panic(err.Error()) } fmt.Printf("%+v\n", tokenValue) } ``` #### Response ```json { "errors": [ { "code": 1000, "message": "message", "documentation_url": "documentation_url", "source": { "pointer": "pointer" } } ], "messages": [ { "code": 1000, "message": "message", "documentation_url": "documentation_url", "source": { "pointer": "pointer" } } ], "success": true, "result": "8M7wS6hCpXVc-DoRnPPY_UCWPgy8aea4Wy6kCe5T" } ```