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

# Initiate Bill Payment

POST http://localhost:8080/api/v3/transactions/pay-bill
Content-Type: application/json

Starts a bill payment from `walletId` (a PERSONAL or BUSINESS wallet). The body takes one of two shapes:

- **Biller from the catalogue**: `billProviderId` + `accountNumber`. The biller's payment method decides the route: `CHOICE_BILL` billers are paid through Choice's bill payment service (category `UTILITY_BILL`, with `dueAmount`/`dueDate` from Choice), and `MPESA_PAYBILL` billers go out as an M-Pesa Paybill payment to the biller's business number. `category`/`shortCode`/`referenceNumber` must be absent.
- **Manual M-Pesa Paybill/Till**: no `billProviderId`; `category` is `MPESA_PAYBILL` (requires `referenceNumber`) or `MPESA_TILL`, and `shortCode` is the paybill/till number.

`description` is only passed to M-Pesa payments. `dueAmount`/`dueDate` are null for M-Pesa payments. Next step: **Confirm Bill Payment** with the returned `transactionId`.

Reference: https://apidocs.sare.africa/sare-core-api/wallet/initiate-bill-payment

## Request

### Headers

- `Authorization` (string, optional)
- `X-Device-Id` (string, optional) — Required on non-GET requests to non-public paths (DeviceSignatureFilter), skipped for GET/whitelisted/multipart requests and in the local profile.
- `X-Signature` (string, optional) — Base64 ECDSA signature over sha256(body) + timestamp + requestId, signed with the device's registered private key.
- `X-Timestamp` (string, optional) — Unix epoch seconds; must be within 5 minutes of server time.
- `X-Request-Id` (string, optional) — Unique per request - reused values are rejected as replays.
- `Idempotency-Key` (string, optional)

### Body (application/json)

This endpoint expects an object.

- `walletId` (string, optional)
- `amount` (integer, optional)
- `billProviderId` (string, optional)
- `accountNumber` (string, optional)

## Response

### 200

200 OK (Catalogue Biller, Choice Bill Payment)

- `code` (integer, optional)
- `message` (string, optional)
- `data` (TransactionsPayBillPostResponsesContentApplicationJsonSchemaData, optional)

## Errors

### 400 Bad Request Error

400 Biller And Paybill Both Given

- `status` (integer, optional)
- `message` (string, optional)
- `path` (string, optional)

## Types

### TransactionsPayBillPostResponsesContentApplicationJsonSchemaData

- `transactionId` (string, optional)
- `walletId` (string, optional)
- `amount` (integer, optional)
- `fee` (integer, optional)
- `category` (string, optional)
- `destination` (string, optional)
- `recipientName` (any, optional)
- `status` (string, optional)
- `reference` (string, optional)
- `timestamp` (string, optional)
- `dueAmount` (integer, optional)
- `dueDate` (date, optional)

## Examples

### 200 OK (Catalogue Biller, Choice Bill Payment)

**Response**

```json
{
  "code": 200,
  "message": "Payment initiated.",
  "data": {
    "transactionId": "3c4d5e6f-7a8b-4c9d-8e0f-1a2b3c4d5e70",
    "walletId": "b1e7f6a0-9d2b-4a5b-9c3d-1a2b3c4d5e6f",
    "amount": 1250,
    "fee": 0,
    "category": "UTILITY_BILL",
    "destination": "1234567890",
    "status": "INITIATED",
    "reference": "UTL7K3M9QX",
    "timestamp": "2026-10-07 13:00:00",
    "dueAmount": 1250,
    "dueDate": "2026-10-15"
  }
}
```

**SDK Code**

```python 200 OK (Catalogue Biller, Choice Bill Payment)
import requests

url = "http://localhost:8080/api/v3/transactions/pay-bill"

headers = {
    "Authorization": "Bearer {{accessToken}}",
    "Idempotency-Key": "idem-{{$guid}}",
    "X-Device-Id": "{{deviceId}}",
    "X-Request-Id": "{{requestId}}",
    "X-Signature": "{{signature}}",
    "X-Timestamp": "{{timestamp}}"
}

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

print(response.json())
```

