Get Access Token
AI-generatedOverview
This node provides authentication functionality for the M-Pesa Mozambique API. It primarily allows users to obtain an access token required for authenticating subsequent API requests or to validate the provided API credentials. This is useful in workflows where secure interaction with the M-Pesa payment system is needed, such as initiating payments, querying transaction status, or managing customer data.
Typical use cases include:
- Automatically retrieving a fresh access token before making API calls.
- Verifying that the configured API credentials are valid and active.
- Managing token expiry by specifying how long the token should be considered valid.
Properties
| Name | Meaning |
|---|---|
| Operation | The action to perform: "Get Access Token" to retrieve a new authentication token, or "Validate Credentials" to check if the API credentials are valid. |
| Token Expiry (minutes) | The duration in minutes for which the retrieved access token will be considered valid before expiring. Only applicable when the operation is "Get Access Token". Default is 60 minutes. |
Output
The node outputs JSON data structured as follows depending on the selected operation:
Get Access Token:
{ "access_token": "string", // The retrieved bearer token string "token_type": "Bearer", // The type of token returned "expires_in": number, // Token validity duration in seconds (based on Token Expiry input) "expires_at": "ISO8601 string", // Exact timestamp when the token expires "scope": "mpesa_api" // Scope of the token }Validate Credentials:
{ "valid": true|false, // Whether the credentials are valid "message": "string", // Validation message, e.g., "Credenciais válidas" or error details "environment": "string", // Environment info from credentials (e.g., sandbox or production) "serviceProviderCode": "string" // Service provider code from credentials }
If the node encounters an error and "Continue On Fail" is enabled, it outputs an object with an error property describing the issue.
Dependencies
- Requires an API key credential for the M-Pesa Mozambique API.
- Uses an internal helper class (
MPesaApiHelper) to handle API requests and token retrieval. - The node expects proper configuration of the M-Pesa API credentials including service provider code and environment.
- No additional external services beyond the M-Pesa API itself.
Troubleshooting
- Invalid Credentials Error: If the validation operation returns invalid credentials, verify that the API key and service provider code are correctly set and have not expired or been revoked.
- Token Retrieval Failure: Network issues or incorrect credentials can cause failure to get an access token. Check connectivity and credential correctness.
- Token Expiry Misconfiguration: Setting an extremely low or high token expiry time may cause unexpected behavior; use reasonable values (default 60 minutes).
- Error Messages: Errors thrown during execution include descriptive messages. Enabling "Continue On Fail" allows the workflow to continue while capturing error details in output.
Links and References
- M-Pesa Mozambique API Documentation (Note: link is generic; refer to specific Mozambique API docs if available)
- OAuth 2.0 Bearer Token Standard: https://tools.ietf.org/html/rfc6750