Host Partner Full Zone Set Up API Instructions

Use Case: Basic Cloudflare provisioning without control panel access. Applicable for providers that can’t leverage pre-built Cloudflare plugins such as website builders, ecommerce and platform providers.

 

1. Step - User creation
Start by creating a user using the `user_create` action on the Host API: https://www.cloudflare.com/docs/host-api.html#s3.2.1


The response will actually look something like this:


{

   "request": {

       "act": "user_create"

   },

   "response": {

       "cloudflare_email": "[email protected]",

       "user_key": "d5b67c0e77fd54482859be8ac7266ac2",

       "unique_id": "test_account_id",

       "user_api_key": "dc1fe5280bdd96f9acf08cd232f18f462a599"

   },

   "result": "success",

   "msg": null

}


Be sure to save both the `user_key` and `user_api_key`. The `user_key` will be used in the following step that interacts with the Host API. The `user_api_key` will be used for all subsequent steps.

 

2. Step - Full zone set
Then create a request to the `full_zone_set` action on the Host API. This action is not documented as part of the base Host API. It will associate the zone with your partner account.


The action should work like this curl request:


curl -s https://api.cloudflare.com/host-gw.html -d "host_key=$HOST_KEY" -d "user_key=$USER_KEY" -d "act=full_zone_set" -d "zone_name=$ZONE_NAME"


Note: The ‘user_key’ will be the user_key value from the initial user_create action.


The response from this call should be like the following JSON response:


{

   "request": {

       "act": "full_zone_set"

   },

   "response": {

       "act": "full_zone_set",

       "zone_name": "example.com",

       "jumpstart": true,

       "msg": "Have the user set their nameservers on their registrar to cruz.ns.cloudflare.com, greg.ns.cloudflare.com respectively to complete the zone signup process"

   },

   "result": "success",

   "msg": null

}


Note: The nameservers that the domain should point at will be in the “msg” section.

 

The zone is now registered in Cloudflare, but is likely missing or has inaccurate DNS information. You will need to create and verify all the necessary DNS zone records in Cloudflare.


3. Step - DNS zone records creation/verification

All of the following requests use our latest client API documented here: https://api.cloudflare.com/


This API will make calls to https://api.cloudflare.com/client/v4/ and the authentication headers should be on behalf of the end customer, so use the ‘user_api_key’ from the initial ‘user_create’ call and the user’s email address.

 

First step is to get the unique id for the zone (domain name).


This uses the ‘/zone’ endpoint documented here: https://api.cloudflare.com/#zone-list-zones


The ‘name’ should be set to the domain name, and this should return a response like the following:


{
 "success": true,
 "errors": [],
 "messages": [],
 "result": [
   {
     "id": "9a7806061c88ada191ed06f989cc3dac",
     "name": "example.com",
     "development_mode": 7200,
     "meta": {
       "wildcard_proxiable": false,
       "custom_certificate_quota": 1
     },
     "original_name_servers": [
       "ns1.originaldnshost.com",
       "ns2.originaldnshost.com"
     ],
     "original_registrar": "GoDaddy",
     "original_dnshost": "NameCheap",
     "created_on": "2014-01-01T05:20:00.12345Z",
     "modified_on": "2014-01-01T05:20:00.12345Z",
     "name_servers": [
       "tony.ns.cloudflare.com",
       "woz.ns.cloudflare.com"
     ],
     "owner": {
       "id": "9a7806061c88ada191ed06f989cc3dac",
       "email": "[email protected]",
       "owner_type": "user"
     },
     "permissions": [
       "#zone:read",
       "#zone:edit"
     ],
     "plan": {
       "id": "9a7806061c88ada191ed06f989cc3dac",
       "name": "Pro Plan",
       "price": 20,
       "currency": "USD",
       "frequency": "monthly",
       "is_subscribed": true,
       "can_subscribe": true
     },
     "status": "active",
     "paused": false,
     "type": "full"
   }
 ],
 "result_info": {
   "page": 1,
   "per_page": 20,
   "count": 1,
   "total_count": 2000
 }
}


This response gives you the `id` for the zone, which will be used in subsequent calls.


Note: This is a good way to also get the nameservers for Cloudflare if needed programatically.

 

Next, we will want to see what, if any, DNS records Cloudflare was able to detect for the domain. (This same call can be used at the end to verify that Cloudflare has all the necessary DNS records.)


The endpoint that will be called is `/zones/:zone_identifier/dns_records` and is documented here: https://api.cloudflare.com/#dns-records-for-a-zone-list-dns-records


The `:zone_identifier` should be updated with the `zone_id` from the previous step. If successful, you will get a response like the following:


{
 "success": true,
 "errors": [],
 "messages": [],
 "result": [
   {
     "id": "9a7806061c88ada191ed06f989cc3dac",
     "type": "A",
     "name": "example.com",
     "content": "1.2.3.4",
     "proxiable": true,
     "proxied": false,
     "ttl": 120,
     "locked": false,
     "zone_id": "9a7806061c88ada191ed06f989cc3dac",
     "zone_name": "example.com",
     "created_on": "2014-01-01T05:20:00.12345Z",
     "modified_on": "2014-01-01T05:20:00.12345Z",
     "data": {}
   }
 ],
 "result_info": {
   "page": 1,
   "per_page": 20,
   "count": 1,
   "total_count": 2000
 }
}

 

Finally, all DNS records for the zone will need to be added for the client.


4. Step - Adding DNS records for the zone

To add DNS records, use the same endpoint as above (`/zones/:zone_identifier/dns_records`) but use a POST request and add the necessary information as documented here: https://api.cloudflare.com/#dns-records-for-a-zone-create-dns-record


Successful record additions will receive a response like so:


{
 "success": true,
 "errors": [],
 "messages": [],
 "result": {
   "id": "9a7806061c88ada191ed06f989cc3dac",
   "type": "A",
   "name": "example.com",
   "content": "1.2.3.4",
   "proxiable": true,
   "proxied": false,
   "ttl": 120,
   "locked": false,
   "zone_id": "9a7806061c88ada191ed06f989cc3dac",
   "zone_name": "example.com",
   "created_on": "2014-01-01T05:20:00.12345Z",
   "modified_on": "2014-01-01T05:20:00.12345Z",
   "data": {}
 }
}

 

Once all records have been added, the domain should be updated at the registrar to point at Cloudflare’s nameservers. This will start the domain in using Cloudflare!

 

Still not finding what you need?

The Cloudflare team is here to help. 95% of questions can be answered using the search tool, but if you can’t find what you need, submit a support request.

Powered by Zendesk