```javascript 200 OK (Catalogue Biller, Choice Bill Payment)
const url = 'http://localhost:8080/api/v3/transactions/pay-bill';
const options = {
  method: 'POST',
  headers: {
    Authorization: 'Bearer {{accessToken}}',
    'Idempotency-Key': 'idem-{{$guid}}',
    'X-Device-Id': '{{deviceId}}',
    'X-Request-Id': '{{requestId}}',
    'X-Signature': '{{signature}}',
    'X-Timestamp': '{{timestamp}}'
  }
};

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

```go 200 OK (Catalogue Biller, Choice Bill Payment)
package main

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

func main() {

	url := "http://localhost:8080/api/v3/transactions/pay-bill"

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

	req.Header.Add("Authorization", "Bearer {{accessToken}}")
	req.Header.Add("Idempotency-Key", "idem-{{$guid}}")
	req.Header.Add("X-Device-Id", "{{deviceId}}")
	req.Header.Add("X-Request-Id", "{{requestId}}")
	req.Header.Add("X-Signature", "{{signature}}")
	req.Header.Add("X-Timestamp", "{{timestamp}}")

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

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

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

}
```

```ruby 200 OK (Catalogue Biller, Choice Bill Payment)
require 'uri'
require 'net/http'

url = URI("http://localhost:8080/api/v3/transactions/pay-bill")

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

request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer {{accessToken}}'
request["Idempotency-Key"] = 'idem-{{$guid}}'
request["X-Device-Id"] = '{{deviceId}}'
request["X-Request-Id"] = '{{requestId}}'
request["X-Signature"] = '{{signature}}'
request["X-Timestamp"] = '{{timestamp}}'

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

```java 200 OK (Catalogue Biller, Choice Bill Payment)
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.post("http://localhost:8080/api/v3/transactions/pay-bill")
  .header("Authorization", "Bearer {{accessToken}}")
  .header("Idempotency-Key", "idem-{{$guid}}")
  .header("X-Device-Id", "{{deviceId}}")
  .header("X-Request-Id", "{{requestId}}")
  .header("X-Signature", "{{signature}}")
  .header("X-Timestamp", "{{timestamp}}")
  .asString();
```

```php 200 OK (Catalogue Biller, Choice Bill Payment)
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'http://localhost:8080/api/v3/transactions/pay-bill', [
  'headers' => [
    'Authorization' => 'Bearer {{accessToken}}',
    'Idempotency-Key' => 'idem-{{$guid}}',
    'X-Device-Id' => '{{deviceId}}',
    'X-Request-Id' => '{{requestId}}',
    'X-Signature' => '{{signature}}',
    'X-Timestamp' => '{{timestamp}}',
  ],
]);

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

```csharp 200 OK (Catalogue Biller, Choice Bill Payment)
using RestSharp;

var client = new RestClient("http://localhost:8080/api/v3/transactions/pay-bill");
var request = new RestRequest(Method.POST);
request.AddHeader("Authorization", "Bearer {{accessToken}}");
request.AddHeader("Idempotency-Key", "idem-{{$guid}}");
request.AddHeader("X-Device-Id", "{{deviceId}}");
request.AddHeader("X-Request-Id", "{{requestId}}");
request.AddHeader("X-Signature", "{{signature}}");
request.AddHeader("X-Timestamp", "{{timestamp}}");
IRestResponse response = client.Execute(request);
```

```swift 200 OK (Catalogue Biller, Choice Bill Payment)
import Foundation

let headers = [
  "Authorization": "Bearer {{accessToken}}",
  "Idempotency-Key": "idem-{{$guid}}",
  "X-Device-Id": "{{deviceId}}",
  "X-Request-Id": "{{requestId}}",
  "X-Signature": "{{signature}}",
  "X-Timestamp": "{{timestamp}}"
]

