Post JSON data

Options
I am creating webhook end point that receives the JSON data (as post). Its header has hmac hash to validate the request.

When I receive the payload, it looks like the order in JSON is changed when received on Xano. For example the JSON posted from the external server to the Xano endpoint is:
{
  "event_id": "...",
  "mobile":"...",
  "sdkAuthToken":"..."
}

But this when seen in debug mode is as following:
{
   "mobile":"...",
   "event_id":"....",
   "sdkAuthToken":"...."
}

This is happening all times. Is there a sort order by any means in debug mode?

Comments

  • Michael Udinski
    Michael Udinski Administrator

    ADMIN

    Options
     the order typically shouldn't matter. Is it causing an error for your use-case? 
  • Ray Deck
    Ray Deck Trusted Xano Expert ✭✭✭
    Options
    Most systems don't guarantee the order in an object (using curly braces {}). So if you have {A: 1, B: 2, C:3} you might later render it as {C:3,  A: 1, B:2}. Objects give fidelity of association, but not of sequence. 

    In contrast, you can have an array (using the square brackets []) that guarantee fidelity of sequence, but will lack association. [1,2,3] will continue to be [1,2,3], but its up to someone else to determine what the importance of those positions is. 
  • Puneet Mathur
    Puneet Mathur Member
    Options
     the request has a sha256 hmac which verifies the authenticity of the request.

    So when I execute:

    const payloadBytes = payload.getBytes();
    const secretBytes = secret.getBytes();
    var expectedSignature = crypto.createHmac('sha256', Buffer.from(secretBytes)).update( Buffer.from(payloadBytes)).digest('hex');

    (here payload is the complete input as received)

    the result is different when the sequence is not the same as sent by external server. 
  • Puneet Mathur
    Puneet Mathur Member
    Options
    Is there a way I can get the raw data which is being posted?
  • Ray Deck
    Ray Deck Trusted Xano Expert ✭✭✭
    Options
     Under utility functions there is a "get raw data (webhook)" function that may help. Note that Xano is a little aggressive turning text formatted as JSON into objects that can later get re-ordered, so keep an eye on what happens with that data if you care about fidelity of sort or the integrity of the original string. (For example, the original body might be important for cryptographic validation.)