Daraja SDK Logomark
Daraja SDK
Account & Ledger

Pull Transactions

Retrieve a list of C2B transactions on your account for a recent period, to recover missed callback notifications.

A reconciliation tool: lets a partner pull every C2B transaction made under their Pay Bill/Till within the last 48 hours, including ones whose callback never reached the registered URL because of downtime on the merchant's side.

How it works

This is a two-step API: register your short code once (Register Pull), then query transactions repeatedly afterward (Query Pull Transaction).

  1. The merchant registers their short code for pulling via API. This is required only once, and the short code must belong to a user already live in production.
  2. When callback notifications are missed (for example, due to downtime), the merchant sends a request to retrieve transactions for the affected period.
  3. The merchant reconciles using the returned data.

Prerequisites

  • Daraja account and sandbox app.
  • A live Pay Bill/Till with Business Admin/Manager operators and an existing C2B integration already registered, for Go Live.

Defect in the source material

Safaricom documents this API as asynchronous in its "Good to Know" section, but also states the method is POST for registration and GET for the transaction query itself, with the query returning data directly in the HTTP response rather than via a callback. That makes the query call read as synchronous in practice; both statements are Safaricom's own and are reproduced as published.

Register Pull

Endpoint

POST https://sandbox.safaricom.co.ke/pulltransactions/v1/register

Headers

KeyValue
Content-Typeapplication/json
AuthorizationBearer <access_token>

Request

{
  "ShortCode": "600000",
  "RequestType": "Pull",
  "NominatedNumber": "0722000000",
  "CallBackURL": "https://domain/path"
}
FieldDescriptionSample value
ShortCodeOrganization short code used at Go Live.17831
RequestTypeDefaults to, and is documented as, Pull.Pull
NominatedNumberThe Safaricom MSISDN associated with the account using Pull.254722000000
CallBackURLA valid, secure URL.https://mydomain.com/confirmation

Response

{
  "ResponseRefID": "feb5e3f2-fbc-4745-844c-ee37b546f627",
  "ResponseStatus": "1000",
  "ShortCode": "600000",
  "ResponseDescription": "Shortcode Registered Successfully"
}
CodeMeaning
1000Short code registered successfully
1001Short code already registered

Query Pull Transaction

Headers

KeyValue
Content-Typeapplication/json
AuthorizationBearer <access_token>

Request

{
  "ShortCode": "600000",
  "StartDate": "2020-08-04 8:36:00",
  "EndDate": "2020-08-16 10:10:000",
  "OffSetValue": "0"
}
FieldDescriptionSample value
ShortCodeYour Pay Bill/Till number.17843
StartDate / EndDatePeriod to query, formatted YYYY-MM-DD HH:MM:SS.2019-07-31 20:35:21
OffSetValuePagination offset, starting at 0. To get results 101 to 200, pass 100.100

Defect in the source material

Safaricom's own sample request writes EndDate as "2020-08-16 10:10:000", with three trailing zeros on the seconds component rather than two. Reproduced exactly as documented.

Response

{
  "ResponseRefID": "26178-42530161-2",
  "ResponseCode": "1000",
  "ResponseMessage": "Success",
  "Response": [
    [
      {
        "transactionId": "yzlyrEsRG1",
        "trxDate": "2020-08-05T10:13:00Z",
        "msisdn": 722000000,
        "sender": "UAT2",
        "transactiontype": "c2b-pay-bill-debit",
        "billreference": "37207636392",
        "amount": "168.00",
        "organizationname": "Daraja Pull API Test"
      }
    ]
  ]
}
FieldDescription
transactionIdThe M-PESA transaction ID.
trxDateCompletion timestamp.
msisdnThe paying customer's number.
transactiontypee.g. c2b-pay-bill-debit.
billreferenceAccount reference, for Pay Bill transactions.
amountAmount transacted.
organizationnameOrganization name as registered at Go Live.

Response is documented as an array of arrays (note the double [[ ]] in the sample above), not a flat array. When no transactions exist for the period, Safaricom documents the body as "Transaction": "[[]]", a field name that doesn't match Response used in the successful sample; both are reproduced as documented.

Response codes

CodeMeaning
1000Success, transactions fetched
1001No transactions available for the period

Error codes

CodeMeaning
400.001Invalid short code
401.001Invalid access token
500Failed to retrieve transactions; no transactions available for the short code

Testing and Go Live

Daraja Simulator with the C2B product attached (Pull Transactions builds on an existing C2B integration, so it's tested alongside it), registering URLs before each simulation and using CustomerPayBillOnline or CustomerBuyGoodsOnline.

Postman: token from the sandbox OAuth endpoint, then call the register or query endpoint above.

Going live follows Organization Portal & Go Live; this API additionally requires an already-registered C2B integration on the short code.

FAQs

On this page