PHP Guide for calling Mefree.NET API

This guide provides detailed instructions on using PHP to interact with the Mefree.NET API, including generating signatures, building requests, and completing the API call flow.


1. Signature Rules Overview

Mefree.NET API uses a signature-based authentication mechanism. The signature is generated using the following logic:

1.1 Signature String Rules

The signature string is created in the following format:

sign = timestamp + method + requestPath
  • timestamp: UTC time in ISO 8601 format (e.g., 2024-11-26T12:34:56.789Z).

  • method: HTTP method, such as GET or POST.

  • requestPath: API request path (including query parameters), for example:

    • /api/config

    • /api/order?quantity=65000&target_address=TRON_ADDRESS&period=1

1.2 Signature Generation Process

  1. Concatenate timestamp, method, and requestPath into a string.

  2. Use the HMAC-SHA256 algorithm to encrypt the concatenated string with your API Secret Key.

  3. Encode the resulting hash using Base64 to generate the signature.

1.3 Required HTTP Headers

Each API request must include the following headers:

  • Content-Type: application/json

  • MF-ACCESS-KEY: Your API Key.

  • MF-ACCESS-SIGN: The generated signature.

  • MF-ACCESS-TIMESTAMP: Current UTC timestamp.


2. Implementing Signature in PHP

2.1 Signature Generation Function

Here’s how to generate the signature in PHP:


3. Constructing API Requests

3.1 Configuration

Set up the API base URL and keys:

3.2 General HTTP Request Function

Here’s a reusable function to make API requests:


4. API Call Examples

4.1 Fetch Account Information

Endpoint: /api/config HTTP Method: GET

Code Example:


4.2 Create an Order

Endpoint: /api/order?quantity=65000&target_address=TRON_ADDRESS&period=1 HTTP Method: POST

Code Example:


4.3 Check Order Status

Endpoint: /api/order/{pay_hash} HTTP Method: GET

Code Example:


5. Common Issues

5.1 Invalid Signature (401 Unauthorized)

  • Ensure MF-ACCESS-KEY matches your API Key.

  • Confirm the signature string is constructed as timestamp + method + requestPath.

  • Ensure the timestamp is in UTC and formatted correctly (e.g., 2024-11-26T12:34:56.789Z).

  • Use the correct Secret Key to generate the signature.

5.2 Invalid Parameters (400 Bad Request)

  • Verify the request path and query parameters.

  • Ensure Content-Type is set to application/json.

5.3 Rate Limit Exceeded (429 Too Many Requests)

  • Mefree API imposes rate limits. Avoid making excessive requests in a short time.

  • Add delays or throttle requests if necessary (e.g., limit to 2 requests/second).


6. Conclusion

This guide demonstrates how to efficiently interact with the Mefree.NET API using PHP, including generating signatures, making requests, and handling responses. For critical operations such as placing orders, implementing retry mechanisms is recommended to enhance reliability. For further assistance, contact Mefree's official support team.

Last updated