M-Pesa Query Transaction
AI-generatedOverview
This node, M-Pesa Query Transaction, is designed to query the status of M-Pesa transactions. It allows users to check the current state of a transaction by providing references such as a transaction ID, third party reference, or conversation ID. This is particularly useful in financial workflows where confirming payment statuses or transaction outcomes is critical.
Common scenarios:
- Verifying if a payment was successfully processed.
- Tracking transaction status updates in real-time.
- Reconciling payments with external systems using unique references.
Practical example:
A business receives payments via M-Pesa and wants to automate confirmation of each payment before fulfilling an order. By inputting the transaction ID or third party reference into this node, the workflow can automatically verify the payment status and proceed accordingly.
Properties
| Name | Meaning |
|---|---|
| Third Party Reference | Unique reference from the third-party system identifying the transaction (max 20 characters). |
| Query Reference | Reference used for querying the transaction; can be TransactionID, ThirdPartyReference, or ConversationID. |
| Service Provider Code | The shortcode or code of the service provider handling the transaction (defaulted from credentials). |
| Query Type | Type of reference used for the query. Options: - Transaction ID - Third Party Reference - Conversation ID |
Output
The node outputs JSON data containing detailed information about the queried transaction status. The output includes:
- The original request parameters (
thirdPartyReference,queryReference,serviceProviderCode). - The response fields returned by the M-Pesa API, including:
output_ResponseCode: Response code indicating success or failure (success indicated by"INS-0").output_ResponseTransactionStatus: Status of the transaction (e.g., completed, pending).
- Additional metadata:
queryType: The type of query performed.success: Boolean flag indicating if the query was successful.timestamp: ISO timestamp when the query was made.
If an error occurs during execution and "Continue On Fail" is enabled, the output will contain an error field with the error message.
The node does not output binary data.
Dependencies
- Requires an API key credential for authenticating with the M-Pesa API.
- Uses an internal helper class to make HTTP requests to the M-Pesa API endpoint
/ipg/v1x/queryTransactionStatus/. - The
serviceProviderCodecan be provided directly or taken from the stored credentials.
Troubleshooting
- Missing required properties: If either "Third Party Reference" or "Query Reference" is empty, the node throws an error indicating these are mandatory.
- Reference length exceeded: The "Third Party Reference" must not exceed 20 characters; otherwise, an error is thrown.
- API errors: If the M-Pesa API returns an error or unexpected response, the node will throw an error unless "Continue On Fail" is enabled.
- Credential issues: Ensure that valid API credentials are configured; otherwise, authentication will fail.
- Incorrect Query Type: Using a wrong query type may result in no matching transaction found.
To resolve errors:
- Verify all required inputs are correctly filled.
- Check the length constraints on references.
- Confirm API credentials and service provider codes are correct.
- Enable "Continue On Fail" to handle errors gracefully within workflows.
Links and References
- M-Pesa Developer Portal
- M-Pesa API Documentation
- n8n Documentation on Creating Custom Nodes