Language

Step 1: Obtain an application access token

Your application will need to exchange its client_id, client_secret, and grant_type=client_credentials for an application access token. With this token, you can then make API requests to the Kopo Kopo API.

Step 2: Polling Transactions

To make the following request, we need to use the access_token we just previously obtained. Security considerations:

POST https://sandbox.kopokopo.com/api/v1/polling
Content-Type: application/json
Accept: application/json
Authorization: Bearer < AccessToken >
{
  "scope": "company",
  "scope_reference": "",
  "from_time": "2021-04-12T08:50:22+03:00",
  "to_time": "2021-04-19T08:50:22+03:00",
  "_links": {
      "callback_url": "https://callback_to_your_app.your_application.com"
  }
}
# Using K2Connect - https://github.com/kopokopo/k2-connect-ruby (Recommended)
your_input =
{
  scope: "company",
  scope_reference: "",
  from_time: "2021-04-12T08:50:22+03:00",
  to_time: "2021-04-19T08:50:22+03:00",
  callback_url: 'https://call_back_to_your_app.your_application.com'
}

k2_polling = K2Polling.new("your_access_token")
k2_polling.polling(your_input)
k2_polling.location_url # => "https://sandbox.kopokopo.com/api/v1/polling/247b1bd8-f5a0-4b71-a898-f62f67b8ae1c"

request_body =
{
  "access_token": ACCESS_TOKEN,
  "callback_url": "https://webhook.site/52fd1913-778e-4ee1-bdc4-74517abb758d",
  "scope": "company",
  "scope_reference": "",
  "from_time": "2021-04-12T08:50:22+03:00",
  "to_time": "2021-04-19T08:50:22+03:00"
}

# Using K2Connect - https://github.com/kopokopo/k2-connect-python (Recommended)
k2connect.initialize(environ.get('CLIENT_ID'), environ.get('CLIENT_SECRET'), 'http://127.0.0.1:3000/')
polling_service = k2connect.Polling
polling_location = polling_service.polling(request_body)
polling_location # => 'https://sandbox.kopokopo.com/api/v1/polling/247b1bd8-f5a0-4b71-a898-f62f67b8ae1c'


const PollingService = K2.PollingService

var pollingOptions = {
  scope: "company",
  scopeReference: "",
  fromTime: "2021-04-12T08:50:22+03:00",
  toTime: "2021-04-19T08:50:22+03:00",
  // This is where once the request is completed kopokopo will post the response
  callbackUrl: 'https://callback_to_your_app.your_application.com/endpoint',
    accessToken: 'myRand0mAcc3ssT0k3n'
}

PollingService
  .pollTransactions(pollingOptions)
  .then( response => {
    console.log(response)
    // => 'https://sandbox.kopokopo.com/api/v1/polling/247b1bd8-f5a0-4b71-a898-f62f67b8ae1c'
  })
  .catch( error => {
    console.log(error)
  })
<?
$polling = $K2->PollingService();
$response = $polling->pollTransactions([
  'scope' => "company",
  'scopeReference' => "",
  'fromTime' => "2021-04-12T08:50:22+03:00",
  'toTime' => "2021-04-19T08:50:22+03:00",
  'callbackUrl' => 'https://callback_to_your_app.your_application.com/endpoint',
  'accessToken' => 'myRand0mAcc3ssT0k3n',
]);
if($response['status'] == 'success')
{
    echo "The resource location is:" . json_encode($response['location']);
    // => 'https://sandbox.kopokopo.com/api/v1/polling/247b1bd8-f5a0-4b71-a898-f62f67b8ae1c'
}

Retrieve your newly created subscription by its resource location:

GET https://sandbox.kopokopo.com/api/v1/polling/5af4c10a-f6de-4ac8-840d-42cb65454216
Accept: application/json
Authorization: Bearer pBA9fVDBEyYZCEsLf/wKehyh1RTpzjUj5KzIRfDi0wKTii7DqY

...

{
  "data": {
    "id": "d4849121-d7d4-49f8-881f-b41601a7fe43",
    "type": "polling",
    "attributes": {
      "status": "Success",
      "created_at": "2021-04-28T11:25:53.497+03:00",
      "from_time": "2021-04-12T08:50:22+03:00",
      "to_time": "2021-04-19T08:50:22+03:00",
      "transactions": [
        {
          "type": "Buygoods Transaction",
          "resource": {
            "id": "c4fbb520-9155-406e-aee8-661a07a49f86",
            "amount": "500.0",
            "status": "Received",
            "system": "Lipa Na M-PESA",
            "currency": "KES",
            "reference": "APR202119",
            "till_number": "000000",
            "origination_time": "2021-04-19T08:19:00+03:00",
            "sender_last_name": "Doe",
            "sender_first_name": "Jane",
            "sender_middle_name": "",
            "sender_phone_number": "+254799999999"
          }
        },
        {
          "type": "Buygoods Transaction",
          "resource": {
            "id": "18f8da83-5d95-45f9-9670-1958a8fe1e30",
            "amount": "500.0",
            "status": "Received",
            "system": "Lipa Na M-PESA",
            "currency": "KES",
            "reference": "APR202126",
            "till_number": "K000000",
            "origination_time": "2021-04-19T08:19:00+03:00",
            "sender_last_name": "Doe",
            "sender_first_name": "Jane",
            "sender_middle_name": "",
            "sender_phone_number": "+254799999999"
          }
        }
      ],
      "scope": "Company",
      "scope_reference": null,
      "_links": {
        "callback_url": "https://webhook.site/a67f60b8-8c26-40a2-866c-99f5314a3e0e",
        "self": "https://sandbox.kopokopo.com/api/v1/polling/d4849121-d7d4-49f8-881f-b41601a7fe43"
      }
    }
  }
}
pollingUrl = 'https://sandbox.kopokopo.com/api/v1/polling/5af4c10a-f6de-4ac8-840d-42cb65454216'

# Using K2Connect - https://github.com/kopo-kopo/k2-connect-ruby (Recommended)
polling = K2Polling.new(your_access_token)
polling.query_resource_url(pollingUrl)
//  Using Kopo Kopo Connect - https://github.com/kopokopo/k2-connect-node (Recommended)
const PollingService = K2.PollingService

var pollingUrl = 'https://sandbox.kopokopo.com/polling/5af4c10a-f6de-4ac8-840d-42cb65454216'

PollingService
  .getStatus({accessToken: 'myRand0mAcc3ssT0k3n', location: pollingUrl})
  .then(response => { console.log(response) }) 
  .catch(error => { console.log(error) })
pollingUrl = 'https://sandbox.kopokopo.com/api/v1/polling/5af4c10a-f6de-4ac8-840d-42cb65454216'

#Provide example using K2Connect https://github.com/kopo-kopo/k2-connect-python (Recommended)
k2connect.initialize(CLIENT_ID, CLIENT_SECRET, BASE_URL)
polling_service = k2connect.PollingService
polling_service.webhook_status(ACCESS_TOKEN, pollingUrl) 
<?
//  Using Kopo Kopo Connect - https://github.com/kopokopo/k2-connect-php (Recommended)
$polling = $K2->PollingService();

$options = [
  'location' => 'https://sandbox.kopokopo.com/api/v1/polling/d76265cd-0951-e511-80da-0aa34a9b2388',
  'accessToken' => 'myRand0mAcc3ssT0k3n',
];
$response = $polling->getStatus($options);

echo $response;