> This page is for Developers.

> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://docs.emnify.com/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.emnify.com/_mcp/server.

# Create a DNS firewall profile

POST https://cdn.emnify.net/api/v1/dns_firewall_profile
Content-Type: application/json

**Required permissions** [Learn more](/developers/api-guidelines/permissions#how-permissions-work)

`DnsFirewallProfile` + `Create`

*Roles:* Administrator

Creates a new DNS firewall profile.

The provided `profile` content is validated before creation.
Rules use a line-oriented text format: `<ACTION> <NAME> [# COMMENT]`.
Supported actions are `ALLOW` and `DENY`.
Wildcards are supported only as a leading `*.`.
Internationalised (non-ASCII) names are accepted and normalized to Punycode before validation.
Rule order does not matter: when multiple rules match a domain, the most specific matching rule takes precedence (an exact name beats a wildcard, and a more specific wildcard beats a broader one).

If no rule matches, the effective default behavior is controlled by the service profile's DNS firewall mode:
`allowlist` denies unmatched queries, `blocklist` allows them.

Use the `dry_run` query parameter to validate the profile without persisting it.

Reference: https://docs.emnify.com/developers/api/dns-firewall-profile/dns-firewall-profile-create

## Authentication

- `Authorization` header (bearer token, required) — An `auth_token` should be provided to authenticate a session. To obtain an `auth_token`, see the [`/api/v1/authenticate` **POST** request](/developers/api/authentication/authenticate).

## Request

### Query parameters

- `dry_run` (boolean, optional, default: false) — When set to `true`, validates the profile rules without creating the profile. Returns validation results only.

### Body (application/json)

This endpoint expects an object.

- `name` (string, required) — Name of the DNS firewall profile.
- `profile` (string, required) — DNS firewall rules in line-oriented text format, one rule per line. Each rule follows the syntax: `<ACTION> <NAME> [# COMMENT]`.
- `profile_file_name` (string, required) — Original file name of the uploaded profile. Must end with `.txt`.
- `description` (string, optional) — Description of the DNS firewall profile.

## Response

### 200

Dry-run validation only (`dry_run=true` and validation succeeded)

- `validation_issues` (ApiV1DnsFirewallProfilePostResponsesContentApplicationJsonSchemaValidationIssues, optional)

### 201

DNS firewall profile successfully created

- `id` (integer, optional) — Unique identifier of the DNS firewall profile.
- `name` (string, optional) — Name of the DNS firewall profile.
- `description` (string, optional) — Description of the DNS firewall profile.
- `created` (string, optional) — Timestamp when the profile was created.
- `last_updated` (string, optional) — Timestamp when the profile was last modified.
- `last_uploaded` (string, optional) — Timestamp when the profile rules were last uploaded.
- `profile` (string, optional) — DNS firewall rules in line-oriented text format, one rule per line.
- `profile_file_name` (string, optional)
- `validation_issues` (ApiV1DnsFirewallProfilePostResponsesContentApplicationJsonSchemaValidationIssues, optional)

## Errors

### 400 Bad Request Error

Malformed JSON, invalid payload, or **profile validation failed**.

- `DNSFirewallProfileCreateRequestBadRequestError`
  - PostDNSFirewallProfileError: PostDNSFirewallProfileError
  - PostDNSFirewallProfileValidationFailed: PostDNSFirewallProfileValidationFailed

### 401 Unauthorized Error

Missing or invalid Authorization header.

- `error_code` (integer, optional)
- `error_token` (string, optional)
- `message` (string, optional)
- `errors` (list of ApiV1DnsFirewallProfilePostResponsesContentApplicationJsonSchemaErrorsItems, optional) — sub error descriptions

### 403 Forbidden Error

User doesn't have permission to create DNS firewall profiles, or the feature isn't enabled for the organization.

- `error_token` (string, required)
- `message` (string, required)
- `error_code` (integer, optional)
- `errors` (list of ApiV1DnsFirewallProfilePostResponsesContentApplicationJsonSchemaErrorsItems, optional) — sub error descriptions

### 409 Conflict Error

Conflict. See HTTP response body for details.

- `error_code` (integer, optional)
- `error_token` (string, optional)
- `message` (string, optional)

### 422 Unprocessable Entity Error

Unprocessable entity. The request shape is acceptable, but metadata fields such as `name`, `description`, or `profile_file_name` failed validation.

- `validation_issues` (ApiV1DnsFirewallProfilePostResponsesContentApplicationJsonSchemaValidationIssues, required)

## Types

### ApiV1DnsFirewallProfilePostResponsesContentApplicationJsonSchemaValidationIssues

- `valid` (boolean, optional)
- `message` (string, optional)

### PostDNSFirewallProfileError

- `error_token` (string, required)
- `message` (string, required)
- `error_code` (integer, optional)
- `errors` (list of ApiV1DnsFirewallProfilePostResponsesContentApplicationJsonSchemaOneOf0ErrorsItems, optional) — sub error descriptions

### PostDNSFirewallProfileValidationFailed

- `validation_issues` (ApiV1DnsFirewallProfilePostResponsesContentApplicationJsonSchemaOneOf1ValidationIssues, required)

### ApiV1DnsFirewallProfilePostResponsesContentApplicationJsonSchemaErrorsItems

### ApiV1DnsFirewallProfilePostResponsesContentApplicationJsonSchemaOneOf0ErrorsItems

### ApiV1DnsFirewallProfilePostResponsesContentApplicationJsonSchemaOneOf1ValidationIssues

- `valid` (boolean, optional)
- `message` (string, optional)
- `errors` (list of ApiV1DnsFirewallProfilePostResponsesContentApplicationJsonSchemaOneOf1ValidationIssuesErrorsItems, optional)
- `warnings` (list of ApiV1DnsFirewallProfilePostResponsesContentApplicationJsonSchemaOneOf1ValidationIssuesWarningsItems, optional)

### ApiV1DnsFirewallProfilePostResponsesContentApplicationJsonSchemaOneOf1ValidationIssuesErrorsItems

- `linenumber` (integer, optional)
- `field` (string, optional)
- `code` (string, optional)
- `msg` (string, optional)
- `params` (map from string to any, optional)

### ApiV1DnsFirewallProfilePostResponsesContentApplicationJsonSchemaOneOf1ValidationIssuesWarningsItems

- `linenumber` (integer, optional)
- `field` (string, optional)
- `code` (string, optional)
- `msg` (string, optional)
- `params` (map from string to any, optional)

## Examples

**Request**

```json
{
  "name": "corp-dns-policy",
  "profile": "ALLOW example.com\nALLOW *.example.com\nDENY phishing.example.test\n",
  "profile_file_name": "corp-dns-policy.txt",
  "description": "Corporate DNS firewall policy"
}
```

**Response**

```json
{
  "validation_issues": {
    "valid": true,
    "errors": [],
    "warnings": []
  },
  "created": "2026-07-07T08:15:00Z",
  "description": "Corporate DNS firewall policy",
  "id": 10,
  "last_updated": "2026-07-07T08:15:00Z",
  "last_uploaded": "2026-07-07T08:15:00Z",
  "name": "corp-dns-policy",
  "profile": "ALLOW example.com\nALLOW *.example.com\nDENY phishing.example.test\n",
  "profile_file_name": "corp-dns-policy.txt"
}
```

**SDK Code**

```python
import requests

url = "https://cdn.emnify.net/api/v1/dns_firewall_profile"

payload = {
    "name": "corp-dns-policy",
    "profile": "ALLOW example.com
ALLOW *.example.com
DENY phishing.example.test
",
    "profile_file_name": "corp-dns-policy.txt",
    "description": "Corporate DNS firewall policy"
}
headers = {
    "Authorization": "Bearer <token>",
    "Content-Type": "application/json"
}

response = requests.post(url, json=payload, headers=headers)

print(response.json())
```

```javascript
const url = 'https://cdn.emnify.net/api/v1/dns_firewall_profile';
const options = {
  method: 'POST',
  headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
  body: '{"name":"corp-dns-policy","profile":"ALLOW example.com\nALLOW *.example.com\nDENY phishing.example.test\n","profile_file_name":"corp-dns-policy.txt","description":"Corporate DNS firewall policy"}'
};

try {
  const response = await fetch(url, options);
  const data = await response.json();
  console.log(data);
} catch (error) {
  console.error(error);
}
```

```go
package main

import (
	"fmt"
	"strings"
	"net/http"
	"io"
)

func main() {

	url := "https://cdn.emnify.net/api/v1/dns_firewall_profile"

	payload := strings.NewReader("{\n  \"name\": \"corp-dns-policy\",\n  \"profile\": \"ALLOW example.com\\nALLOW *.example.com\\nDENY phishing.example.test\\n\",\n  \"profile_file_name\": \"corp-dns-policy.txt\",\n  \"description\": \"Corporate DNS firewall policy\"\n}")

	req, _ := http.NewRequest("POST", url, payload)

	req.Header.Add("Authorization", "Bearer <token>")
	req.Header.Add("Content-Type", "application/json")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(res)
	fmt.Println(string(body))

}
```

```ruby
require 'uri'
require 'net/http'

url = URI("https://cdn.emnify.net/api/v1/dns_firewall_profile")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n  \"name\": \"corp-dns-policy\",\n  \"profile\": \"ALLOW example.com\\nALLOW *.example.com\\nDENY phishing.example.test\\n\",\n  \"profile_file_name\": \"corp-dns-policy.txt\",\n  \"description\": \"Corporate DNS firewall policy\"\n}"

response = http.request(request)
puts response.read_body
```

```java
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.post("https://cdn.emnify.net/api/v1/dns_firewall_profile")
  .header("Authorization", "Bearer <token>")
  .header("Content-Type", "application/json")
  .body("{\n  \"name\": \"corp-dns-policy\",\n  \"profile\": \"ALLOW example.com\\nALLOW *.example.com\\nDENY phishing.example.test\\n\",\n  \"profile_file_name\": \"corp-dns-policy.txt\",\n  \"description\": \"Corporate DNS firewall policy\"\n}")
  .asString();
```

```php
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://cdn.emnify.net/api/v1/dns_firewall_profile', [
  'body' => '{
  "name": "corp-dns-policy",
  "profile": "ALLOW example.com\\nALLOW *.example.com\\nDENY phishing.example.test\\n",
  "profile_file_name": "corp-dns-policy.txt",
  "description": "Corporate DNS firewall policy"
}',
  'headers' => [
    'Authorization' => 'Bearer <token>',
    'Content-Type' => 'application/json',
  ],
]);

echo $response->getBody();
```

```csharp
using RestSharp;

var client = new RestClient("https://cdn.emnify.net/api/v1/dns_firewall_profile");
var request = new RestRequest(Method.POST);
request.AddHeader("Authorization", "Bearer <token>");
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\n  \"name\": \"corp-dns-policy\",\n  \"profile\": \"ALLOW example.com\\nALLOW *.example.com\\nDENY phishing.example.test\\n\",\n  \"profile_file_name\": \"corp-dns-policy.txt\",\n  \"description\": \"Corporate DNS firewall policy\"\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift
import Foundation

let headers = [
  "Authorization": "Bearer <token>",
  "Content-Type": "application/json"
]
let parameters = [
  "name": "corp-dns-policy",
  "profile": "ALLOW example.com
ALLOW *.example.com
DENY phishing.example.test
",
  "profile_file_name": "corp-dns-policy.txt",
  "description": "Corporate DNS firewall policy"
] as [String : Any]

let postData = JSONSerialization.data(withJSONObject: parameters, options: [])

let request = NSMutableURLRequest(url: NSURL(string: "https://cdn.emnify.net/api/v1/dns_firewall_profile")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "POST"
request.allHTTPHeaderFields = headers
request.httpBody = postData as Data

let session = URLSession.shared
let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in
  if (error != nil) {
    print(error as Any)
  } else {
    let httpResponse = response as? HTTPURLResponse
    print(httpResponse)
  }
})

dataTask.resume()
```