This guide details the steps to help you to change your plan on Cloudflare using the Cloudflare API. You can always change your plan within the user interface of the Cloudflare portal, however, you may be looking to change your plans in bulk and that is where using the Cloudflare API makes more sense.
For the purposes of Cloudflare settings, a "zone" or "domain zone" is Cloudflare's naming convention for a "website" URL address.
To upgrade a domain to Cloudflare Enterprise using the API, you will need to go through a two step process.
This is required, as Cloudflare has specific Cloudflare plan IDs set up in the backend, so you will need to identify what your unique Cloudflare plan IDs are for your domain zone.
There is a unique ID for Free, Professional, Business and Enterprise plans for each of your domain zones.
Then you run the List Available Plans API within a Terminal (MacOS) or CommandPrompt (Windows).
curl -X GET "https://api.cloudflare.com/client/v4/zones/YOURZONEID/available_plans"
-H "X-Auth-Email: YOUREMAILADDRESS" <br> -H "X-Auth-Key: YOURAPIKEY(Global-Auth-Key)"
-H "Content-Type: application/json"
You will then receive an output for this "List Available Plans" API.
OUTPUT:
{"result":[<br>{"id":"UNIQUE-FREE-PLAN-ID","name":"Free Plan","price":0,"currency":"USD","frequency":"monthly",
"is_subscribed":false,"can_subscribe":true,"legacy_id":"free","legacy_discount":false,"externally_managed":false},
{"id":"UNIQUE-BUSINESS-PLAN-ID","name":"Business Plan","price":200,"currency":"USD","frequency":"monthly",
"is_subscribed":false,"can_subscribe":true,"legacy_id":"business","legacy_discount":false,"externally_managed":false},
{"id":"UNIQUE-PROFESSIONAL-PLAN-ID","name":"Professional Plan","price":20,"currency":"USD","frequency":"monthly",
"is_subscribed":false,"can_subscribe":true,"legacy_id":"pro","legacy_discount":false,"externally_managed":false},
{"id":"UNIQUE-ENTERPRISE-PLAN-ID","name":"Enterprise","price":0,"currency":"USD","frequency":"monthly",
"is_subscribed":false,"can_subscribe":false,"legacy_id":"enterprise","legacy_discount":false,"externally_managed":true}],"success":true,"errors":[],
"messages":[],"result_info":{"page":1,"per_page":25,"total_pages":1,"count":4,"total_count":4}}
Take note of the Unique Cloudflare Plan IDs here, and copy and paste the one you want to change your plan to.
Now we need to change the plan to that using the next API.
Change the domain zone plan using the Cloudflare "Edit Zone" API
curl -X PATCH "https://api.cloudflare.com/client/v4/zones/ZONEID"
-H "X-Auth-Email: YOUREMAILADDRESS"
-H "X-Auth-Key: YOURAPIKEY-Global-Auth-Key"
-H "Content-Type: application/json"
--data '{"plan":{"id":"INSERT-CLOUDFLARE-PLAN-ID-HERE"}}'
You will then receive an output for this Cloudflare "Edit Zone" API. It should look something like this but with your domain details.
{ "success": true, <br>"errors": [], <br>"messages": [],
"result": {
"id": "ZONE-ID", "name": "dejavuguides.com", "development_mode": 7200,
"original_name_servers": [ "ns1.dejavuguides.com", "ns2.dejavuguides.com" ], "original_registrar": "GoDaddy", "original_dnshost": "NameCheap",
"created_on": "2014-01-01T05:20:00.12345Z", "modified_on": "2014-01-01T05:20:00.12345Z", "activated_on": "2014-01-02T00:01:00.12345Z",
"owner": { "id": "OWNER-ID", "email": "user@example.com",
"type": "user" }, "account": { "id": "ACCOUNT-ID", "name": "Demo Account" },
"permissions": [ "#zone:read", "#zone:edit" ],
"plan": { "id": "CLOUDFLARE-PLAN-ID", "name": "Pro Plan", "price": 20, "currency": "USD",
"frequency": "monthly", "legacy_id": "pro",
"is_subscribed": true, "can_subscribe": true },
"plan_pending": { "id": "CLOUDFLARE-PLAN-ID", "name":
"Pro Plan", "price": 20, "currency": "USD", <br>"frequency": "monthly", "legacy_id": "pro", <br>"is_subscribed": true, "can_subscribe": true },
"status": "active", "paused": false, "type": "full",
"name_servers": [ "tony.ns.cloudflare.com", "woz.ns.cloudflare.com" ] } }
Then log into your Cloudflare dashboard and check if it has been changed to this new plan you have selected successfully.
Screenshots to help you: