> 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.

# Replace DNS firewall profiles on a service profile

PUT https://cdn.emnify.net/api/v1/service_profile/{service_profile_id}/dns_firewall_rule_set
Content-Type: application/json

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

`ServiceProfile.DnsFirewallRuleSet` + `Update` [+1 endpoint](/developers/api-guidelines/permission-endpoints#permission-serviceprofile-dnsfirewallruleset-update "This permission also grants 1 other endpoint")

*Roles:* Administrator

Replaces the set of DNS firewall profiles attached to a service profile.
Devices inherit their DNS firewall policy through their assigned service profile.
Passing an empty list removes all attached DNS firewall profiles.

Reference: https://docs.emnify.com/developers/api/service-profiles/service-profile-dns-firewall-rule-set-put

## 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

### Path parameters

- `service_profile_id` (double, required) — The Numeric ID of a Service Profile

### Body (application/json)

This endpoint expects an object.

- `dns_firewall_profiles` (list of integer, required) — List of DNS firewall profile IDs to attach to the service profile.

## Response

### 204

DNS firewall profiles successfully replaced on the service profile.

## Errors

### 401 Unauthorized Error

Missing or invalid Authorization header.

- `any`

### 403 Forbidden Error

User does not have permission to modify DNS firewall rule sets, or the feature is not enabled for the organization.

- `any`

### 404 Not Found Error

Service profile not found, or at least one of the DNS firewall profiles not found.

- `any`

### 409 Conflict Error

Conflict. See HTTP response body for details.

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

## Examples

### Replace DNS Firewall Profiles

**Request**

```json
{
  "dns_firewall_profiles": [
    10,
    11,
    12
  ]
}
```

**Response**

```json
{}
```

**SDK Code**

```python Replace DNS Firewall Profiles
import requests

url = "https://cdn.emnify.net/api/v1/service_profile/123/dns_firewall_rule_set"

payload = { "dns_firewall_profiles": [10, 11, 12] }
headers = {
    "Authorization": "Bearer <token>",
    "Content-Type": "application/json"
}

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

print(response.json())
```

```javascript Replace DNS Firewall Profiles
const url = 'https://cdn.emnify.net/api/v1/service_profile/123/dns_firewall_rule_set';
const options = {
  method: 'PUT',
  headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
  body: '{"dns_firewall_profiles":[10,11,12]}'
};

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

```go Replace DNS Firewall Profiles
package main

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

func main() {

	url := "https://cdn.emnify.net/api/v1/service_profile/123/dns_firewall_rule_set"

	payload := strings.NewReader("{\n  \"dns_firewall_profiles\": [\n    10,\n    11,\n    12\n  ]\n}")

	req, _ := http.NewRequest("PUT", 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 Replace DNS Firewall Profiles
require 'uri'
require 'net/http'

url = URI("https://cdn.emnify.net/api/v1/service_profile/123/dns_firewall_rule_set")

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

request = Net::HTTP::Put.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n  \"dns_firewall_profiles\": [\n    10,\n    11,\n    12\n  ]\n}"

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

```java Replace DNS Firewall Profiles
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.put("https://cdn.emnify.net/api/v1/service_profile/123/dns_firewall_rule_set")
  .header("Authorization", "Bearer <token>")
  .header("Content-Type", "application/json")
  .body("{\n  \"dns_firewall_profiles\": [\n    10,\n    11,\n    12\n  ]\n}")
  .asString();
```

```php Replace DNS Firewall Profiles
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('PUT', 'https://cdn.emnify.net/api/v1/service_profile/123/dns_firewall_rule_set', [
  'body' => '{
  "dns_firewall_profiles": [
    10,
    11,
    12
  ]
}',
  'headers' => [
    'Authorization' => 'Bearer <token>',
    'Content-Type' => 'application/json',
  ],
]);

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

```csharp Replace DNS Firewall Profiles
using RestSharp;

var client = new RestClient("https://cdn.emnify.net/api/v1/service_profile/123/dns_firewall_rule_set");
var request = new RestRequest(Method.PUT);
request.AddHeader("Authorization", "Bearer <token>");
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\n  \"dns_firewall_profiles\": [\n    10,\n    11,\n    12\n  ]\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift Replace DNS Firewall Profiles
import Foundation

let headers = [
  "Authorization": "Bearer <token>",
  "Content-Type": "application/json"
]
let parameters = ["dns_firewall_profiles": [10, 11, 12]] as [String : Any]

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

let request = NSMutableURLRequest(url: NSURL(string: "https://cdn.emnify.net/api/v1/service_profile/123/dns_firewall_rule_set")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "PUT"
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()
```

### Remove All DNS Firewall Profiles

**Request**

```json
{
  "dns_firewall_profiles": []
}
```

**Response**

```json
{}
```

**SDK Code**

```python Remove All DNS Firewall Profiles
import requests

url = "https://cdn.emnify.net/api/v1/service_profile/123/dns_firewall_rule_set"

payload = { "dns_firewall_profiles": [] }
headers = {
    "Authorization": "Bearer <token>",
    "Content-Type": "application/json"
}

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

print(response.json())
```

```javascript Remove All DNS Firewall Profiles
const url = 'https://cdn.emnify.net/api/v1/service_profile/123/dns_firewall_rule_set';
const options = {
  method: 'PUT',
  headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
  body: '{"dns_firewall_profiles":[]}'
};

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

```go Remove All DNS Firewall Profiles
package main

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

func main() {

	url := "https://cdn.emnify.net/api/v1/service_profile/123/dns_firewall_rule_set"

	payload := strings.NewReader("{\n  \"dns_firewall_profiles\": []\n}")

	req, _ := http.NewRequest("PUT", 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 Remove All DNS Firewall Profiles
require 'uri'
require 'net/http'

url = URI("https://cdn.emnify.net/api/v1/service_profile/123/dns_firewall_rule_set")

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

request = Net::HTTP::Put.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n  \"dns_firewall_profiles\": []\n}"

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

```java Remove All DNS Firewall Profiles
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.put("https://cdn.emnify.net/api/v1/service_profile/123/dns_firewall_rule_set")
  .header("Authorization", "Bearer <token>")
  .header("Content-Type", "application/json")
  .body("{\n  \"dns_firewall_profiles\": []\n}")
  .asString();
```

```php Remove All DNS Firewall Profiles
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('PUT', 'https://cdn.emnify.net/api/v1/service_profile/123/dns_firewall_rule_set', [
  'body' => '{
  "dns_firewall_profiles": []
}',
  'headers' => [
    'Authorization' => 'Bearer <token>',
    'Content-Type' => 'application/json',
  ],
]);

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

```csharp Remove All DNS Firewall Profiles
using RestSharp;

var client = new RestClient("https://cdn.emnify.net/api/v1/service_profile/123/dns_firewall_rule_set");
var request = new RestRequest(Method.PUT);
request.AddHeader("Authorization", "Bearer <token>");
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\n  \"dns_firewall_profiles\": []\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift Remove All DNS Firewall Profiles
import Foundation

let headers = [
  "Authorization": "Bearer <token>",
  "Content-Type": "application/json"
]
let parameters = ["dns_firewall_profiles": []] as [String : Any]

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

let request = NSMutableURLRequest(url: NSURL(string: "https://cdn.emnify.net/api/v1/service_profile/123/dns_firewall_rule_set")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "PUT"
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()
```