# User ## User Details `client.user.get(RequestOptionsoptions?): UserGetResponse` **get** `/user` User Details ### Returns - `UserGetResponse` - `id?: string` Identifier of the user. - `betas?: Array` Lists the betas that the user is participating in. - `country?: string | null` The country in which the user lives. - `first_name?: string | null` User's first name - `has_business_zones?: boolean` Indicates whether user has any business zones - `has_enterprise_zones?: boolean` Indicates whether user has any enterprise zones - `has_pro_zones?: boolean` Indicates whether user has any pro zones - `last_name?: string | null` User's last name - `organizations?: Array` - `id?: string` Identifier - `name?: string` Organization name. - `permissions?: Array` Access permissions for this User. - `roles?: Array` 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. - `"member"` - `"invited"` - `suspended?: boolean` Indicates whether user has been suspended - `telephone?: string | null` User's telephone number - `two_factor_authentication_enabled?: boolean` Indicates whether two-factor authentication is enabled for the user account. Does not apply to API authentication. - `two_factor_authentication_locked?: boolean` Indicates whether two-factor authentication is required by one of the accounts that the user is a member of. - `zipcode?: string | null` The zipcode or postal code where the user lives. ### Example ```node import Cloudflare from 'cloudflare'; const client = new Cloudflare({ apiEmail: process.env['CLOUDFLARE_EMAIL'], // This is the default and can be omitted apiKey: process.env['CLOUDFLARE_API_KEY'], // This is the default and can be omitted }); const user = await client.user.get(); console.log(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(UserEditParamsbody, RequestOptionsoptions?): UserEditResponse` **patch** `/user` Edit part of your user details. ### Parameters - `body: UserEditParams` - `country?: string | null` The country in which the user lives. - `first_name?: string | null` User's first name - `last_name?: string | null` User's last name - `telephone?: string | null` User's telephone number - `zipcode?: string | null` The zipcode or postal code where the user lives. ### Returns - `UserEditResponse` - `id?: string` Identifier of the user. - `betas?: Array` Lists the betas that the user is participating in. - `country?: string | null` The country in which the user lives. - `first_name?: string | null` User's first name - `has_business_zones?: boolean` Indicates whether user has any business zones - `has_enterprise_zones?: boolean` Indicates whether user has any enterprise zones - `has_pro_zones?: boolean` Indicates whether user has any pro zones - `last_name?: string | null` User's last name - `organizations?: Array` - `id?: string` Identifier - `name?: string` Organization name. - `permissions?: Array` Access permissions for this User. - `roles?: Array` 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. - `"member"` - `"invited"` - `suspended?: boolean` Indicates whether user has been suspended - `telephone?: string | null` User's telephone number - `two_factor_authentication_enabled?: boolean` Indicates whether two-factor authentication is enabled for the user account. Does not apply to API authentication. - `two_factor_authentication_locked?: boolean` Indicates whether two-factor authentication is required by one of the accounts that the user is a member of. - `zipcode?: string | null` The zipcode or postal code where the user lives. ### Example ```node import Cloudflare from 'cloudflare'; const client = new Cloudflare({ apiToken: process.env['CLOUDFLARE_API_TOKEN'], // This is the default and can be omitted }); const response = await client.user.edit(); console.log(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" } } ``` ## Domain Types ### User Get Response - `UserGetResponse` - `id?: string` Identifier of the user. - `betas?: Array` Lists the betas that the user is participating in. - `country?: string | null` The country in which the user lives. - `first_name?: string | null` User's first name - `has_business_zones?: boolean` Indicates whether user has any business zones - `has_enterprise_zones?: boolean` Indicates whether user has any enterprise zones - `has_pro_zones?: boolean` Indicates whether user has any pro zones - `last_name?: string | null` User's last name - `organizations?: Array` - `id?: string` Identifier - `name?: string` Organization name. - `permissions?: Array` Access permissions for this User. - `roles?: Array` 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. - `"member"` - `"invited"` - `suspended?: boolean` Indicates whether user has been suspended - `telephone?: string | null` User's telephone number - `two_factor_authentication_enabled?: boolean` Indicates whether two-factor authentication is enabled for the user account. Does not apply to API authentication. - `two_factor_authentication_locked?: boolean` Indicates whether two-factor authentication is required by one of the accounts that the user is a member of. - `zipcode?: string | null` The zipcode or postal code where the user lives. ### User Edit Response - `UserEditResponse` - `id?: string` Identifier of the user. - `betas?: Array` Lists the betas that the user is participating in. - `country?: string | null` The country in which the user lives. - `first_name?: string | null` User's first name - `has_business_zones?: boolean` Indicates whether user has any business zones - `has_enterprise_zones?: boolean` Indicates whether user has any enterprise zones - `has_pro_zones?: boolean` Indicates whether user has any pro zones - `last_name?: string | null` User's last name - `organizations?: Array` - `id?: string` Identifier - `name?: string` Organization name. - `permissions?: Array` Access permissions for this User. - `roles?: Array` 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. - `"member"` - `"invited"` - `suspended?: boolean` Indicates whether user has been suspended - `telephone?: string | null` User's telephone number - `two_factor_authentication_enabled?: boolean` Indicates whether two-factor authentication is enabled for the user account. Does not apply to API authentication. - `two_factor_authentication_locked?: boolean` Indicates whether two-factor authentication is required by one of the accounts that the user is a member of. - `zipcode?: string | null` The zipcode or postal code where the user lives. # Audit Logs ## Get user audit logs `client.user.auditLogs.list(AuditLogListParamsquery?, RequestOptionsoptions?): V4PagePaginationArray` **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?: string` Finds a specific log by its ID. - `action?: Action` - `type?: string` Filters by the action type. - `actor?: Actor` - `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?: (string & {}) | (string & {})` Limits the returned results to logs older than the specified date. A `full-date` that conforms to RFC3339. - `(string & {})` - `(string & {})` - `direction?: "desc" | "asc"` Changes the direction of the chronological sorting. - `"desc"` - `"asc"` - `_export?: boolean` Indicates that this request is an export of logs in CSV format. - `hide_user_logs?: boolean` Indicates whether or not to hide user level audit logs. - `page?: number` Defines which page of results to return. - `per_page?: number` Sets the number of results to return per page. - `since?: (string & {}) | (string & {})` Limits the returned results to logs newer than the specified date. A `full-date` that conforms to RFC3339. - `(string & {})` - `(string & {})` - `zone?: Zone` - `name?: string` Filters by the name of the zone associated to the change. ### Returns - `AuditLog` - `id?: string` A string that uniquely identifies the audit log. - `action?: Action` - `result?: boolean` A boolean that indicates if the action attempted was successful. - `type?: string` A short string that describes the action that was performed. - `actor?: Actor` - `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?: "user" | "admin" | "Cloudflare"` The type of actor, whether a User, Cloudflare Admin, or an Automated System. - `"user"` - `"admin"` - `"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?: Owner` - `id?: string` Identifier - `resource?: Resource` - `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?: string` A UTC RFC3339 timestamp that specifies when the action being logged occured. ### Example ```node import Cloudflare from 'cloudflare'; const client = new Cloudflare({ apiToken: process.env['CLOUDFLARE_API_TOKEN'], // This is the default and can be omitted }); // Automatically fetches more pages as needed. for await (const auditLog of client.user.auditLogs.list()) { console.log(auditLog.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": "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(HistoryListParamsquery?, RequestOptionsoptions?): V4PagePaginationArray` **get** `/user/billing/history` Accesses your billing history object. ### Parameters - `query: HistoryListParams` - `action?: string` The billing item action. - `occurred_at?: string` When the billing item was created. - `order?: "type" | "occurred_at" | "action"` Field to order billing history by. - `"type"` - `"occurred_at"` - `"action"` - `page?: number` Page number of paginated results. - `per_page?: number` Number of items per page. - `type?: string` The billing item type. ### Returns - `BillingHistory` - `id: string` Billing item identifier tag. - `action: string` The billing item action. - `amount: number` The amount associated with this billing item. - `currency: string` The monetary unit in which pricing information is displayed. - `description: string` The billing item description. - `occurred_at: string` When the billing item was created. - `type: string` The billing item type. - `zone: Zone` - `name?: string` ### Example ```node import Cloudflare from 'cloudflare'; const client = new Cloudflare({ apiToken: process.env['CLOUDFLARE_API_TOKEN'], // This is the default and can be omitted }); // Automatically fetches more pages as needed. for await (const billingHistory of client.user.billing.history.list()) { console.log(billingHistory.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", "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 - `BillingHistory` - `id: string` Billing item identifier tag. - `action: string` The billing item action. - `amount: number` The amount associated with this billing item. - `currency: string` The monetary unit in which pricing information is displayed. - `description: string` The billing item description. - `occurred_at: string` When the billing item was created. - `type: string` The billing item type. - `zone: Zone` - `name?: string` # Profile ## Billing Profile Details `client.user.billing.profile.get(RequestOptionsoptions?): ProfileGetResponse` **get** `/user/billing/profile` Accesses your billing profile object. ### Returns - `ProfileGetResponse` - `id?: string` Billing item identifier tag. - `account_type?: string` - `address?: string` - `address2?: string` - `balance?: string` - `card_expiry_month?: number` - `card_expiry_year?: number` - `card_number?: string` - `city?: string` - `company?: string` - `country?: string` - `created_on?: string` - `device_data?: string` - `edited_on?: string` - `enterprise_billing_email?: string` - `enterprise_primary_email?: string` - `first_name?: string` - `is_partner?: boolean` - `last_name?: string` - `next_bill_date?: string` - `payment_address?: string` - `payment_address2?: string` - `payment_city?: string` - `payment_country?: string` - `payment_email?: string` - `payment_first_name?: string` - `payment_gateway?: string` - `payment_last_name?: string` - `payment_nonce?: string` - `payment_state?: string` - `payment_zipcode?: string` - `primary_email?: string` - `state?: string` - `tax_id_type?: string` - `telephone?: string` - `use_legacy?: boolean` - `validation_code?: string` - `vat?: string` - `zipcode?: string` ### Example ```node import Cloudflare from 'cloudflare'; const client = new Cloudflare({ apiToken: process.env['CLOUDFLARE_API_TOKEN'], // This is the default and can be omitted }); const profile = await client.user.billing.profile.get(); console.log(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 } ``` ## Domain Types ### Profile Get Response - `ProfileGetResponse` - `id?: string` Billing item identifier tag. - `account_type?: string` - `address?: string` - `address2?: string` - `balance?: string` - `card_expiry_month?: number` - `card_expiry_year?: number` - `card_number?: string` - `city?: string` - `company?: string` - `country?: string` - `created_on?: string` - `device_data?: string` - `edited_on?: string` - `enterprise_billing_email?: string` - `enterprise_primary_email?: string` - `first_name?: string` - `is_partner?: boolean` - `last_name?: string` - `next_bill_date?: string` - `payment_address?: string` - `payment_address2?: string` - `payment_city?: string` - `payment_country?: string` - `payment_email?: string` - `payment_first_name?: string` - `payment_gateway?: string` - `payment_last_name?: string` - `payment_nonce?: string` - `payment_state?: string` - `payment_zipcode?: string` - `primary_email?: string` - `state?: string` - `tax_id_type?: string` - `telephone?: string` - `use_legacy?: boolean` - `validation_code?: string` - `vat?: string` - `zipcode?: string` # Invites ## List Invitations `client.user.invites.list(RequestOptionsoptions?): SinglePage` **get** `/user/invites` Lists all invitations associated with my user. ### Returns - `Invite` - `invited_member_id: string | null` ID of the user to add to the organization. - `organization_id: string` ID of the organization the user will be added to. - `id?: string` Invite identifier tag. - `expires_on?: string` When the invite is no longer active. - `invited_by?: string` The email address of the user who created the invite. - `invited_member_email?: string` Email address of the user to add to the organization. - `invited_on?: string` When the invite was sent. - `organization_is_enforcing_twofactor?: boolean` - `organization_name?: string` Organization name. - `roles?: Array` List of role names the membership has for this account. - `status?: "pending" | "accepted" | "rejected" | "expired"` Current status of the invitation. - `"pending"` - `"accepted"` - `"rejected"` - `"expired"` ### Example ```node import Cloudflare from 'cloudflare'; const client = new Cloudflare({ apiEmail: process.env['CLOUDFLARE_EMAIL'], // This is the default and can be omitted apiKey: process.env['CLOUDFLARE_API_KEY'], // This is the default and can be omitted }); // Automatically fetches more pages as needed. for await (const invite of client.user.invites.list()) { console.log(invite.invited_member_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": [ { "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(stringinviteId, RequestOptionsoptions?): Invite` **get** `/user/invites/{invite_id}` Gets the details of an invitation. ### Parameters - `inviteId: string` Invite identifier tag. ### Returns - `Invite` - `invited_member_id: string | null` ID of the user to add to the organization. - `organization_id: string` ID of the organization the user will be added to. - `id?: string` Invite identifier tag. - `expires_on?: string` When the invite is no longer active. - `invited_by?: string` The email address of the user who created the invite. - `invited_member_email?: string` Email address of the user to add to the organization. - `invited_on?: string` When the invite was sent. - `organization_is_enforcing_twofactor?: boolean` - `organization_name?: string` Organization name. - `roles?: Array` List of role names the membership has for this account. - `status?: "pending" | "accepted" | "rejected" | "expired"` Current status of the invitation. - `"pending"` - `"accepted"` - `"rejected"` - `"expired"` ### Example ```node import Cloudflare from 'cloudflare'; const client = new Cloudflare({ apiEmail: process.env['CLOUDFLARE_EMAIL'], // This is the default and can be omitted apiKey: process.env['CLOUDFLARE_API_KEY'], // This is the default and can be omitted }); const invite = await client.user.invites.get('4f5f0c14a2a41d5063dd301b2f829f04'); console.log(invite.invited_member_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": { "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(stringinviteId, InviteEditParamsbody, RequestOptionsoptions?): Invite` **patch** `/user/invites/{invite_id}` Responds to an invitation. ### Parameters - `inviteId: string` Invite identifier tag. - `body: InviteEditParams` - `status: "accepted" | "rejected"` Status of your response to the invitation (rejected or accepted). - `"accepted"` - `"rejected"` ### Returns - `Invite` - `invited_member_id: string | null` ID of the user to add to the organization. - `organization_id: string` ID of the organization the user will be added to. - `id?: string` Invite identifier tag. - `expires_on?: string` When the invite is no longer active. - `invited_by?: string` The email address of the user who created the invite. - `invited_member_email?: string` Email address of the user to add to the organization. - `invited_on?: string` When the invite was sent. - `organization_is_enforcing_twofactor?: boolean` - `organization_name?: string` Organization name. - `roles?: Array` List of role names the membership has for this account. - `status?: "pending" | "accepted" | "rejected" | "expired"` Current status of the invitation. - `"pending"` - `"accepted"` - `"rejected"` - `"expired"` ### Example ```node import Cloudflare from 'cloudflare'; const client = new Cloudflare({ apiEmail: process.env['CLOUDFLARE_EMAIL'], // This is the default and can be omitted apiKey: process.env['CLOUDFLARE_API_KEY'], // This is the default and can be omitted }); const invite = await client.user.invites.edit('4f5f0c14a2a41d5063dd301b2f829f04', { status: 'accepted', }); console.log(invite.invited_member_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": { "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 - `Invite` - `invited_member_id: string | null` ID of the user to add to the organization. - `organization_id: string` ID of the organization the user will be added to. - `id?: string` Invite identifier tag. - `expires_on?: string` When the invite is no longer active. - `invited_by?: string` The email address of the user who created the invite. - `invited_member_email?: string` Email address of the user to add to the organization. - `invited_on?: string` When the invite was sent. - `organization_is_enforcing_twofactor?: boolean` - `organization_name?: string` Organization name. - `roles?: Array` List of role names the membership has for this account. - `status?: "pending" | "accepted" | "rejected" | "expired"` Current status of the invitation. - `"pending"` - `"accepted"` - `"rejected"` - `"expired"` # Organizations ## List Organizations `client.user.organizations.list(OrganizationListParamsquery?, RequestOptionsoptions?): V4PagePaginationArray` **get** `/user/organizations` Lists organizations the user is associated with. ### Parameters - `query: OrganizationListParams` - `direction?: "asc" | "desc"` Direction to order organizations. - `"asc"` - `"desc"` - `match?: "any" | "all"` Whether to match all search requirements or at least one (any). - `"any"` - `"all"` - `name?: string` Organization name. - `order?: "id" | "name" | "status"` Field to order organizations by. - `"id"` - `"name"` - `"status"` - `page?: number` Page number of paginated results. - `per_page?: number` Number of organizations per page. - `status?: "member" | "invited"` Whether the user is a member of the organization or has an inivitation pending. - `"member"` - `"invited"` ### Returns - `Organization` - `id?: string` Identifier - `name?: string` Organization name. - `permissions?: Array` Access permissions for this User. - `roles?: Array` 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. - `"member"` - `"invited"` ### Example ```node import Cloudflare from 'cloudflare'; const client = new Cloudflare({ apiEmail: process.env['CLOUDFLARE_EMAIL'], // This is the default and can be omitted apiKey: process.env['CLOUDFLARE_API_KEY'], // This is the default and can be omitted }); // Automatically fetches more pages as needed. for await (const organization of client.user.organizations.list()) { console.log(organization.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", "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(stringorganizationId, RequestOptionsoptions?): OrganizationGetResponse` **get** `/user/organizations/{organization_id}` Gets a specific organization the user is associated with. ### Parameters - `organizationId: string` Identifier ### Returns - `OrganizationGetResponse = unknown` ### Example ```node import Cloudflare from 'cloudflare'; const client = new Cloudflare({ apiEmail: process.env['CLOUDFLARE_EMAIL'], // This is the default and can be omitted apiKey: process.env['CLOUDFLARE_API_KEY'], // This is the default and can be omitted }); const organization = await client.user.organizations.get('023e105f4ecef8ad9ca31a8372d0c353'); console.log(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(stringorganizationId, RequestOptionsoptions?): OrganizationDeleteResponse` **delete** `/user/organizations/{organization_id}` Removes association to an organization. ### Parameters - `organizationId: string` Identifier ### Returns - `OrganizationDeleteResponse` - `id?: string` Identifier ### Example ```node import Cloudflare from 'cloudflare'; const client = new Cloudflare({ apiEmail: process.env['CLOUDFLARE_EMAIL'], // This is the default and can be omitted apiKey: process.env['CLOUDFLARE_API_KEY'], // This is the default and can be omitted }); const organization = await client.user.organizations.delete('023e105f4ecef8ad9ca31a8372d0c353'); console.log(organization.id); ``` #### Response ```json { "id": "023e105f4ecef8ad9ca31a8372d0c353" } ``` ## Domain Types ### Organization - `Organization` - `id?: string` Identifier - `name?: string` Organization name. - `permissions?: Array` Access permissions for this User. - `roles?: Array` 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. - `"member"` - `"invited"` ### Organization Get Response - `OrganizationGetResponse = unknown` ### Organization Delete Response - `OrganizationDeleteResponse` - `id?: string` Identifier # Subscriptions ## Get User Subscriptions `client.user.subscriptions.get(RequestOptionsoptions?): SinglePage` **get** `/user/subscriptions` Lists all of a user's subscriptions. ### Returns - `Subscription` - `id?: string` Subscription identifier tag. - `currency?: string` The monetary unit in which pricing information is displayed. - `current_period_end?: string` The end of the current period and also when the next billing is due. - `current_period_start?: string` When the current billing period started. May match initial_period_start if this is the first period. - `frequency?: "weekly" | "monthly" | "quarterly" | "yearly"` How often the subscription is renewed automatically. - `"weekly"` - `"monthly"` - `"quarterly"` - `"yearly"` - `price?: number` The price of the subscription that will be billed, in US dollars. - `rate_plan?: RatePlan` The rate plan applied to the subscription. - `id?: "free" | "lite" | "pro" | 7 more` The ID of the rate plan. - `"free"` - `"lite"` - `"pro"` - `"pro_plus"` - `"business"` - `"enterprise"` - `"partners_free"` - `"partners_pro"` - `"partners_business"` - `"partners_enterprise"` - `currency?: string` The currency applied to the rate plan subscription. - `externally_managed?: boolean` Whether this rate plan is managed externally from Cloudflare. - `is_contract?: boolean` Whether a rate plan is enterprise-based (or newly adopted term contract). - `public_name?: string` The full name of the rate plan. - `scope?: string` The scope that this rate plan applies to. - `sets?: Array` The list of sets this rate plan applies to. Returns array of strings. - `state?: "Trial" | "Provisioned" | "Paid" | 4 more` The state that the subscription is in. - `"Trial"` - `"Provisioned"` - `"Paid"` - `"AwaitingPayment"` - `"Cancelled"` - `"Failed"` - `"Expired"` ### Example ```node import Cloudflare from 'cloudflare'; const client = new Cloudflare({ apiToken: process.env['CLOUDFLARE_API_TOKEN'], // This is the default and can be omitted }); // Automatically fetches more pages as needed. for await (const subscription of client.user.subscriptions.get()) { console.log(subscription.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": "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(stringidentifier, SubscriptionUpdateParamsbody, RequestOptionsoptions?): SubscriptionUpdateResponse` **put** `/user/subscriptions/{identifier}` Updates a user's subscriptions. ### Parameters - `identifier: string` Subscription identifier tag. - `body: SubscriptionUpdateParams` - `frequency?: "weekly" | "monthly" | "quarterly" | "yearly"` How often the subscription is renewed automatically. - `"weekly"` - `"monthly"` - `"quarterly"` - `"yearly"` - `rate_plan?: RatePlan` The rate plan applied to the subscription. - `id?: "free" | "lite" | "pro" | 7 more` The ID of the rate plan. - `"free"` - `"lite"` - `"pro"` - `"pro_plus"` - `"business"` - `"enterprise"` - `"partners_free"` - `"partners_pro"` - `"partners_business"` - `"partners_enterprise"` - `currency?: string` The currency applied to the rate plan subscription. - `externally_managed?: boolean` Whether this rate plan is managed externally from Cloudflare. - `is_contract?: boolean` Whether a rate plan is enterprise-based (or newly adopted term contract). - `public_name?: string` The full name of the rate plan. - `scope?: string` The scope that this rate plan applies to. - `sets?: Array` The list of sets this rate plan applies to. Returns array of strings. ### Returns - `SubscriptionUpdateResponse = unknown | string | null` - `unknown` - `string | null` ### Example ```node import Cloudflare from 'cloudflare'; const client = new Cloudflare({ apiToken: process.env['CLOUDFLARE_API_TOKEN'], // This is the default and can be omitted }); const subscription = await client.user.subscriptions.update('506e3185e9c882d175a2d0cb0093d9f2'); console.log(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(stringidentifier, RequestOptionsoptions?): SubscriptionDeleteResponse` **delete** `/user/subscriptions/{identifier}` Deletes a user's subscription. ### Parameters - `identifier: string` Subscription identifier tag. ### Returns - `SubscriptionDeleteResponse` - `subscription_id?: string` Subscription identifier tag. ### Example ```node import Cloudflare from 'cloudflare'; const client = new Cloudflare({ apiToken: process.env['CLOUDFLARE_API_TOKEN'], // This is the default and can be omitted }); const subscription = await client.user.subscriptions.delete('506e3185e9c882d175a2d0cb0093d9f2'); console.log(subscription.subscription_id); ``` #### Response ```json { "subscription_id": "506e3185e9c882d175a2d0cb0093d9f2" } ``` ## Domain Types ### Subscription Update Response - `SubscriptionUpdateResponse = unknown | string | null` - `unknown` - `string | null` ### Subscription Delete Response - `SubscriptionDeleteResponse` - `subscription_id?: string` Subscription identifier tag. # Tokens ## List Tokens `client.user.tokens.list(TokenListParamsquery?, RequestOptionsoptions?): V4PagePaginationArray` **get** `/user/tokens` List all access tokens you created. ### Parameters - `query: TokenListParams` - `direction?: "asc" | "desc"` Direction to order results. - `"asc"` - `"desc"` - `page?: number` Page number of paginated results. - `per_page?: number` Maximum number of results per page. ### Returns - `Token` - `id?: string` Token identifier tag. - `condition?: Condition` - `request_ip?: RequestIP` Client IP restrictions. - `in?: Array` List of IPv4/IPv6 CIDR addresses. - `not_in?: Array` List of IPv4/IPv6 CIDR addresses. - `expires_on?: string` The expiration time on or after which the JWT MUST NOT be accepted for processing. - `issued_on?: string` The time on which the token was created. - `last_used_on?: string` Last time the token was used. - `modified_on?: string` Last time the token was modified. - `name?: string` Token name. - `not_before?: string` The time before which the token MUST NOT be accepted for processing. - `policies?: Array` List of access policies assigned to the token. - `id: string` Policy identifier. - `effect: "allow" | "deny"` Allow or deny operations against the resources. - `"allow"` - `"deny"` - `permission_groups: Array` A set of permission groups that are specified to the policy. - `id: string` Identifier of the permission group. - `meta?: Meta` Attributes associated to the permission group. - `key?: string` - `value?: string` - `name?: string` Name of the permission group. - `resources: Record | Record>` A list of resource names that the policy applies to. - `Record` - `Record>` - `status?: "active" | "disabled" | "expired"` Status of the token. - `"active"` - `"disabled"` - `"expired"` ### Example ```node import Cloudflare from 'cloudflare'; const client = new Cloudflare({ apiToken: process.env['CLOUDFLARE_API_TOKEN'], // This is the default and can be omitted }); // Automatically fetches more pages as needed. for await (const token of client.user.tokens.list()) { console.log(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" } ], "result_info": { "count": 1, "page": 1, "per_page": 20, "total_count": 2000 } } ``` ## Token Details `client.user.tokens.get(stringtokenId, RequestOptionsoptions?): Token` **get** `/user/tokens/{token_id}` Get information about a specific token. ### Parameters - `tokenId: string` Token identifier tag. ### Returns - `Token` - `id?: string` Token identifier tag. - `condition?: Condition` - `request_ip?: RequestIP` Client IP restrictions. - `in?: Array` List of IPv4/IPv6 CIDR addresses. - `not_in?: Array` List of IPv4/IPv6 CIDR addresses. - `expires_on?: string` The expiration time on or after which the JWT MUST NOT be accepted for processing. - `issued_on?: string` The time on which the token was created. - `last_used_on?: string` Last time the token was used. - `modified_on?: string` Last time the token was modified. - `name?: string` Token name. - `not_before?: string` The time before which the token MUST NOT be accepted for processing. - `policies?: Array` List of access policies assigned to the token. - `id: string` Policy identifier. - `effect: "allow" | "deny"` Allow or deny operations against the resources. - `"allow"` - `"deny"` - `permission_groups: Array` A set of permission groups that are specified to the policy. - `id: string` Identifier of the permission group. - `meta?: Meta` Attributes associated to the permission group. - `key?: string` - `value?: string` - `name?: string` Name of the permission group. - `resources: Record | Record>` A list of resource names that the policy applies to. - `Record` - `Record>` - `status?: "active" | "disabled" | "expired"` Status of the token. - `"active"` - `"disabled"` - `"expired"` ### Example ```node import Cloudflare from 'cloudflare'; const client = new Cloudflare({ apiToken: process.env['CLOUDFLARE_API_TOKEN'], // This is the default and can be omitted }); const token = await client.user.tokens.get('ed17574386854bf78a67040be0a770b0'); console.log(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.create(TokenCreateParamsbody, RequestOptionsoptions?): TokenCreateResponse` **post** `/user/tokens` Create a new access token. ### Parameters - `body: TokenCreateParams` - `name: string` Token name. - `policies: Array` List of access policies assigned to the token. - `id: string` Policy identifier. - `effect: "allow" | "deny"` Allow or deny operations against the resources. - `"allow"` - `"deny"` - `permission_groups: Array` A set of permission groups that are specified to the policy. - `id: string` Identifier of the permission group. - `meta?: Meta` Attributes associated to the permission group. - `key?: string` - `value?: string` - `name?: string` Name of the permission group. - `resources: Record | Record>` A list of resource names that the policy applies to. - `Record` - `Record>` - `condition?: Condition` - `request_ip?: RequestIP` Client IP restrictions. - `in?: Array` List of IPv4/IPv6 CIDR addresses. - `not_in?: Array` List of IPv4/IPv6 CIDR addresses. - `expires_on?: string` The expiration time on or after which the JWT MUST NOT be accepted for processing. - `not_before?: string` The time before which the token MUST NOT be accepted for processing. ### Returns - `TokenCreateResponse` - `id?: string` Token identifier tag. - `condition?: Condition` - `request_ip?: RequestIP` Client IP restrictions. - `in?: Array` List of IPv4/IPv6 CIDR addresses. - `not_in?: Array` List of IPv4/IPv6 CIDR addresses. - `expires_on?: string` The expiration time on or after which the JWT MUST NOT be accepted for processing. - `issued_on?: string` The time on which the token was created. - `last_used_on?: string` Last time the token was used. - `modified_on?: string` Last time the token was modified. - `name?: string` Token name. - `not_before?: string` The time before which the token MUST NOT be accepted for processing. - `policies?: Array` List of access policies assigned to the token. - `id: string` Policy identifier. - `effect: "allow" | "deny"` Allow or deny operations against the resources. - `"allow"` - `"deny"` - `permission_groups: Array` A set of permission groups that are specified to the policy. - `id: string` Identifier of the permission group. - `meta?: Meta` Attributes associated to the permission group. - `key?: string` - `value?: string` - `name?: string` Name of the permission group. - `resources: Record | Record>` A list of resource names that the policy applies to. - `Record` - `Record>` - `status?: "active" | "disabled" | "expired"` Status of the token. - `"active"` - `"disabled"` - `"expired"` - `value?: TokenValue` The token value. ### Example ```node import Cloudflare from 'cloudflare'; const client = new Cloudflare({ apiToken: process.env['CLOUDFLARE_API_TOKEN'], // This is the default and can be omitted }); const token = await client.user.tokens.create({ name: 'readonly token', policies: [ { effect: 'allow', permission_groups: [ { id: 'c8fed203ed3043cba015a93ad1616f1f' }, { id: '82e64a83756745bbbb1c9c2701bf816b' }, ], resources: { foo: 'string' }, }, ], }); console.log(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(stringtokenId, TokenUpdateParamsbody, RequestOptionsoptions?): Token` **put** `/user/tokens/{token_id}` Update an existing token. ### Parameters - `tokenId: string` Token identifier tag. - `body: TokenUpdateParams` - `name: string` Token name. - `policies: Array` List of access policies assigned to the token. - `id: string` Policy identifier. - `effect: "allow" | "deny"` Allow or deny operations against the resources. - `"allow"` - `"deny"` - `permission_groups: Array` A set of permission groups that are specified to the policy. - `id: string` Identifier of the permission group. - `meta?: Meta` Attributes associated to the permission group. - `key?: string` - `value?: string` - `name?: string` Name of the permission group. - `resources: Record | Record>` A list of resource names that the policy applies to. - `Record` - `Record>` - `condition?: Condition` - `request_ip?: RequestIP` Client IP restrictions. - `in?: Array` List of IPv4/IPv6 CIDR addresses. - `not_in?: Array` List of IPv4/IPv6 CIDR addresses. - `expires_on?: string` The expiration time on or after which the JWT MUST NOT be accepted for processing. - `not_before?: string` The time before which the token MUST NOT be accepted for processing. - `status?: "active" | "disabled" | "expired"` Status of the token. - `"active"` - `"disabled"` - `"expired"` ### Returns - `Token` - `id?: string` Token identifier tag. - `condition?: Condition` - `request_ip?: RequestIP` Client IP restrictions. - `in?: Array` List of IPv4/IPv6 CIDR addresses. - `not_in?: Array` List of IPv4/IPv6 CIDR addresses. - `expires_on?: string` The expiration time on or after which the JWT MUST NOT be accepted for processing. - `issued_on?: string` The time on which the token was created. - `last_used_on?: string` Last time the token was used. - `modified_on?: string` Last time the token was modified. - `name?: string` Token name. - `not_before?: string` The time before which the token MUST NOT be accepted for processing. - `policies?: Array` List of access policies assigned to the token. - `id: string` Policy identifier. - `effect: "allow" | "deny"` Allow or deny operations against the resources. - `"allow"` - `"deny"` - `permission_groups: Array` A set of permission groups that are specified to the policy. - `id: string` Identifier of the permission group. - `meta?: Meta` Attributes associated to the permission group. - `key?: string` - `value?: string` - `name?: string` Name of the permission group. - `resources: Record | Record>` A list of resource names that the policy applies to. - `Record` - `Record>` - `status?: "active" | "disabled" | "expired"` Status of the token. - `"active"` - `"disabled"` - `"expired"` ### Example ```node import Cloudflare from 'cloudflare'; const client = new Cloudflare({ apiToken: process.env['CLOUDFLARE_API_TOKEN'], // This is the default and can be omitted }); const token = await client.user.tokens.update('ed17574386854bf78a67040be0a770b0', { name: 'readonly token', policies: [ { effect: 'allow', permission_groups: [ { id: 'c8fed203ed3043cba015a93ad1616f1f' }, { id: '82e64a83756745bbbb1c9c2701bf816b' }, ], resources: { foo: 'string' }, }, ], }); console.log(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(stringtokenId, RequestOptionsoptions?): TokenDeleteResponse | null` **delete** `/user/tokens/{token_id}` Destroy a token. ### Parameters - `tokenId: string` Token identifier tag. ### Returns - `TokenDeleteResponse` - `id: string` Identifier ### Example ```node import Cloudflare from 'cloudflare'; const client = new Cloudflare({ apiToken: process.env['CLOUDFLARE_API_TOKEN'], // This is the default and can be omitted }); const token = await client.user.tokens.delete('ed17574386854bf78a67040be0a770b0'); console.log(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(RequestOptionsoptions?): TokenVerifyResponse` **get** `/user/tokens/verify` Test whether a token works. ### Returns - `TokenVerifyResponse` - `id: string` Token identifier tag. - `status: "active" | "disabled" | "expired"` Status of the token. - `"active"` - `"disabled"` - `"expired"` - `expires_on?: string` The expiration time on or after which the JWT MUST NOT be accepted for processing. - `not_before?: string` The time before which the token MUST NOT be accepted for processing. ### Example ```node import Cloudflare from 'cloudflare'; const client = new Cloudflare({ apiToken: process.env['CLOUDFLARE_API_TOKEN'], // This is the default and can be omitted }); const response = await client.user.tokens.verify(); console.log(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" } } ``` ## Domain Types ### Token Create Response - `TokenCreateResponse` - `id?: string` Token identifier tag. - `condition?: Condition` - `request_ip?: RequestIP` Client IP restrictions. - `in?: Array` List of IPv4/IPv6 CIDR addresses. - `not_in?: Array` List of IPv4/IPv6 CIDR addresses. - `expires_on?: string` The expiration time on or after which the JWT MUST NOT be accepted for processing. - `issued_on?: string` The time on which the token was created. - `last_used_on?: string` Last time the token was used. - `modified_on?: string` Last time the token was modified. - `name?: string` Token name. - `not_before?: string` The time before which the token MUST NOT be accepted for processing. - `policies?: Array` List of access policies assigned to the token. - `id: string` Policy identifier. - `effect: "allow" | "deny"` Allow or deny operations against the resources. - `"allow"` - `"deny"` - `permission_groups: Array` A set of permission groups that are specified to the policy. - `id: string` Identifier of the permission group. - `meta?: Meta` Attributes associated to the permission group. - `key?: string` - `value?: string` - `name?: string` Name of the permission group. - `resources: Record | Record>` A list of resource names that the policy applies to. - `Record` - `Record>` - `status?: "active" | "disabled" | "expired"` Status of the token. - `"active"` - `"disabled"` - `"expired"` - `value?: TokenValue` The token value. ### Token Delete Response - `TokenDeleteResponse` - `id: string` Identifier ### Token Verify Response - `TokenVerifyResponse` - `id: string` Token identifier tag. - `status: "active" | "disabled" | "expired"` Status of the token. - `"active"` - `"disabled"` - `"expired"` - `expires_on?: string` The expiration time on or after which the JWT MUST NOT be accepted for processing. - `not_before?: string` The time before which the token MUST NOT be accepted for processing. # Permission Groups ## List Token Permission Groups `client.user.tokens.permissionGroups.list(PermissionGroupListParamsquery?, RequestOptionsoptions?): SinglePage` **get** `/user/tokens/permission_groups` Find all available permission groups for API Tokens ### Parameters - `query: PermissionGroupListParams` - `name?: string` Filter by the name of the permission group. The value must be URL-encoded. - `scope?: string` Filter by the scope of the permission group. The value must be URL-encoded. ### Returns - `PermissionGroupListResponse` - `id?: string` Public ID. - `name?: string` Permission Group Name - `scopes?: Array<"com.cloudflare.api.account" | "com.cloudflare.api.account.zone" | "com.cloudflare.api.user" | "com.cloudflare.edge.r2.bucket">` Resources to which the Permission Group is scoped - `"com.cloudflare.api.account"` - `"com.cloudflare.api.account.zone"` - `"com.cloudflare.api.user"` - `"com.cloudflare.edge.r2.bucket"` ### Example ```node import Cloudflare from 'cloudflare'; const client = new Cloudflare({ apiToken: process.env['CLOUDFLARE_API_TOKEN'], // This is the default and can be omitted }); // Automatically fetches more pages as needed. for await (const permissionGroupListResponse of client.user.tokens.permissionGroups.list()) { console.log(permissionGroupListResponse.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": "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 } } ``` ## Domain Types ### Permission Group List Response - `PermissionGroupListResponse` - `id?: string` Public ID. - `name?: string` Permission Group Name - `scopes?: Array<"com.cloudflare.api.account" | "com.cloudflare.api.account.zone" | "com.cloudflare.api.user" | "com.cloudflare.edge.r2.bucket">` Resources to which the Permission Group is scoped - `"com.cloudflare.api.account"` - `"com.cloudflare.api.account.zone"` - `"com.cloudflare.api.user"` - `"com.cloudflare.edge.r2.bucket"` # Value ## Roll Token `client.user.tokens.value.update(stringtokenId, ValueUpdateParamsbody, RequestOptionsoptions?): TokenValue` **put** `/user/tokens/{token_id}/value` Roll the token secret. ### Parameters - `tokenId: string` Token identifier tag. - `body: ValueUpdateParams` - `body: unknown` ### Returns - `TokenValue = string` The token value. ### Example ```node import Cloudflare from 'cloudflare'; const client = new Cloudflare({ apiToken: process.env['CLOUDFLARE_API_TOKEN'], // This is the default and can be omitted }); const tokenValue = await client.user.tokens.value.update('ed17574386854bf78a67040be0a770b0', {}); console.log(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" } ```