API Reference

With this API you can create a new payment request.

Description

Headers

  • Content-Type: The Content-Type header is set to application/json, indicating that the request body contains JSON data.
  • Authorization: The Authorization header is used with a bearer token for authentication. The actual token value should replace the placeholder Bearer eyJhbG...NrEQ41w.

Request Body

The request body is in JSON format and contains the following fields:

  • phoneNumber: A string representing the phone number (SPENN Account) to which the transaction is being sent.
  • amount: A numeric value indicating the amount of the transaction.
  • message: A string field for including a message with the transaction.
  • externalReference: A string field for an external reference associated with the transaction. This can be used as a reference to track the request later. This is an optional parameter.

Sample Request:

import requests # Define the API endpoint URL url = 'https://uat-businessapi.spenn.com/api/Partner/transaction/request' # Define the request headers headers = { 'Content-Type': 'application/json', 'Authorization': 'Bearer eyJhbG...NrEQ41w' # Replace with your actual bearer token } # Define the request payload (request body) as a dictionary payload = { "phoneNumber": "+250783008884", "amount": 10, "message": "Please send some money", "externalReference": "sasd23xfhaxfasdfa2342" } # Make the POST request response = requests.post(url, headers=headers, json=payload) # Check the response if response.status_code == 200: print("Success! Response:") print(response.json()) else: print(f"Request failed with status code {response.status_code}") print(response.text)
import java.io.BufferedReader; import java.io.DataOutputStream; import java.io.InputStreamReader; import java.net.HttpURLConnection; import java.net.URL; public class ApiCallExample { public static void main(String[] args) { try { // Define the API endpoint URL String url = "https://uat-businessapi.spenn.com/api/Partner/transaction/request"; // Create a connection URL obj = new URL(url); HttpURLConnection con = (HttpURLConnection) obj.openConnection(); // Set the request method to POST con.setRequestMethod("POST"); // Set request headers con.setRequestProperty("Content-Type", "application/json"); con.setRequestProperty("Authorization", "Bearer eyJhbG...NrEQ41w"); // Replace with your actual bearer token // Define the request payload as a JSON string String payload = "{" + "\"phoneNumber\": \"+250783008884\"," + "\"amount\": 10," + "\"message\": \"Please send some money\"," + "\"externalReference\": \"sasd23xfhaxfasdfa2342\"" + "}"; // Enable input/output streams con.setDoOutput(true); DataOutputStream wr = new DataOutputStream(con.getOutputStream()); wr.writeBytes(payload); wr.flush(); wr.close(); // Get the response code int responseCode = con.getResponseCode(); // Read the response if (responseCode == 200) { BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream())); String inputLine; StringBuffer response = new StringBuffer(); while ((inputLine = in.readLine()) != null) { response.append(inputLine); } in.close(); System.out.println("Success! Response:"); System.out.println(response.toString()); } else { System.out.println("Request failed with status code " + responseCode); } } catch (Exception e) { e.printStackTrace(); } } }
const fetch = require('node-fetch'); // Define the API endpoint URL const url = 'https://uat-businessapi.spenn.com/api/Partner/transaction/request'; // Define the request headers const headers = { 'Content-Type': 'application/json', 'Authorization': 'Bearer eyJhbG...NrEQ41w', // Replace with your actual bearer token }; // Define the request payload as a JSON object const payload = { phoneNumber: '+250783008884', amount: 10, message: 'Please send some money', externalReference: 'sasd23xfhaxfasdfa2342', }; // Make the POST request fetch(url, { method: 'POST', headers: headers, body: JSON.stringify(payload), }) .then((response) => response.json()) .then((data) => { console.log('Success! Response:'); console.log(data); }) .catch((error) => { console.error('Request failed:', error); });

👍

Sample Response

{ "$id": "1", "requestId": "1e6cc63a-2d0d-4885-9c51-f9a35f113811", "status": "Pending", “externalReference”: “sasd23xfhaxfasdfa2342” }