> This page is for version v1 (default).
> For other versions, use one of these documentation indexes:
> - v1 (default): https://docs.plextera.com/v-1/llms.txt

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

# Extract document

POST https://api.plextera.com/api/public/v1/document-insights/extractions
Content-Type: application/json

Creates an extraction from a File Service file or a document URL.

Workspace configuration determines routing and output fields.
See [Configuration, routing, and output](/guides/core-guides/document-extraction#configuration-routing-and-output) before sending `docType`.


Reference: https://docs.plextera.com/api/api-reference/document-insights/extract-document

## Authentication

- `Authorization` header (required) — Use the API key format: `api-key <token>`.

## Request

### Body (application/json)

This endpoint expects a CreateExtractRequest.

- `document` (CreateExtractRequestDocument, required) — Document source. Send either `fileId` for an existing Plextera file or `url` for a downloadable HTTPS document. For direct file upload, use POST /document-insights/extractions/upload.
- `labels` (map from string to string, optional) — Optional string key-value pairs. Custom labels are returned for correlation and do not affect extraction. The reserved `docType` label controls routing; use the exact value from the relevant Document Insights configuration in Plextera, or ask your workspace administrator or Plextera if you cannot find it. With default routing, omit `docType` but keep any custom correlation labels you need. Up to 50 labels; keys 1-64 characters; values 1-512 characters.

## Response

### 202

Extraction accepted and queued. Poll or subscribe for the result.

- `id` (string, optional) — Extraction identifier. Store this value for polling, feedback, and event correlation. Example: `69654f0bc073ef404baec649`.
- `status` (enum, optional) — Current processing state. `FAILED` covers routing, processing, or extracted-data validation problems. `REJECTED` covers document-level problems such as duplicate content or an unsupported language. Stop polling when the value is `COMPLETED`, `FAILED`, or `REJECTED`.
  - Allowed values: `QUEUED`, `PROCESSING`, `COMPLETED`, `FAILED`, `REJECTED`
- `outputAvailable` (boolean, optional) — `true` means the final `output` is ready and included in the extraction details or completed event payload.
- `createdAt` (datetime, optional) — UTC timestamp when Plextera accepted the extraction request. Example: `2026-04-07T10:05:04Z`.
- `updatedAt` (datetime, optional) — UTC timestamp of the latest known state change. Example: `2026-04-07T10:22:00Z`.
- `completedAt` (datetime, optional) — UTC timestamp when the extraction reached `COMPLETED`, `FAILED`, or `REJECTED`. Omitted while the extraction is still queued or processing.
- `error` (RunError, optional) — Failure or rejection details. Present only when `status` is `FAILED` or `REJECTED`.
- `labels` (map from string to string, optional) — String key-value pairs submitted with the extraction and returned for correlation.
- `document` (DocumentInsightsDocument, optional) — Summary of the source document that was processed.

## Errors

### 400 Bad Request Error

INVALID_REQUEST — The request is malformed: unreadable JSON, an invalid parameter value, or a bad multipart body.

- `error` (ApiError, optional) — Machine-readable error details shared by every error response.

### 401 Unauthorized Error

UNAUTHORIZED — The API key is missing, malformed, or revoked.

- `error` (ApiError, optional) — Machine-readable error details shared by every error response.

### 403 Forbidden Error

FORBIDDEN — The API key is valid but not allowed to perform this operation.

- `error` (ApiError, optional) — Machine-readable error details shared by every error response.

### 405 Method Not Allowed Error

METHOD_NOT_ALLOWED — The HTTP method is not supported for this path.

- `error` (ApiError, optional) — Machine-readable error details shared by every error response.

### 406 Not Acceptable Error

NOT_ACCEPTABLE — The requested response media type is not supported.

- `error` (ApiError, optional) — Machine-readable error details shared by every error response.

### 409 Conflict Error

CONFLICT — The request conflicts with existing state in an upstream Plextera service.

- `error` (ApiError, optional) — Machine-readable error details shared by every error response.

### 422 Unprocessable Entity Error

VALIDATION_FAILED — one or more request fields are invalid. See `details`.

- `error` (ApiError, optional) — Machine-readable error details shared by every error response.

### 429 Too Many Requests Error

RATE_LIMITED — Too many requests in a short window. 429 responses are enforced at the network edge; the body may be plain text instead of this envelope, so rely on the status code and the Retry-After header.

- `error` (ApiError, optional) — Machine-readable error details shared by every error response.

### 500 Internal Server Error

INTERNAL_ERROR — Unexpected failure inside Plextera. Retry with backoff; contact support with the requestId if it persists.

- `error` (ApiError, optional) — Machine-readable error details shared by every error response.

### 502 Bad Gateway Error

DOWNSTREAM_ERROR — A downstream Plextera service failed while handling the request. Retry with backoff.

- `error` (ApiError, optional) — Machine-readable error details shared by every error response.

## Types

### CreateExtractRequestDocument

Document source. Send either `fileId` for an existing Plextera file or `url` for a downloadable HTTPS document. For direct file upload, use POST /document-insights/extractions/upload.

### RunError

Terminal failure details. Present only for failed or rejected extractions and workflow runs.

- `code` (string, optional) — Stable machine-readable reason code. Document Insights returns `DOCUMENT_NOT_ROUTED` with `FAILED` for routing problems, `DOCUMENT_EXTRACTION_FAILED` with `FAILED` for processing or extracted-data validation problems, and `DOCUMENT_REJECTED` with `REJECTED` for document-level problems such as duplicate content or an unsupported language.
- `message` (string, optional) — Human-readable explanation of the failure or rejection.

### DocumentInsightsDocument

Document summary used inside Document Insights extraction and event payloads. Includes file metadata returned by File Service and page count returned by Document Insights; optional fields are omitted if the upstream service does not return them.

- `fileId` (string, optional) — Plextera File Service identifier for the source document.
- `fileName` (string, optional) — Source file name returned by File Service. Omitted when the upstream file record does not include a name.
- `mimeType` (string, optional) — Standard MIME media type of the source document, for example `application/pdf`. Omitted when Document Insights cannot determine the media type.
- `size` (long, optional) — Source document size in bytes returned by File Service. Omitted when file size is unavailable.
- `pageCount` (integer, optional) — Source document page count returned by Document Insights. Omitted when page count has not been computed.
- `contentUrl` (string, optional, nullable) — Short-lived pre-signed URL to download the source document directly from File Service. Returned only by Get extraction (`GET /extractions/{id}`); it is minted per request and expires, so use it promptly and do not store it. Omitted from List extractions responses and whenever the download URL cannot be resolved.

### ApiError

Machine-readable error details shared by every error response.

- `code` (string, optional) — Stable machine-readable error code. Branch your handling on this, not on `message`.
- `message` (string, optional) — Human-readable explanation. Wording may change; do not parse it.
- `requestId` (string, optional) — Unique request identifier, also returned in the X-Request-Id response header. Include it in support requests.
- `retryable` (boolean, optional) — True when retrying the same request later may succeed.
- `details` (list of ApiErrorDetail, optional) — Field-level validation issues. Present only for VALIDATION_FAILED.

### FileDocumentRef

Reference an existing file already stored in Plextera File Service.

- `fileId` (string, required) — Identifier returned by the Files API.

### UrlDocumentRef

Reference a document by HTTPS URL. Plextera downloads the file and stores it before extraction starts.

- `url` (string, required) — Publicly accessible HTTPS URL where Plextera can download the document. Embedded user credentials and URL fragments are not allowed.
- `fileName` (string, optional) — Optional file name to use when storing the downloaded document.

### ApiErrorDetail

Field-level validation issue.

- `field` (string, optional) — Name of the invalid request field.
- `issue` (string, optional) — What is wrong with the field value.

## Examples

### Queued extraction

**Response**

```json
{
  "id": "69654f0bc073ef404baec649",
  "status": "QUEUED",
  "outputAvailable": false,
  "createdAt": "2026-04-07T10:05:04Z",
  "updatedAt": "2026-04-07T10:05:04Z",
  "labels": {
    "customerDocumentId": "doc-42",
    "docType": "invoice"
  },
  "document": {
    "fileId": "file_01JY7M4ZVX5R1P3M3Q0TA1S7ZM",
    "fileName": "invoice.pdf",
    "mimeType": "application/pdf"
  }
}
```

**SDK Code**

```python Queued extraction
import requests

url = "https://api.plextera.com/api/public/v1/document-insights/extractions"

headers = {"Authorization": "<apiKey>"}

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

print(response.json())
```

```javascript Queued extraction
const url = 'https://api.plextera.com/api/public/v1/document-insights/extractions';
const options = {method: 'POST', headers: {Authorization: '<apiKey>'}};

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

```go Queued extraction
package main

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

func main() {

	url := "https://api.plextera.com/api/public/v1/document-insights/extractions"

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

	req.Header.Add("Authorization", "<apiKey>")

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

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

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

}
```

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

url = URI("https://api.plextera.com/api/public/v1/document-insights/extractions")

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

request = Net::HTTP::Post.new(url)
request["Authorization"] = '<apiKey>'

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

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

HttpResponse<String> response = Unirest.post("https://api.plextera.com/api/public/v1/document-insights/extractions")
  .header("Authorization", "<apiKey>")
  .asString();
```

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

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://api.plextera.com/api/public/v1/document-insights/extractions', [
  'headers' => [
    'Authorization' => '<apiKey>',
  ],
]);

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

