Skip to content

CreateZoneExplained

Robin Brämer edited this page Feb 7, 2019 · 4 revisions

Create a Zone

There are multiple ways of creating a new Cloudflare request in this API/Library. In this example you create a new blocking CloudflareRequest pointing to the "create zone" endpoint and passing your CloudflareAccess instance.

  • As of the api documentation (https://api.cloudflare.com/#zone-create-zone) you need to pass the zone name (in this example robinbraemer.com).
  • Then as a response we get a Zone object returned which can automatically be serialized as Zone.class provided by the library.
  • Here we make use of the CloudflareCallback interface to handle success or any failure during the request.
new CloudflareRequest( Category.CREATE_ZONE, cloudflareAccess )
		.body( "name", "robinbraemer.com" )
		.asObject( new CloudflareCallback<CloudflareResponse<Zone>>() {
			@Override
			public void onSuccess( CloudflareResponse<Zone> r ) {
				// your code...
				System.out.println( r.getObject() );
			}
			
			@Override
			public void onFailure( Throwable t, int statusCode, String statusMessage, Map<Integer, String> errors ) {
				// your code...
				System.out.println( "Error creating zone: " + errors );
			}
		}, Zone.class );
Clone this wiki locally