This endpoint initializes a transaction on your link to a designated phone number.
Method | Endpoint |
---|---|
POST |
https://tinypesa.com/api/v1/express/initialize |
Header | Description | Value |
---|---|---|
Accept | The Accept request HTTP header advertises which content types, expressed as MIME types, the client can understand. | application/json |
|
|Apikey|Unique API key obtained from your admin link |Dfw3sdfx234F
|
The body required to initialize an STK transaction is the target phone number and amount as shown below. In a successful response, the request_id
is given for reference in the webhook as the TinyPesaID.
Parameter | Description | Sample value |
---|---|---|
amount | The amount to request your customer in KES | 100 |
msisdn | The phone number to charge this amount. | 0712345678 or 254712345678 |
account_no | [Optional] This is a custom reference sent over the webhook as ExternalReference. |
GADSF23FS |
Sample validation error response.
{
"amount": ["The amount field is required."],
"msisdn": ["The msisdn field is required."]
}
Sample success response.
{
"success": true,
"request_id": "f866567603d2b51ede711863d0f3d756deb08085393"
}
curl -X POST \
https://tinypesa.com/api/v1/express/initialize \
-H "Content-Type: application/x-www-form-urlencoded" \
-H "ApiKey: erwyuweoyf" \
-d 'amount=50&msisdn=0700034834&account_no=200'
const base_url = "https://tinypesa.com/api/v1/"
func initTransaction(){
formData := url.Values{
"amount": {10}, "msisdn": {"0712345678"},
}
client := &http.Client{}
req, err := http.NewRequest("POST", base_url+"express/initialize", strings.NewReader(formData.Encode()))
if err != nil {
panic(err.Error())
}
req.Header.Add("Accept", "application/json")
req.Header.Add("Apikey", "Dfw3sdfx234F")
response, err := client.Do(req)
if(err!=nil){
panic(err.Error())
}
/*
From the response retrieve the access token and use it in the valuations request
*/
}
<?php
$url="http://www.tinypesa.com/api/v1/express/initialize";
$data = array(
'amount' => 50,
'msisdn' => '0712345678',
'account_no'=>'200'
);
$headers = array(
"Content-Type: application/x-www-form-urlencoded",
"ApiKey: erwyuweoyf"
);
$options = array(
'http' => array(
'header' => $headers,
'method' => 'POST',
'content' => http_build_query($data)
)
);
$context = stream_context_create($options);
$resp = file_get_contents($url, false, $context);
var_dump($resp);
?>
var url = " https://tinypesa.com/api/v1/express/initialize";
fetch(url, {
body: "amount=50&msisdn=0700034834&account_no=200",
headers: {
Apikey: "erwyuweoyf",
"Content-Type": "application/x-www-form-urlencoded",
},
method: "POST",
});