let request = NSMutableURLRequest(url: NSURL(string: "http://localhost:8080/api/v3/transactions/pay-bill")! 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()
```

### 200 OK (Manual M-Pesa Paybill)

**Response**

```json
{
  "code": 200,
  "message": "Payment initiated.",
  "data": {
    "transactionId": "1a2b3c4d-5e6f-4a7b-8c9d-0e1f2a3b4c5f",
    "walletId": "b1e7f6a0-9d2b-4a5b-9c3d-1a2b3c4d5e6f",
    "amount": 500,
    "fee": 0,
    "category": "MPESA_PAYBILL",
    "destination": "888880",
    "recipientName": null,
    "status": "INITIATED",
    "reference": "UTL4HN8RT2",
    "timestamp": "2026-10-07 13:00:00"
  }
}
```

**SDK Code**

```python 200 OK (Manual M-Pesa Paybill)
import requests

url = "http://localhost:8080/api/v3/transactions/pay-bill"

headers = {
    "Authorization": "Bearer {{accessToken}}",
    "Idempotency-Key": "idem-{{$guid}}",
    "X-Device-Id": "{{deviceId}}",
    "X-Request-Id": "{{requestId}}",
    "X-Signature": "{{signature}}",
    "X-Timestamp": "{{timestamp}}"
}

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

print(response.json())
```

```javascript 200 OK (Manual M-Pesa Paybill)
const url = 'http://localhost:8080/api/v3/transactions/pay-bill';
const options = {
  method: 'POST',
  headers: {
    Authorization: 'Bearer {{accessToken}}',
    'Idempotency-Key': 'idem-{{$guid}}',
    'X-Device-Id': '{{deviceId}}',
    'X-Request-Id': '{{requestId}}',
    'X-Signature': '{{signature}}',
    'X-Timestamp': '{{timestamp}}'
  }
};

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

```go 200 OK (Manual M-Pesa Paybill)
package main

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

func main() {

	url := "http://localhost:8080/api/v3/transactions/pay-bill"

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

	req.Header.Add("Authorization", "Bearer {{accessToken}}")
	req.Header.Add("Idempotency-Key", "idem-{{$guid}}")
	req.Header.Add("X-Device-Id", "{{deviceId}}")
	req.Header.Add("X-Request-Id", "{{requestId}}")
	req.Header.Add("X-Signature", "{{signature}}")
	req.Header.Add("X-Timestamp", "{{timestamp}}")

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

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

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

}
```

```ruby 200 OK (Manual M-Pesa Paybill)
require 'uri'
require 'net/http'

url = URI("http://localhost:8080/api/v3/transactions/pay-bill")

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

request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer {{accessToken}}'
request["Idempotency-Key"] = 'idem-{{$guid}}'
request["X-Device-Id"] = '{{deviceId}}'
request["X-Request-Id"] = '{{requestId}}'
request["X-Signature"] = '{{signature}}'
request["X-Timestamp"] = '{{timestamp}}'

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

```java 200 OK (Manual M-Pesa Paybill)
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.post("http://localhost:8080/api/v3/transactions/pay-bill")
  .header("Authorization", "Bearer {{accessToken}}")
  .header("Idempotency-Key", "idem-{{$guid}}")
  .header("X-Device-Id", "{{deviceId}}")
  .header("X-Request-Id", "{{requestId}}")
  .header("X-Signature", "{{signature}}")
  .header("X-Timestamp", "{{timestamp}}")
  .asString();
```

```php 200 OK (Manual M-Pesa Paybill)
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'http://localhost:8080/api/v3/transactions/pay-bill', [
  'headers' => [
    'Authorization' => 'Bearer {{accessToken}}',
    'Idempotency-Key' => 'idem-{{$guid}}',
    'X-Device-Id' => '{{deviceId}}',
    'X-Request-Id' => '{{requestId}}',
    'X-Signature' => '{{signature}}',
    'X-Timestamp' => '{{timestamp}}',
  ],
]);

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

```csharp 200 OK (Manual M-Pesa Paybill)
using RestSharp;

var client = new RestClient("http://localhost:8080/api/v3/transactions/pay-bill");
var request = new RestRequest(Method.POST);
request.AddHeader("Authorization", "Bearer {{accessToken}}");
request.AddHeader("Idempotency-Key", "idem-{{$guid}}");
request.AddHeader("X-Device-Id", "{{deviceId}}");
request.AddHeader("X-Request-Id", "{{requestId}}");
request.AddHeader("X-Signature", "{{signature}}");
request.AddHeader("X-Timestamp", "{{timestamp}}");
IRestResponse response = client.Execute(request);
```