```csharp Queued extraction
using RestSharp;

var client = new RestClient("https://api.plextera.com/api/public/v1/document-insights/extractions");
var request = new RestRequest(Method.POST);
request.AddHeader("Authorization", "<apiKey>");
IRestResponse response = client.Execute(request);
```

```swift Queued extraction
import Foundation

let headers = ["Authorization": "<apiKey>"]

let request = NSMutableURLRequest(url: NSURL(string: "https://api.plextera.com/api/public/v1/document-insights/extractions")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "POST"
request.allHTTPHeaderFields = headers

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()
```

### Existing file

**Request**

```json
{
  "document": {
    "fileId": "file_01JY7M4ZVX5R1P3M3Q0TA1S7ZM"
  },
  "labels": {
    "customerDocumentId": "doc-42",
    "docType": "YOUR_CONFIGURED_DOCUMENT_TYPE"
  }
}
```

**Response**

```json
{
  "id": "69654f0bc073ef404baec649",
  "status": "QUEUED",
  "outputAvailable": false,
  "createdAt": "2026-04-07T10:05:04Z",
  "updatedAt": "2026-04-07T10:05:04Z",
  "labels": {
    "customerDocumentId": "doc-42",
    "docType": "invoice"
  },
  "document": {
    "fileId": "file_01JY7M4ZVX5R1P3M3Q0TA1S7ZM",
    "fileName": "invoice.pdf",
    "mimeType": "application/pdf"
  }
}
```

