Synchronisation - Troubleshooting guide

Note:

  • Refer to Current timestamp doc for detailed information.

  • We recommend only using this approach when you encounter timestamp-related issues. For regular use, your local system's timestamp should suffice

  • Always make sure that your system time is accurate and try to keep it synchronised with a reliable source

If you're receiving a "Ahead of Time" 401 error, it likely indicates a mismatch between your local timestamp and the server timestamp. This discrepancy can lead to failed authentication, thus triggering a 401 error.

You can follow the steps below to resolve the issue:

  1. Fetch Server Timestamp: Use the Server Timestamp endpoint to obtain the current timestamp from the server, using the link here.

  2. Generate Signature with Server Timestamp: Use the fetched server timestamp to generate the signature for your API requests.

  3. Re-attempt API Request: Send your API request again, this time using the signature generated with the server's timestamp.

Here is a reference code to utilise server timestamp:

var CryptoJS = require('crypto-js');
const axios = require('axios');

const currentTimestamp = async () => {
    try {
        const response = await axios.get(`https://api.onramp.money/onramp/api/v2/common/public/currentTimestamp`);
        // console.log("Timestamp API Response:", JSON.stringify(response.data.data, null, 2));
        return response.data.data;
    } catch (error) {
        console.error("Timestamp API Error:", error);
        return null;
    }
};

async function main() {
  try {
    const API_KEY = "API_KEY";
    const API_SECRET = "API_SECRET";


    let body = {
      page: 2,
      pageSize: 50,
      order: "ASC"
    };

    let current_timestamp = await currentTimestamp();
		//let current_timestamp = new Date().getTime();  // local timestamp
    if (!current_timestamp) {
      current_timestamp = new Date().getTime();
    }
    console.log("Current Timestamp:", current_timestamp);

    let payload = {
      timestamp: current_timestamp,
      body: body
    };

    payload = Buffer.from(JSON.stringify(payload)).toString('base64');
    let signature = CryptoJS.enc.Hex.stringify(CryptoJS.HmacSHA512(payload, API_SECRET));

    let options = {
      url: 'https://api.onramp.money/onramp/api/v1/transaction/merchantHistory',
      method: 'POST',
      headers: {
        'Accept': 'application/json',
        'Content-Type': 'application/json;charset=UTF-8',
        'X-RECON-SIGNATURE': signature,
        'X-RECON-APIKEY': API_KEY,
        'X-RECON-PAYLOAD': payload
      },
      data: body
    };

    console.log("API Request Options:", options);

    let data = await axios(options);
    console.log("API Response:", data?.data);
  } catch (error) {
    console.log("Error Details:", error);
  }
}

main();

Last updated