Skip to main content

Polling

Polling API Requests​

Poll Buygoods Transactions between the specified dates for a particular till or for the whole company

POST https://sandbox.kopokopo.com/api/v2/polling
Content-Type: application/json
Accept: application/json
Authorization: Bearer < AccessToken >
User-Agent: "< product >/< product-version > < comment >"
{
"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"
}
}

HTTP Request​

POST https://sandbox.kopokopo.com/api/v2/polling
Accept: application/json
Content-Type: application/json
Authorization: Bearer 0Sn0W6kzNicvoWhDbQcVSKLRUpGjIdlPSEYyrHqrDDoRnQwE7Q
User-Agent: < product >/< product-version > < comment >

Request Parameters (JSON)​

ParameterRequiredTypeDescription
scopeyesStringThe scope of the polling request. Could be either company or till
scope_referenceyesStringIf the scope is till the scope reference is required and it should be your till number
from_timeYesStringA string containing a date in the iso8601 format
to_timeYesStringA string containing a date in the iso8601 format
_linksYesJSONA JSON object containing the callback_url where the result of the Polling Query will be posted

HTTP Response​

Successful Response​

Upon a successful request a HTTP Status 201 will be returned and the location HTTP Header will contain the URL of the newly created Polling API Request

HTTP/1.1 201 Created
Location: https://sandbox.kopokopo.com/api/v2/polling/247b1bd8-f5a0-4b71-a898-f62f67b8ae1c

Error Response​

This will have a HTTP Status code indicating the error and it might have a json that contains the error code and an error message specifying the error that occured. Please note that the error response might not be present depending on the type of error that occured.

If the error json response is present, it will look as follows:

HTTP/1.1 400 Bad Request

{ "error_code": 400, "error_message": "Scope is invalid" }

Process Polling API Result​

POST https://your-callback-url.com/api/v2/polling_result
Content-Type: application/json
X-KopoKopo-Signature: 0Sn0W6kzNicvoWhDbQcVSKLRUpGjIdlPSEYyrHqrDDoRnQwE7Q
User-Agent: < product >/< product-version > < comment >
{
"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"
}
},
{
"type": "External Till to Till Transaction",
"resource": {
"id": "dfcfd000-3c43-4fff-beb3-c82718715f2e",
"amount": "1000.0",
"status": "Complete",
"system": "M-PESA",
"currency": "KES",
"reference": "JUL202410",
"till_number": "112233",
"sending_till": "John",
"origination_time": "2024-07-10T13:00:00+03:00"
}
}
],
"scope": "Company",
"scope_reference": null,
"_links": {
"callback_url": "https://webhook.site/a67f60b8-8c26-40a2-866c-99f5314a3e0e",
"self": "https://sandbox.kopokopo.com/api/v2/polling/d4849121-d7d4-49f8-881f-b41601a7fe43"
}
}
}
}

After the Polling query is performed, a Polling Result will be posted asynchronously to the call back URL specified in the Polling API Request.

Polling Result Parameters (JSON)​

Parameters contained in a successful Polling result;

ParameterRequiredTypeDescription
idYesStringThe ID of the Polling API Request
typeYesStringThe topic of the request. polling in this instance.
statusYesStringA status string denoting the status of the Polling Request
from_timeYesDateThe from date that was specified in the request
to_timeYesDateThe to date that was specified in the request
transactionsNoJSONAn JSON object containing the transactions from the query with the specified parameters
_linksYesJSONA JSON object containing links to the Polling API request

Transactions JSON(Could be multiple)

ParameterTypeDescription
typeStringThe type of transaction (Buygoods Transaction)
resourceJSONThe resource corresponding to the event. In this case this is a Buygoods Transaction

Resource (Buygoods Transaction) JSON

ParameterTypeDescription
idStringThe api reference of the transaction
referenceStringThe mpesa reference
statusStringThe status of the transaction
origination_timeStringThe transaction timestamp
sender_phone_numberStringThe phone number that sent the payment
amountFloatThe amount of the transaction
currencyStringCurrency
till_numberStringThe till number to which the payment was made
systemStringThe mobile money system
sender_first_nameStringFirst name of payer
sender_middle_nameStringMiddle name of payer
sender_last_nameStringLast name of payer

Query Polling API Status​

GET https://sandbox.kopokopo.com/api/v2/polling/d79995cd-0111-e511-80da-0aa34a9b2388
Accept: application/json
Authorization: Bearer 0Sn0W6kzNicvoWhDbQcVSKLRUpGjIdlPSEYyrHqrDDoRnQwE7Q
Content-Type: application/json
User-Agent: < product >/< product-version > < comment >
polling_url = 'https://sandbox.kopokopo.com/api/v2/polling/d4849121-d7d4-49f8-881f-b41601a7fe43'

# Using K2 Connect - https://github.com/kopokopo/k2-connect-ruby (Recommended)
k2_polling = K2Polling.new("your_access_token")
k2_polling.polling(your_input)

# Query specific resource
k2_polling.query_resource(polling_url) or k2_polling.query_resource(k2_polling.location_url)

# Query recent transaction
k2_polling.query_status

The request above results the following JSON payload when a Polling Result exists

{
"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/v2/polling/d4849121-d7d4-49f8-881f-b41601a7fe43"
}
}
}
}

With an Polling location url, you can query what the status of the Polling API is. If a corresponding Polling Result exists, it will be bundled in the payload of the result.

HTTP Request​

GET https://sandbox.kopokopo.com/api/v2/polling/
Accept: application/json
Content-Type: application/json
Authorization: Bearer 0Sn0W6kzNicvoWhDbQcVSKLRUpGjIdlPSEYyrHqrDDoRnQwE7Q
User-Agent: < product >/< product-version > < comment >

Query Parameters​

ParameterRequiredTypeDescription
IDYesStringThe reference / ID of the Polling to retrieve

HTTP Response​

Transactions JSON(Could be multiple)

ParameterTypeDescription
typeStringThe type of transaction (Buygoods Transaction)
resourceJSONThe resource corresponding to the event. In this case this is a Buygoods Transaction

Resource (Buygoods Transaction) JSON

ParameterTypeDescription
idStringThe api reference of the transaction
referenceStringThe mpesa reference
statusStringThe status of the transaction
origination_timeStringThe transaction timestamp
sender_phone_numberStringThe phone number that sent the payment
amountFloatThe amount of the transaction
currencyStringCurrency
till_numberStringThe till number to which the payment was made
systemStringThe mobile money system
sender_first_nameStringFirst name of payer
sender_middle_nameStringMiddle name of payer
sender_last_nameStringLast name of payer