**SDK Code**

```python Existing file
import requests

url = "https://api.plextera.com/api/public/v1/document-insights/extractions"

payload = {
    "document": { "fileId": "file_01JY7M4ZVX5R1P3M3Q0TA1S7ZM" },
    "labels": {
        "customerDocumentId": "doc-42",
        "docType": "YOUR_CONFIGURED_DOCUMENT_TYPE"
    }
}
headers = {
    "Authorization": "<apiKey>",
    "Content-Type": "application/json"
}

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

print(response.json())
```

```javascript Existing file
const url = 'https://api.plextera.com/api/public/v1/document-insights/extractions';
const options = {
  method: 'POST',
  headers: {Authorization: '<apiKey>', 'Content-Type': 'application/json'},
  body: '{"document":{"fileId":"file_01JY7M4ZVX5R1P3M3Q0TA1S7ZM"},"labels":{"customerDocumentId":"doc-42","docType":"YOUR_CONFIGURED_DOCUMENT_TYPE"}}'
};

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

```go Existing file
package main

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

func main() {

	url := "https://api.plextera.com/api/public/v1/document-insights/extractions"

	payload := strings.NewReader("{\n  \"document\": {\n    \"fileId\": \"file_01JY7M4ZVX5R1P3M3Q0TA1S7ZM\"\n  },\n  \"labels\": {\n    \"customerDocumentId\": \"doc-42\",\n    \"docType\": \"YOUR_CONFIGURED_DOCUMENT_TYPE\"\n  }\n}")

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

	req.Header.Add("Authorization", "<apiKey>")
	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 Existing file
require 'uri'
require 'net/http'

url = URI("https://api.plextera.com/api/public/v1/document-insights/extractions")

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

request = Net::HTTP::Post.new(url)
request["Authorization"] = '<apiKey>'
request["Content-Type"] = 'application/json'
request.body = "{\n  \"document\": {\n    \"fileId\": \"file_01JY7M4ZVX5R1P3M3Q0TA1S7ZM\"\n  },\n  \"labels\": {\n    \"customerDocumentId\": \"doc-42\",\n    \"docType\": \"YOUR_CONFIGURED_DOCUMENT_TYPE\"\n  }\n}"

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

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

HttpResponse<String> response = Unirest.post("https://api.plextera.com/api/public/v1/document-insights/extractions")
  .header("Authorization", "<apiKey>")
  .header("Content-Type", "application/json")
  .body("{\n  \"document\": {\n    \"fileId\": \"file_01JY7M4ZVX5R1P3M3Q0TA1S7ZM\"\n  },\n  \"labels\": {\n    \"customerDocumentId\": \"doc-42\",\n    \"docType\": \"YOUR_CONFIGURED_DOCUMENT_TYPE\"\n  }\n}")
  .asString();
```

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

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://api.plextera.com/api/public/v1/document-insights/extractions', [
  'body' => '{
  "document": {
    "fileId": "file_01JY7M4ZVX5R1P3M3Q0TA1S7ZM"
  },
  "labels": {
    "customerDocumentId": "doc-42",
    "docType": "YOUR_CONFIGURED_DOCUMENT_TYPE"
  }
}',
  'headers' => [
    'Authorization' => '<apiKey>',
    'Content-Type' => 'application/json',
  ],
]);

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

```csharp Existing file
using RestSharp;

var client = new RestClient("https://api.plextera.com/api/public/v1/document-insights/extractions");
var request = new RestRequest(Method.POST);
request.AddHeader("Authorization", "<apiKey>");
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\n  \"document\": {\n    \"fileId\": \"file_01JY7M4ZVX5R1P3M3Q0TA1S7ZM\"\n  },\n  \"labels\": {\n    \"customerDocumentId\": \"doc-42\",\n    \"docType\": \"YOUR_CONFIGURED_DOCUMENT_TYPE\"\n  }\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift Existing file
import Foundation

let headers = [
  "Authorization": "<apiKey>",
  "Content-Type": "application/json"
]
let parameters = [
  "document": ["fileId": "file_01JY7M4ZVX5R1P3M3Q0TA1S7ZM"],
  "labels": [
    "customerDocumentId": "doc-42",
    "docType": "YOUR_CONFIGURED_DOCUMENT_TYPE"
  ]
] as [String : Any]

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

let request = NSMutableURLRequest(url: NSURL(string: "https://api.plextera.com/api/public/v1/document-insights/extractions")! 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()
```

### Document URL

**Request**

```json
{
  "document": {
    "fileId": "file_01JY7M4ZVX5R1P3M3Q0TA1S7ZM",
    "fileName": "invoice.pdf",
    "url": "https://example.com/documents/invoice.pdf"
  },
  "labels": {
    "customerDocumentId": "doc-42"
  }
}
```

**Response**

```json
{
  "id": "69654f0bc073ef404baec649",
  "status": "QUEUED",
  "outputAvailable": false,
  "createdAt": "2026-04-07T10:05:04Z",
  "updatedAt": "2026-04-07T10:05:04Z",
  "labels": {
    "customerDocumentId": "doc-42",
    "docType": "invoice"
  },
  "document": {
    "fileId": "file_01JY7M4ZVX5R1P3M3Q0TA1S7ZM",
    "fileName": "invoice.pdf",
    "mimeType": "application/pdf"
  }
}
```

**SDK Code**

```python Document URL
import requests

url = "https://api.plextera.com/api/public/v1/document-insights/extractions"

payload = {
    "document": {
        "fileId": "file_01JY7M4ZVX5R1P3M3Q0TA1S7ZM",
        "fileName": "invoice.pdf",
        "url": "https://example.com/documents/invoice.pdf"
    },
    "labels": { "customerDocumentId": "doc-42" }
}
headers = {
    "Authorization": "<apiKey>",
    "Content-Type": "application/json"
}

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

print(response.json())
```

```javascript Document URL
const url = 'https://api.plextera.com/api/public/v1/document-insights/extractions';
const options = {
  method: 'POST',
  headers: {Authorization: '<apiKey>', 'Content-Type': 'application/json'},
  body: '{"document":{"fileId":"file_01JY7M4ZVX5R1P3M3Q0TA1S7ZM","fileName":"invoice.pdf","url":"https://example.com/documents/invoice.pdf"},"labels":{"customerDocumentId":"doc-42"}}'
};

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

```go Document URL
package main

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

func main() {

	url := "https://api.plextera.com/api/public/v1/document-insights/extractions"

	payload := strings.NewReader("{\n  \"document\": {\n    \"fileId\": \"file_01JY7M4ZVX5R1P3M3Q0TA1S7ZM\",\n    \"fileName\": \"invoice.pdf\",\n    \"url\": \"https://example.com/documents/invoice.pdf\"\n  },\n  \"labels\": {\n    \"customerDocumentId\": \"doc-42\"\n  }\n}")

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

	req.Header.Add("Authorization", "<apiKey>")
	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 Document URL
require 'uri'
require 'net/http'

url = URI("https://api.plextera.com/api/public/v1/document-insights/extractions")

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

request = Net::HTTP::Post.new(url)
request["Authorization"] = '<apiKey>'
request["Content-Type"] = 'application/json'
request.body = "{\n  \"document\": {\n    \"fileId\": \"file_01JY7M4ZVX5R1P3M3Q0TA1S7ZM\",\n    \"fileName\": \"invoice.pdf\",\n    \"url\": \"https://example.com/documents/invoice.pdf\"\n  },\n  \"labels\": {\n    \"customerDocumentId\": \"doc-42\"\n  }\n}"

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

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

HttpResponse<String> response = Unirest.post("https://api.plextera.com/api/public/v1/document-insights/extractions")
  .header("Authorization", "<apiKey>")
  .header("Content-Type", "application/json")
  .body("{\n  \"document\": {\n    \"fileId\": \"file_01JY7M4ZVX5R1P3M3Q0TA1S7ZM\",\n    \"fileName\": \"invoice.pdf\",\n    \"url\": \"https://example.com/documents/invoice.pdf\"\n  },\n  \"labels\": {\n    \"customerDocumentId\": \"doc-42\"\n  }\n}")
  .asString();
```

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

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://api.plextera.com/api/public/v1/document-insights/extractions', [
  'body' => '{
  "document": {
    "fileId": "file_01JY7M4ZVX5R1P3M3Q0TA1S7ZM",
    "fileName": "invoice.pdf",
    "url": "https://example.com/documents/invoice.pdf"
  },
  "labels": {
    "customerDocumentId": "doc-42"
  }
}',
  'headers' => [
    'Authorization' => '<apiKey>',
    'Content-Type' => 'application/json',
  ],
]);

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

```csharp Document URL
using RestSharp;

var client = new RestClient("https://api.plextera.com/api/public/v1/document-insights/extractions");
var request = new RestRequest(Method.POST);
request.AddHeader("Authorization", "<apiKey>");
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\n  \"document\": {\n    \"fileId\": \"file_01JY7M4ZVX5R1P3M3Q0TA1S7ZM\",\n    \"fileName\": \"invoice.pdf\",\n    \"url\": \"https://example.com/documents/invoice.pdf\"\n  },\n  \"labels\": {\n    \"customerDocumentId\": \"doc-42\"\n  }\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift Document URL
import Foundation

let headers = [
  "Authorization": "<apiKey>",
  "Content-Type": "application/json"
]
let parameters = [
  "document": [
    "fileId": "file_01JY7M4ZVX5R1P3M3Q0TA1S7ZM",
    "fileName": "invoice.pdf",
    "url": "https://example.com/documents/invoice.pdf"
  ],
  "labels": ["customerDocumentId": "doc-42"]
] as [String : Any]

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

let request = NSMutableURLRequest(url: NSURL(string: "https://api.plextera.com/api/public/v1/document-insights/extractions")! 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()
```