> 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 IP firewall profiles on a service profile

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

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

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

*Roles:* Administrator

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

Reference: https://docs.emnify.com/developers/api/service-profiles/service-profile-ip-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

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

### Body (application/json)

This endpoint expects an object.

- `ip_firewall_profiles` (list of integer, required) — List of IP firewall profile IDs to attach to the service profile. An ID that appears more than once attaches the profile once.

## Response

### 204

IP firewall profiles successfully replaced on the service profile.

## Errors

### 401 Unauthorized Error

Missing or invalid Authorization header.

- `any`

### 403 Forbidden Error

User doesn't have permission to modify IP firewall rule sets, or the organization doesn't subscribe to the IP firewall.

- `any`

### 404 Not Found Error

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

- `any`

### 409 Conflict Error

The request lists more than 10 IP firewall profiles, or removes all profiles while the IP firewall is enforced on the service profile.

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

## Examples

### Replace IP Firewall Profiles

**Request**

```json
{
  "ip_firewall_profiles": [
    1,
    2,
    3
  ]
}
```

**Response**

```json
{}
```

**SDK Code**

```python Replace IP Firewall Profiles
import requests

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

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

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

print(response.json())
```

```javascript Replace IP Firewall Profiles
const url = 'https://cdn.emnify.net/api/v1/service_profile/123/ip_firewall_rule_set';
const options = {
  method: 'PUT',
  headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
  body: '{"ip_firewall_profiles":[1,2,3]}'
};

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

```go Replace IP Firewall Profiles
package main

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

func main() {

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

	payload := strings.NewReader("{\n  \"ip_firewall_profiles\": [\n    1,\n    2,\n    3\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 IP Firewall Profiles
require 'uri'
require 'net/http'

url = URI("https://cdn.emnify.net/api/v1/service_profile/123/ip_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  \"ip_firewall_profiles\": [\n    1,\n    2,\n    3\n  ]\n}"

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

```java Replace IP 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/ip_firewall_rule_set")
  .header("Authorization", "Bearer <token>")
  .header("Content-Type", "application/json")
  .body("{\n  \"ip_firewall_profiles\": [\n    1,\n    2,\n    3\n  ]\n}")
  .asString();
```

```php Replace IP 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/ip_firewall_rule_set', [
  'body' => '{
  "ip_firewall_profiles": [
    1,
    2,
    3
  ]
}',
  'headers' => [
    'Authorization' => 'Bearer <token>',
    'Content-Type' => 'application/json',
  ],
]);

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

```csharp Replace IP Firewall Profiles
using RestSharp;

var client = new RestClient("https://cdn.emnify.net/api/v1/service_profile/123/ip_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  \"ip_firewall_profiles\": [\n    1,\n    2,\n    3\n  ]\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift Replace IP Firewall Profiles
import Foundation

let headers = [
  "Authorization": "Bearer <token>",
  "Content-Type": "application/json"
]
let parameters = ["ip_firewall_profiles": [1, 2, 3]] 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/ip_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 IP Firewall Profiles

**Request**

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

**Response**

```json
{}
```

**SDK Code**

```python Remove All IP Firewall Profiles
import requests

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

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

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

print(response.json())
```

```javascript Remove All IP Firewall Profiles
const url = 'https://cdn.emnify.net/api/v1/service_profile/123/ip_firewall_rule_set';
const options = {
  method: 'PUT',
  headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
  body: '{"ip_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 IP Firewall Profiles
package main

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

func main() {

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

	payload := strings.NewReader("{\n  \"ip_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 IP Firewall Profiles
require 'uri'
require 'net/http'

url = URI("https://cdn.emnify.net/api/v1/service_profile/123/ip_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  \"ip_firewall_profiles\": []\n}"

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

```java Remove All IP 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/ip_firewall_rule_set")
  .header("Authorization", "Bearer <token>")
  .header("Content-Type", "application/json")
  .body("{\n  \"ip_firewall_profiles\": []\n}")
  .asString();
```

```php Remove All IP 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/ip_firewall_rule_set', [
  'body' => '{
  "ip_firewall_profiles": []
}',
  'headers' => [
    'Authorization' => 'Bearer <token>',
    'Content-Type' => 'application/json',
  ],
]);

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

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

var client = new RestClient("https://cdn.emnify.net/api/v1/service_profile/123/ip_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  \"ip_firewall_profiles\": []\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift Remove All IP Firewall Profiles
import Foundation

let headers = [
  "Authorization": "Bearer <token>",
  "Content-Type": "application/json"
]
let parameters = ["ip_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/ip_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()
```