```swift 200 OK (Manual M-Pesa Paybill)
import Foundation

let headers = [
  "Authorization": "Bearer {{accessToken}}",
  "Idempotency-Key": "idem-{{$guid}}",
  "X-Device-Id": "{{deviceId}}",
  "X-Request-Id": "{{requestId}}",
  "X-Signature": "{{signature}}",
  "X-Timestamp": "{{timestamp}}"
]

let request = NSMutableURLRequest(url: NSURL(string: "http://localhost:8080/api/v3/transactions/pay-bill")! 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()
```

### Wallet_initiateBillPayment_example

**Request**

```json
{
  "walletId": "b1e7f6a0-9d2b-4a5b-9c3d-1a2b3c4d5e6f",
  "amount": 1250,
  "billProviderId": "9a8b7c6d-5e4f-4a3b-8c2d-1e0f9a8b7c6d",
  "accountNumber": "1234567890"
}
```

**Response**

```json
{
  "code": 200,
  "message": "Payment initiated.",
  "data": {
    "transactionId": "3c4d5e6f-7a8b-4c9d-8e0f-1a2b3c4d5e70",
    "walletId": "b1e7f6a0-9d2b-4a5b-9c3d-1a2b3c4d5e6f",
    "amount": 1250,
    "fee": 0,
    "category": "UTILITY_BILL",
    "destination": "1234567890",
    "status": "INITIATED",
    "reference": "UTL7K3M9QX",
    "timestamp": "2026-10-07 13:00:00",
    "dueAmount": 1250,
    "dueDate": "2026-10-15"
  }
}
```

**SDK Code**

```python Wallet_initiateBillPayment_example
import requests

url = "http://localhost:8080/api/v3/transactions/pay-bill"

payload = {
    "walletId": "b1e7f6a0-9d2b-4a5b-9c3d-1a2b3c4d5e6f",
    "amount": 1250,
    "billProviderId": "9a8b7c6d-5e4f-4a3b-8c2d-1e0f9a8b7c6d",
    "accountNumber": "1234567890"
}
headers = {
    "Authorization": "Bearer {{accessToken}}",
    "Idempotency-Key": "idem-{{$guid}}",
    "X-Device-Id": "{{deviceId}}",
    "X-Request-Id": "{{requestId}}",
    "X-Signature": "{{signature}}",
    "X-Timestamp": "{{timestamp}}",
    "Content-Type": "application/json"
}

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

print(response.json())
```

```javascript Wallet_initiateBillPayment_example
const url = 'http://localhost:8080/api/v3/transactions/pay-bill';
const options = {
  method: 'POST',
  headers: {
    Authorization: 'Bearer {{accessToken}}',
    'Idempotency-Key': 'idem-{{$guid}}',
    'X-Device-Id': '{{deviceId}}',
    'X-Request-Id': '{{requestId}}',
    'X-Signature': '{{signature}}',
    'X-Timestamp': '{{timestamp}}',
    'Content-Type': 'application/json'
  },
  body: '{"walletId":"b1e7f6a0-9d2b-4a5b-9c3d-1a2b3c4d5e6f","amount":1250,"billProviderId":"9a8b7c6d-5e4f-4a3b-8c2d-1e0f9a8b7c6d","accountNumber":"1234567890"}'
};

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

```go Wallet_initiateBillPayment_example
package main

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

