This guide explains how to use Java to interact with the Mefree.NET API. It covers signature generation, HTTP request construction, and example API calls.
1. Overview of the Signature Rules
1.1 Signature String Rules
Mefree.NET API requires a signature mechanism for authentication. Ensure the signature is generated following these rules:
Construct the String to Sign:
sign = timestamp + method + requestPath
timestamp: UTC time in ISO 8601 format, e.g., 2024-11-26T12:34:56.789Z.
method: HTTP method, e.g., GET or POST.
requestPath: API request path (including query parameters), such as:
API Endpoint: /api/order/{pay_hash}HTTP Method: GET
Code Example:
publicclassMain {publicstaticvoidmain(String[] args) {try {String payHash ="abcd1234"; // Replace with actual pay_hashString requestPath ="/api/order/"+ payHash;String response =MefreeApiClient.sendRequest("GET", requestPath);System.out.println("Order Status: "+ response); } catch (Exception e) {System.err.println("Failed to fetch order status: "+e.getMessage()); } }}
6. Common Issues
6.1 Invalid Signature (401 Unauthorized)
Ensure the MF-ACCESS-KEY matches your API Key.
Verify the signature generation logic:
String concatenation order is timestamp + method + requestPath.
Use the correct SECRET_KEY.
Ensure the timestamp is in UTC format and not older than 5 seconds.
6.2 Bad Request (400)
Verify the request path and query parameters are correct.
Ensure Content-Type is set to application/json.
6.3 Too Many Requests (429)
Respect the API rate limits and implement a delay between requests if necessary.
7. Summary
With this guide, you can now use Java to call Mefree.NET APIs. It includes signature generation, HTTP request construction, and example code for various API endpoints. For further clarification, contact Mefree technical support or consult the official API documentation.