How to get started with our api's
Our api's are json based and for you to make a successful call you have to generate an access token that expires after an hour.
var request = require('request'); var options = { 'method': 'GET', 'url': 'https://pam.api.easyncpay.com/api/v1/token', 'headers': { 'Content-Type': 'application/json', 'Accept': 'application/json', 'Authorization': 'Basic ACCOUNT_API_TOKEN' } }; request(options, function (error, response) { if (error) throw new Error(error); console.log(response.body); });
{ "data": { "Token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJodHRwczpcL1wvcGFtLmFwaS5lYXN5bmNwYXkuY29tXC9hcGlcL3YxXC90b2tlbiIsImlhdCI6MTYxNDU5NTI4MywiZXhwIjoxNjE0NTk4ODgzLCJuYmYiOjE2MTQ1OTUyODMsImp0aSI6IkYzVmpQNDJQb1ZjU0YycjIiLCJzdWIiOiI4OTczODllMy01ZjdjLTRhYjAtYjI2OS01YjFmNmI3NTM2NGEiLCJwcnYiOiI4N2UwYWYxZWY5ZmQxNTgxMmZkZWM5NzE1M2ExNGUwYjA0NzU0NmFhIn0.KWJbcAoIW6yF0IgCaylv7EqotDZnkXt5MvmuEZrjNbA", "TokenType": "Bearer", "Expires": 3600 }, "success": true }
Listing your linked paybill/till number
var request = require('request'); var options = { 'method': 'GET', 'url': 'https://pam.api.easyncpay.com/api/v1/shortcode', 'headers': { 'Accept': 'application/json', 'Content-Type': 'application/json' } }; request(options, function (error, response) { if (error) throw new Error(error); console.log(response.body); });
Listing all your apps.
var request = require('request'); var options = { 'method': 'GET', 'url': 'https://pam.api.easyncpay.com/api/v1/app', 'headers': { 'Accept': 'application/json' } }; request(options, function (error, response) { if (error) throw new Error(error); console.log(response.body); });
Listing all your latest transactions.
var request = require('request'); var options = { 'method': 'GET', 'url': 'https://pam.api.easyncpay.com/api/v1/pay-loads', 'headers': { 'Accept': 'application/json' } }; request(options, function (error, response) { if (error) throw new Error(error); console.log(response.body); });
Provide all the valid information to check if the paybill/till number credentials are valid.
var request = require('request'); var options = { 'method': 'POST', 'url': 'https://pam.api.easyncpay.com/api/v1/m-pesa/shortcode/validate', 'headers': { 'Accept': 'application/json', 'Content-Type': 'application/json' }, body: JSON.stringify({"ConsumerKey":"","ConsumerSecret":"","Environment":"sandbox/production"}) }; request(options, function (error, response) { if (error) throw new Error(error); console.log(response.body); });
{ "data": { "Message": "The m-pesa app keys are valid." }, "success": true }
Here register the confirm and validation url.
var request = require('request'); var options = { 'method': 'POST', 'url': 'https://pam.api.easyncpay.com/api/v1/m-pesa/c2b/register-url', 'headers': { 'Content-Type': 'application/json', 'Accept': 'application/json' }, body: JSON.stringify({"Secret":""}) }; request(options, function (error, response) { if (error) throw new Error(error); console.log(response.body); });
{ "data": { "Message": "Validation and Confirmation URLs are already registered" }, "success": true }
This section shows how to make stk push and callback data for both stk-push and lipa na mpesa.
var request = require('request'); var options = { 'method': 'POST', 'url': 'https://pam.api.easyncpay.com/api/v1/m-pesa/c2b/stk-push', 'headers': { 'Accept': 'application/json', 'Content-Type': 'application/json' }, body: JSON.stringify({"CallingCode":"254","Secret":"","PhoneNumber":"","Amount":"1","ResultUrl":"","Description":"Testing the PAM API","TransactionType":"CustomerPayBillOnline/CustomerBuyGoodsOnline"}) }; request(options, function (error, response) { if (error) throw new Error(error); console.log(response.body); });
"data": { "Success": true, "Description": "Transaction description.", "ReferenceNumber": "2BONOSBBTN", "PhoneNumber": "254XXXXXXXXX", "MpesaReceiptNumber": "PBO2ZOBY44", "Amount": 20000 }
"data": { "Success": true, "Description": "Transaction description.", "ReferenceNumber": "2BONOSBBTN", "PhoneNumber": "254XXXXXXXXX", "MpesaReceiptNumber": "PBO2ZOBY44", "Amount": 20000, 'TransactionType': 'Pay Bill' 'OrgAccountBalance': 50000 }
"data": { "Success": false, "Description": "Request cancelled by user", "ReferenceNumber": "2BOXRDNMLU", "PhoneNumber": "254XXXXXXXXX" }
This is where all the bulk payments are made.
var request = require('request'); var options = { 'method': 'POST', 'url': 'https://pam.api.easyncpay.com/api/v1/m-pesa/b2c', 'headers': { 'Content-Type': 'application/json', 'Accept': 'application/json' }, body: JSON.stringify({"CallingCode":"254","Secret":"","PhoneNumber":"","Amount":"10","ResultUrl":"","Description":"Testing the PAM API","TransactionType":"BusinessPayment/SalaryPayment/PromotionPayment"}) }; request(options, function (error, response) { if (error) throw new Error(error); console.log(response.body); });
"data": { 'Success' => true, 'Description' => 'Salary payment', 'ReferenceNumber' => '2BO6BCTLYF', 'PhoneNumber' => '254XXXXXXXXX', 'MpesaReceiptNumber' => 'PBO2ZOBY44', 'Amount' => 50000, 'B2CUtilityAccountAvailableFunds' => 70000, 'B2CWorkingAccountAvailableFunds' => 70000, 'B2CChargesPaidAccountAvailableFunds' => 70000 }
"data": { "Success": false, "Description": "The initiator information is invalid.", "ReferenceNumber": "2BO6BCTLYF", "PhoneNumber": "254XXXXXXXXX" }
To make your work easier for integration. We have developed libraries to get you started quicly.