> For the complete documentation index, see [llms.txt](https://developer.rotsi.co.ke/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://developer.rotsi.co.ke/reference/api-reference/stk-push.md).

# STK Push

Once you/or business integrate with the RotsiAPI, you will be able to send a payment prompt on the customer's phone (STK Push Prompt) to your customer's M-PESA registered phone number

## Making an STK push

## Sim ToolKit.

<mark style="color:green;">`POST`</mark> <https://api.rotsi.co.ke/payments/stkPush/v1>

Make an STK Push Prompt to the Payer\`s phone number.

#### Request Body

| Name                                       | Type    | Description                                              |
| ------------------------------------------ | ------- | -------------------------------------------------------- |
| username<mark style="color:red;">\*</mark> | string  | The username of the account, as per the Rotsi Dashboard. |
| amount<mark style="color:red;">\*</mark>   | Integer | The amount of the transaction                            |
| phone<mark style="color:red;">\*</mark>    | string  | The phone number. USe the 254 format. Eg. 254722000000   |

{% tabs %}
{% tab title="JavaScript" %}

```javascript
const axios = require('axios');

const data = {
  amount: 1,
  phone: "254722000000",
  username: "username"
};

const config = {
  headers: {
    'Content-Type': 'application/json',
    'Authorization': 'secret_key'
  }
};

axios.post('https://api.rotsi.co.ke/payments/stkPush/v1', data, config)
  .then(response => {
    console.log(response.data);
  })
  .catch(error => {
    console.error(error);
  });
```

{% endtab %}

{% tab title="Python" %}

```python
import requests

url = "https://api.rotsi.co.ke/payments/stkPush/v1"
headers = {
    'Content-Type': 'application/json',
    'Authorization': 'secret_key'
}
data = {
    "amount": 1,
    "phone": "254722000000",
    "username": "username"
}

response = requests.post(url, headers=headers, json=data)
print(response.json())
```

{% endtab %}

{% tab title="Ruby" %}

```ruby
require 'net/http'
require 'uri'
require 'json'

uri = URI.parse("https://api.rotsi.co.ke/payments/stkPush/v1")
request = Net::HTTP::Post.new(uri)
request.content_type = "application/json"
request["Authorization"] = "secret_key"
request.body = JSON.dump({
  "amount" => 1,
  "phone" => "254722000000",
  "username" => "username"
})

response = Net::HTTP.start(uri.hostname, uri.port, use_ssl: uri.scheme == "https") do |http|
  http.request(request)
end

puts response.body

```

{% endtab %}

{% tab title="Java" %}

```java
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.nio.charset.StandardCharsets;

public class ApiRequest {
    public static void main(String[] args) {
        try {
            URL url = new URL("https://api.rotsi.co.ke/payments/stkPush/v1");
            HttpURLConnection connection = (HttpURLConnection) url.openConnection();
            connection.setRequestMethod("POST");
            connection.setRequestProperty("Content-Type", "application/json");
            connection.setRequestProperty("Authorization", "secret_key");
            connection.setDoOutput(true);

            String jsonInputString = "{\"amount\": 1, \"phone\": \"254722000000\", \"username\": \"username\"}";
            
            try(OutputStream os = connection.getOutputStream()) {
                byte[] input = jsonInputString.getBytes(StandardCharsets.UTF_8);
                os.write(input, 0, input.length);           
            }

            int code = connection.getResponseCode();
            System.out.println("Response Code: " + code);
            // Read response if needed

        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

```

{% endtab %}

{% tab title="PHP" %}

```php
<?php

$url = "https://api.rotsi.co.ke/payments/stkPush/v1";
$data = array(
    "amount" => 10
    "username" => "username",
    "phone" => "254722000000"
);
$headers = array(
    'Content-Type: application/json',
    'Authorization: secret_key'
);

$ch = curl_init($url);

curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));

$response = curl_exec($ch);

if (curl_errno($ch)) {
    echo 'Error:' . curl_error($ch);
} else {
    echo $response;
}

curl_close($ch);

?>
```

{% endtab %}

{% tab title="Curl" %}

```
curl -X POST \
  https://api.rotsi.co.ke/payments/stkPush/v1 \
  -H 'Content-Type: application/json' \
  -H 'Authorization: secret_key' \
  -d '{
    "amount": 1,
    "phone": "254722000000",
    "username": "username"
}'
```

{% endtab %}
{% endtabs %}

{% tabs %}
{% tab title="200 Pet successfully created" %}

<pre class="language-javascript"><code class="lang-javascript">{
<strong>    "status": "Success",
</strong>    "Service": "RotsiSTK",
    "RotsiAPITransactionId": STK719hcbjh2,
    "CustomerMessage": "The payment is successful"
}                          
</code></pre>

{% endtab %}

{% tab title="401 Permission denied" %}

```
{ 
"status": "Failed",
"Service": "RotsiSTK",
"message": "Payment request cancelled by the user",
"RotsiAPITransactionId": STK719hcbjh2,
}
```

{% endtab %}
{% endtabs %}
