# Create / Delete DNS record

## createDnsRecord()

Gets executed when a customer creates a dns record in the storefront.

### Parameters

<table><thead><tr><th width="142">Type</th><th width="166">Name</th><th>Description</th></tr></thead><tbody><tr><td>IpamRdnsHost </td><td>$ipamRdnsHost, </td><td>The DNS host</td></tr><tr><td>String</td><td>$zoneName</td><td>The zone name</td></tr><tr><td>DnsRecordItem </td><td>$dnsRecord</td><td>The DNS record class containing all information for dns record creation</td></tr></tbody></table>

### Response

No response.

Throwing an Exception() will display a generic error message:\
Throwing a StorefrontException() will display the exact message to the customer.

### Example Code

```php
public function createDnsRecord(IpamRdnsHost $ipamRdnsHost, string $zoneName, DnsRecordItem $dnsRecord) {
	$zoneName = $this->getZoneName($zoneName, $ipamRdnsHost);

	try {
		$response = $this->_sendRequest($ipamRdnsHost, "zones/{$zoneName}/dns_records", "POST", [
			"content" => $dnsRecord->content,
			"name" => $dnsRecord->hostname,
			"type" => $dnsRecord->type,
			"ttl" => $dnsRecord->ttl,
		]);

		return $response->result->id;
	} catch (ClientException $e) {
		throw new Exception($this->_getErrorMessage($e));
	}
}
```

### Testing

You can test this function by answering a ticket as a customer.

## deleteDnsRecord()

Gets executed when a customer deletes a dns record in the storefront.

The function is exactly the same as the creation.

### Example Code

```php
public function deleteDnsRecord(IpamRdnsHost $ipamRdnsHost, string $zoneName, DnsRecordItem $dnsRecord) {
	$zoneName = $this->getZoneName($zoneName, $ipamRdnsHost);

	try {
		$this->_sendRequest($ipamRdnsHost, "zones/{$zoneName}/dns_records/{$dnsRecord->id}", "DELETE");
	} catch (ClientException $e) {
		throw new Exception($this->_getErrorMessage($e));
	}
}
```
