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

# Bulk update endpoints

PATCH https://cdn.emnify.net/api/v2/endpoint/multi
Content-Type: application/json

Required permissions Beta [Learn more](/developers/api-guidelines/permissions#how-permissions-work)`Endpoint` + `Update` [+1 endpoint](/developers/api-guidelines/permission-endpoints#permission-endpoint-update "This permission also grants 1 other endpoint")Roles: Administrator UserUpdates details of a list of endpoints in bulk.The request body must be an array of endpoint objects.
Each object requires an `id` field to identify the endpoint, and you only need to include the fields you want to update.Unlike [`PATCH /api/v1/endpoint/{endpoint_id}`](/developers/api/endpoint/endpoint-by-id-patch), this bulk endpoint handles multiple endpoints safely in a single request without sequential execution constraints between individual endpoints.Changing any of these fields resets the device's connectivity: `service_profile`, `tariff_profile`, `status`, `ip_address`, `ip_address_space`, `imei`, `imei_lock`, or `sim`.
The network sends a `Cancel Location`, which ends the device's active data session, and the device must reconnect.
Other fields, such as `name`, `tags`, and `tag_assignments`, don't reset connectivity.The reset happens only for endpoints whose values change.
For example, an endpoint that already uses the target service policy doesn't reset.
Every changed endpoint in the request resets at the same time, so a bulk policy change can disconnect a whole fleet at once.
If you assign a SIM that belongs to another device, that device's connectivity resets too.Execute bulk operations sequentially - wait for each bulk request to complete before starting the next.emnify charges for activated SIMs, even if the endpoint status is set to **Disabled**.
To avoid accruing unexpected charges, update the SIM status to **Suspended** (`"id": 2`).

Reference: https://docs.emnify.com/developers/api/endpoint/bulk-update-endpoint

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

### Body (application/json)

This endpoint expects a list of ApiV2EndpointMultiPatchRequestBodyContentApplicationJsonSchemaItems.

- `list of ApiV2EndpointMultiPatchRequestBodyContentApplicationJsonSchemaItems`

## Response

### 204

Endpoints updated successfully

## Errors

### 400 Bad Request Error

Request body is malformed

- `any`

### 403 Forbidden Error

User doesn't have permission to bulk update endpoints

- `any`

### 404 Not Found Error

Appears in one of the following cases: - IP address space isn't found - IP address space is full

- `any`

### 422 Unprocessable Entity Error

Appears in one of the following cases: - Service profile is invalid - Tariff profile is invalid - Status is invalid - IP address space is invalid - IP address is invalid - SIM is invalid - Both `tags` and `tag_assignments` were provided

- `message` (string, required)
- `error_code` (double, required)
- `error_token` (string, required)
- `errors` (list of ApiV2EndpointMultiPatchResponsesContentApplicationJsonSchemaErrorsItems, required)

## Types

### ApiV2EndpointMultiPatchRequestBodyContentApplicationJsonSchemaItems

- `id` (integer, required) — The endpoint ID to update
- `name` (string, optional) — The endpoint name
- `tag_assignments` (list of integer, optional) — IDs of existing tags replacing the tags currently assigned to the endpoint. An empty array removes all tags. Mutually exclusive with `tags`. Provide at most one of the two.
- `imei` (string, optional) — The IMEI number
- `imei_lock` (boolean, optional) — Whether to lock the endpoint to this IMEI
- `ip_address` (string, optional) — The IP address to assign
- `ip_address_space` (ApiV2EndpointMultiPatchRequestBodyContentApplicationJsonSchemaItemsIpAddressSpace, optional) — Required when setting ip_address
- `service_profile` (ApiV2EndpointMultiPatchRequestBodyContentApplicationJsonSchemaItemsServiceProfile, optional)
- `tariff_profile` (ApiV2EndpointMultiPatchRequestBodyContentApplicationJsonSchemaItemsTariffProfile, optional)
- `status` (ApiV2EndpointMultiPatchRequestBodyContentApplicationJsonSchemaItemsStatus, optional) — Endpoint status: 0 (Enabled) or 1 (Disabled)
- `sim` (ApiV2EndpointMultiPatchRequestBodyContentApplicationJsonSchemaItemsSim, optional)
- `tags` (string, optional, nullable, deprecated) — Comma-separated tags replacing the tags currently assigned to the endpoint. Tags that don't exist yet are created, an empty string removes all tags. Sending `null` leaves the current tags unchanged, the same as omitting the field. Deprecated. Use `tag_assignments` instead.

### ApiV2EndpointMultiPatchResponsesContentApplicationJsonSchemaErrorsItems

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

### ApiV2EndpointMultiPatchRequestBodyContentApplicationJsonSchemaItemsIpAddressSpace

Required when setting ip_address

- `id` (integer, optional)

### ApiV2EndpointMultiPatchRequestBodyContentApplicationJsonSchemaItemsServiceProfile

- `id` (integer, optional)

### ApiV2EndpointMultiPatchRequestBodyContentApplicationJsonSchemaItemsTariffProfile

- `id` (integer, optional)

### ApiV2EndpointMultiPatchRequestBodyContentApplicationJsonSchemaItemsStatus

Endpoint status: 0 (Enabled) or 1 (Disabled)

- `id` (integer, optional)

### ApiV2EndpointMultiPatchRequestBodyContentApplicationJsonSchemaItemsSim

- `id` (integer, optional) — SIM ID to assign (set to null to unassign)
- `status` (ApiV2EndpointMultiPatchRequestBodyContentApplicationJsonSchemaItemsSimStatus, optional) — SIM status: 1 (Activated) or 5 (Factory Test)

### ApiV2EndpointMultiPatchRequestBodyContentApplicationJsonSchemaItemsSimStatus

SIM status: 1 (Activated) or 5 (Factory Test)

- `id` (integer, optional)

## Examples

### Update Specific Fields

**Request**

```json
[
  {
    "id": 123456,
    "name": "Updated endpoint name"
  },
  {
    "id": 987654,
    "tag_assignments": [
      1,
      2
    ]
  }
]
```

**Response**

```json
{}
```

**SDK Code**

```python Update Specific Fields
import requests

url = "https://cdn.emnify.net/api/v2/endpoint/multi"

payload = [
    {
        "id": 123456,
        "name": "Updated endpoint name"
    },
    {
        "id": 987654,
        "tag_assignments": [1, 2]
    }
]
headers = {
    "Authorization": "Bearer <token>",
    "Content-Type": "application/json"
}

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

print(response.json())
```

```javascript Update Specific Fields
const url = 'https://cdn.emnify.net/api/v2/endpoint/multi';
const options = {
  method: 'PATCH',
  headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
  body: '[{"id":123456,"name":"Updated endpoint name"},{"id":987654,"tag_assignments":[1,2]}]'
};

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

```go Update Specific Fields
package main

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

func main() {

	url := "https://cdn.emnify.net/api/v2/endpoint/multi"

	payload := strings.NewReader("[\n  {\n    \"id\": 123456,\n    \"name\": \"Updated endpoint name\"\n  },\n  {\n    \"id\": 987654,\n    \"tag_assignments\": [\n      1,\n      2\n    ]\n  }\n]")

	req, _ := http.NewRequest("PATCH", 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 Update Specific Fields
require 'uri'
require 'net/http'

url = URI("https://cdn.emnify.net/api/v2/endpoint/multi")

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

request = Net::HTTP::Patch.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "[\n  {\n    \"id\": 123456,\n    \"name\": \"Updated endpoint name\"\n  },\n  {\n    \"id\": 987654,\n    \"tag_assignments\": [\n      1,\n      2\n    ]\n  }\n]"

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

```java Update Specific Fields
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.patch("https://cdn.emnify.net/api/v2/endpoint/multi")
  .header("Authorization", "Bearer <token>")
  .header("Content-Type", "application/json")
  .body("[\n  {\n    \"id\": 123456,\n    \"name\": \"Updated endpoint name\"\n  },\n  {\n    \"id\": 987654,\n    \"tag_assignments\": [\n      1,\n      2\n    ]\n  }\n]")
  .asString();
```

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

$client = new \GuzzleHttp\Client();

$response = $client->request('PATCH', 'https://cdn.emnify.net/api/v2/endpoint/multi', [
  'body' => '[
  {
    "id": 123456,
    "name": "Updated endpoint name"
  },
  {
    "id": 987654,
    "tag_assignments": [
      1,
      2
    ]
  }
]',
  'headers' => [
    'Authorization' => 'Bearer <token>',
    'Content-Type' => 'application/json',
  ],
]);

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

```csharp Update Specific Fields
using RestSharp;

var client = new RestClient("https://cdn.emnify.net/api/v2/endpoint/multi");
var request = new RestRequest(Method.PATCH);
request.AddHeader("Authorization", "Bearer <token>");
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "[\n  {\n    \"id\": 123456,\n    \"name\": \"Updated endpoint name\"\n  },\n  {\n    \"id\": 987654,\n    \"tag_assignments\": [\n      1,\n      2\n    ]\n  }\n]", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift Update Specific Fields
import Foundation

let headers = [
  "Authorization": "Bearer <token>",
  "Content-Type": "application/json"
]
let parameters = [
  [
    "id": 123456,
    "name": "Updated endpoint name"
  ],
  [
    "id": 987654,
    "tag_assignments": [1, 2]
  ]
] as [String : Any]

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

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

### Update All Fields

**Request**

```json
[
  {
    "id": 123456,
    "name": "Test 1",
    "tag_assignments": [
      1,
      2
    ],
    "imei": "1234567890",
    "imei_lock": false,
    "ip_address": "127.0.0.1",
    "ip_address_space": {
      "id": 1
    },
    "service_profile": {
      "id": 2
    },
    "tariff_profile": {
      "id": 3
    },
    "status": {
      "id": 0
    },
    "sim": {
      "id": 1234567,
      "status": {
        "id": 1
      }
    }
  },
  {
    "id": 987654,
    "name": "Test 2",
    "tag_assignments": [
      1,
      2
    ],
    "imei": "1234567891",
    "imei_lock": false,
    "ip_address": "127.0.0.2",
    "ip_address_space": {
      "id": 1
    },
    "service_profile": {
      "id": 2
    },
    "tariff_profile": {
      "id": 3
    },
    "status": {
      "id": 0
    },
    "sim": {
      "id": 98765,
      "status": {
        "id": 1
      }
    }
  }
]
```

**Response**

```json
{}
```

**SDK Code**

```python Update All Fields
import requests

url = "https://cdn.emnify.net/api/v2/endpoint/multi"

payload = [
    {
        "id": 123456,
        "name": "Test 1",
        "tag_assignments": [1, 2],
        "imei": "1234567890",
        "imei_lock": False,
        "ip_address": "127.0.0.1",
        "ip_address_space": { "id": 1 },
        "service_profile": { "id": 2 },
        "tariff_profile": { "id": 3 },
        "status": { "id": 0 },
        "sim": {
            "id": 1234567,
            "status": { "id": 1 }
        }
    },
    {
        "id": 987654,
        "name": "Test 2",
        "tag_assignments": [1, 2],
        "imei": "1234567891",
        "imei_lock": False,
        "ip_address": "127.0.0.2",
        "ip_address_space": { "id": 1 },
        "service_profile": { "id": 2 },
        "tariff_profile": { "id": 3 },
        "status": { "id": 0 },
        "sim": {
            "id": 98765,
            "status": { "id": 1 }
        }
    }
]
headers = {
    "Authorization": "Bearer <token>",
    "Content-Type": "application/json"
}

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

print(response.json())
```

```javascript Update All Fields
const url = 'https://cdn.emnify.net/api/v2/endpoint/multi';
const options = {
  method: 'PATCH',
  headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
  body: '[{"id":123456,"name":"Test 1","tag_assignments":[1,2],"imei":"1234567890","imei_lock":false,"ip_address":"127.0.0.1","ip_address_space":{"id":1},"service_profile":{"id":2},"tariff_profile":{"id":3},"status":{"id":0},"sim":{"id":1234567,"status":{"id":1}}},{"id":987654,"name":"Test 2","tag_assignments":[1,2],"imei":"1234567891","imei_lock":false,"ip_address":"127.0.0.2","ip_address_space":{"id":1},"service_profile":{"id":2},"tariff_profile":{"id":3},"status":{"id":0},"sim":{"id":98765,"status":{"id":1}}}]'
};

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

```go Update All Fields
package main

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

func main() {

	url := "https://cdn.emnify.net/api/v2/endpoint/multi"

	payload := strings.NewReader("[\n  {\n    \"id\": 123456,\n    \"name\": \"Test 1\",\n    \"tag_assignments\": [\n      1,\n      2\n    ],\n    \"imei\": \"1234567890\",\n    \"imei_lock\": false,\n    \"ip_address\": \"127.0.0.1\",\n    \"ip_address_space\": {\n      \"id\": 1\n    },\n    \"service_profile\": {\n      \"id\": 2\n    },\n    \"tariff_profile\": {\n      \"id\": 3\n    },\n    \"status\": {\n      \"id\": 0\n    },\n    \"sim\": {\n      \"id\": 1234567,\n      \"status\": {\n        \"id\": 1\n      }\n    }\n  },\n  {\n    \"id\": 987654,\n    \"name\": \"Test 2\",\n    \"tag_assignments\": [\n      1,\n      2\n    ],\n    \"imei\": \"1234567891\",\n    \"imei_lock\": false,\n    \"ip_address\": \"127.0.0.2\",\n    \"ip_address_space\": {\n      \"id\": 1\n    },\n    \"service_profile\": {\n      \"id\": 2\n    },\n    \"tariff_profile\": {\n      \"id\": 3\n    },\n    \"status\": {\n      \"id\": 0\n    },\n    \"sim\": {\n      \"id\": 98765,\n      \"status\": {\n        \"id\": 1\n      }\n    }\n  }\n]")

	req, _ := http.NewRequest("PATCH", 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 Update All Fields
require 'uri'
require 'net/http'

url = URI("https://cdn.emnify.net/api/v2/endpoint/multi")

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

request = Net::HTTP::Patch.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "[\n  {\n    \"id\": 123456,\n    \"name\": \"Test 1\",\n    \"tag_assignments\": [\n      1,\n      2\n    ],\n    \"imei\": \"1234567890\",\n    \"imei_lock\": false,\n    \"ip_address\": \"127.0.0.1\",\n    \"ip_address_space\": {\n      \"id\": 1\n    },\n    \"service_profile\": {\n      \"id\": 2\n    },\n    \"tariff_profile\": {\n      \"id\": 3\n    },\n    \"status\": {\n      \"id\": 0\n    },\n    \"sim\": {\n      \"id\": 1234567,\n      \"status\": {\n        \"id\": 1\n      }\n    }\n  },\n  {\n    \"id\": 987654,\n    \"name\": \"Test 2\",\n    \"tag_assignments\": [\n      1,\n      2\n    ],\n    \"imei\": \"1234567891\",\n    \"imei_lock\": false,\n    \"ip_address\": \"127.0.0.2\",\n    \"ip_address_space\": {\n      \"id\": 1\n    },\n    \"service_profile\": {\n      \"id\": 2\n    },\n    \"tariff_profile\": {\n      \"id\": 3\n    },\n    \"status\": {\n      \"id\": 0\n    },\n    \"sim\": {\n      \"id\": 98765,\n      \"status\": {\n        \"id\": 1\n      }\n    }\n  }\n]"

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

```java Update All Fields
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.patch("https://cdn.emnify.net/api/v2/endpoint/multi")
  .header("Authorization", "Bearer <token>")
  .header("Content-Type", "application/json")
  .body("[\n  {\n    \"id\": 123456,\n    \"name\": \"Test 1\",\n    \"tag_assignments\": [\n      1,\n      2\n    ],\n    \"imei\": \"1234567890\",\n    \"imei_lock\": false,\n    \"ip_address\": \"127.0.0.1\",\n    \"ip_address_space\": {\n      \"id\": 1\n    },\n    \"service_profile\": {\n      \"id\": 2\n    },\n    \"tariff_profile\": {\n      \"id\": 3\n    },\n    \"status\": {\n      \"id\": 0\n    },\n    \"sim\": {\n      \"id\": 1234567,\n      \"status\": {\n        \"id\": 1\n      }\n    }\n  },\n  {\n    \"id\": 987654,\n    \"name\": \"Test 2\",\n    \"tag_assignments\": [\n      1,\n      2\n    ],\n    \"imei\": \"1234567891\",\n    \"imei_lock\": false,\n    \"ip_address\": \"127.0.0.2\",\n    \"ip_address_space\": {\n      \"id\": 1\n    },\n    \"service_profile\": {\n      \"id\": 2\n    },\n    \"tariff_profile\": {\n      \"id\": 3\n    },\n    \"status\": {\n      \"id\": 0\n    },\n    \"sim\": {\n      \"id\": 98765,\n      \"status\": {\n        \"id\": 1\n      }\n    }\n  }\n]")
  .asString();
```

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

$client = new \GuzzleHttp\Client();

$response = $client->request('PATCH', 'https://cdn.emnify.net/api/v2/endpoint/multi', [
  'body' => '[
  {
    "id": 123456,
    "name": "Test 1",
    "tag_assignments": [
      1,
      2
    ],
    "imei": "1234567890",
    "imei_lock": false,
    "ip_address": "127.0.0.1",
    "ip_address_space": {
      "id": 1
    },
    "service_profile": {
      "id": 2
    },
    "tariff_profile": {
      "id": 3
    },
    "status": {
      "id": 0
    },
    "sim": {
      "id": 1234567,
      "status": {
        "id": 1
      }
    }
  },
  {
    "id": 987654,
    "name": "Test 2",
    "tag_assignments": [
      1,
      2
    ],
    "imei": "1234567891",
    "imei_lock": false,
    "ip_address": "127.0.0.2",
    "ip_address_space": {
      "id": 1
    },
    "service_profile": {
      "id": 2
    },
    "tariff_profile": {
      "id": 3
    },
    "status": {
      "id": 0
    },
    "sim": {
      "id": 98765,
      "status": {
        "id": 1
      }
    }
  }
]',
  'headers' => [
    'Authorization' => 'Bearer <token>',
    'Content-Type' => 'application/json',
  ],
]);

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

```csharp Update All Fields
using RestSharp;

var client = new RestClient("https://cdn.emnify.net/api/v2/endpoint/multi");
var request = new RestRequest(Method.PATCH);
request.AddHeader("Authorization", "Bearer <token>");
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "[\n  {\n    \"id\": 123456,\n    \"name\": \"Test 1\",\n    \"tag_assignments\": [\n      1,\n      2\n    ],\n    \"imei\": \"1234567890\",\n    \"imei_lock\": false,\n    \"ip_address\": \"127.0.0.1\",\n    \"ip_address_space\": {\n      \"id\": 1\n    },\n    \"service_profile\": {\n      \"id\": 2\n    },\n    \"tariff_profile\": {\n      \"id\": 3\n    },\n    \"status\": {\n      \"id\": 0\n    },\n    \"sim\": {\n      \"id\": 1234567,\n      \"status\": {\n        \"id\": 1\n      }\n    }\n  },\n  {\n    \"id\": 987654,\n    \"name\": \"Test 2\",\n    \"tag_assignments\": [\n      1,\n      2\n    ],\n    \"imei\": \"1234567891\",\n    \"imei_lock\": false,\n    \"ip_address\": \"127.0.0.2\",\n    \"ip_address_space\": {\n      \"id\": 1\n    },\n    \"service_profile\": {\n      \"id\": 2\n    },\n    \"tariff_profile\": {\n      \"id\": 3\n    },\n    \"status\": {\n      \"id\": 0\n    },\n    \"sim\": {\n      \"id\": 98765,\n      \"status\": {\n        \"id\": 1\n      }\n    }\n  }\n]", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift Update All Fields
import Foundation

let headers = [
  "Authorization": "Bearer <token>",
  "Content-Type": "application/json"
]
let parameters = [
  [
    "id": 123456,
    "name": "Test 1",
    "tag_assignments": [1, 2],
    "imei": "1234567890",
    "imei_lock": false,
    "ip_address": "127.0.0.1",
    "ip_address_space": ["id": 1],
    "service_profile": ["id": 2],
    "tariff_profile": ["id": 3],
    "status": ["id": 0],
    "sim": [
      "id": 1234567,
      "status": ["id": 1]
    ]
  ],
  [
    "id": 987654,
    "name": "Test 2",
    "tag_assignments": [1, 2],
    "imei": "1234567891",
    "imei_lock": false,
    "ip_address": "127.0.0.2",
    "ip_address_space": ["id": 1],
    "service_profile": ["id": 2],
    "tariff_profile": ["id": 3],
    "status": ["id": 0],
    "sim": [
      "id": 98765,
      "status": ["id": 1]
    ]
  ]
] as [String : Any]

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

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