func main() {

	url := "http://localhost:8080/api/v3/transactions/pay-bill"

	payload := strings.NewReader("{\n  \"walletId\": \"b1e7f6a0-9d2b-4a5b-9c3d-1a2b3c4d5e6f\",\n  \"amount\": 1250,\n  \"billProviderId\": \"9a8b7c6d-5e4f-4a3b-8c2d-1e0f9a8b7c6d\",\n  \"accountNumber\": \"1234567890\"\n}")

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

	req.Header.Add("Authorization", "Bearer {{accessToken}}")
	req.Header.Add("Idempotency-Key", "idem-{{$guid}}")
	req.Header.Add("X-Device-Id", "{{deviceId}}")
	req.Header.Add("X-Request-Id", "{{requestId}}")
	req.Header.Add("X-Signature", "{{signature}}")
	req.Header.Add("X-Timestamp", "{{timestamp}}")
	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 Wallet_initiateBillPayment_example
require 'uri'
require 'net/http'

url = URI("http://localhost:8080/api/v3/transactions/pay-bill")

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

request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer {{accessToken}}'
request["Idempotency-Key"] = 'idem-{{$guid}}'
request["X-Device-Id"] = '{{deviceId}}'
request["X-Request-Id"] = '{{requestId}}'
request["X-Signature"] = '{{signature}}'
request["X-Timestamp"] = '{{timestamp}}'
request["Content-Type"] = 'application/json'
request.body = "{\n  \"walletId\": \"b1e7f6a0-9d2b-4a5b-9c3d-1a2b3c4d5e6f\",\n  \"amount\": 1250,\n  \"billProviderId\": \"9a8b7c6d-5e4f-4a3b-8c2d-1e0f9a8b7c6d\",\n  \"accountNumber\": \"1234567890\"\n}"

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

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

HttpResponse<String> response = Unirest.post("http://localhost:8080/api/v3/transactions/pay-bill")
  .header("Authorization", "Bearer {{accessToken}}")
  .header("Idempotency-Key", "idem-{{$guid}}")
  .header("X-Device-Id", "{{deviceId}}")
  .header("X-Request-Id", "{{requestId}}")
  .header("X-Signature", "{{signature}}")
  .header("X-Timestamp", "{{timestamp}}")
  .header("Content-Type", "application/json")
  .body("{\n  \"walletId\": \"b1e7f6a0-9d2b-4a5b-9c3d-1a2b3c4d5e6f\",\n  \"amount\": 1250,\n  \"billProviderId\": \"9a8b7c6d-5e4f-4a3b-8c2d-1e0f9a8b7c6d\",\n  \"accountNumber\": \"1234567890\"\n}")
  .asString();
```

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

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'http://localhost:8080/api/v3/transactions/pay-bill', [
  'body' => '{
  "walletId": "b1e7f6a0-9d2b-4a5b-9c3d-1a2b3c4d5e6f",
  "amount": 1250,
  "billProviderId": "9a8b7c6d-5e4f-4a3b-8c2d-1e0f9a8b7c6d",
  "accountNumber": "1234567890"
}',
  'headers' => [
    'Authorization' => 'Bearer {{accessToken}}',
    'Content-Type' => 'application/json',
    'Idempotency-Key' => 'idem-{{$guid}}',
    'X-Device-Id' => '{{deviceId}}',
    'X-Request-Id' => '{{requestId}}',
    'X-Signature' => '{{signature}}',
    'X-Timestamp' => '{{timestamp}}',
  ],
]);

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

```csharp Wallet_initiateBillPayment_example
using RestSharp;

var client = new RestClient("http://localhost:8080/api/v3/transactions/pay-bill");
var request = new RestRequest(Method.POST);
request.AddHeader("Authorization", "Bearer {{accessToken}}");
request.AddHeader("Idempotency-Key", "idem-{{$guid}}");
request.AddHeader("X-Device-Id", "{{deviceId}}");
request.AddHeader("X-Request-Id", "{{requestId}}");
request.AddHeader("X-Signature", "{{signature}}");
request.AddHeader("X-Timestamp", "{{timestamp}}");
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\n  \"walletId\": \"b1e7f6a0-9d2b-4a5b-9c3d-1a2b3c4d5e6f\",\n  \"amount\": 1250,\n  \"billProviderId\": \"9a8b7c6d-5e4f-4a3b-8c2d-1e0f9a8b7c6d\",\n  \"accountNumber\": \"1234567890\"\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift Wallet_initiateBillPayment_example
import Foundation

let headers = [
  "Authorization": "Bearer {{accessToken}}",
  "Idempotency-Key": "idem-{{$guid}}",
  "X-Device-Id": "{{deviceId}}",
  "X-Request-Id": "{{requestId}}",
  "X-Signature": "{{signature}}",
  "X-Timestamp": "{{timestamp}}",
  "Content-Type": "application/json"
]
let parameters = [
  "walletId": "b1e7f6a0-9d2b-4a5b-9c3d-1a2b3c4d5e6f",
  "amount": 1250,
  "billProviderId": "9a8b7c6d-5e4f-4a3b-8c2d-1e0f9a8b7c6d",
  "accountNumber": "1234567890"
] as [String : Any]

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

let request = NSMutableURLRequest(url: NSURL(string: "http://localhost:8080/api/v3/transactions/pay-bill")! 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()
```