Getting the full URL called of an API endpoint

Options
MattLaro
MattLaro Member ✭✭
edited August 2023 in ? Working with APIs

I'm using Hubspot and I need to implement a verification of the authenticity of a call from Hubspot to a Xano API endpoint.

For this verification, I need the exact same URL called by Hubspot, as is (with query parameters if there's any) to include it in the string that will be hashed and compared.

However, I noticed that $request_uri only returns the portion of the call that succeeds the domain name, so it starts at /api:myapicode/myendpoint. I'm not even sure it includes the query parameter. I did not test.

Is there a sure way, including in Lambda perhaps, to fetch the full URL with variables including the URL query parameters if any is present? Like so :

"https://myxanodomain.com/api:myapi/myendpoint?param1=value1&param2=value2"

Thank you !

Matt

Comments

  • Ray Deck
    Ray Deck Trusted Xano Expert ✭✭✭
    Options

    There is another env variable called $request_querystring that can serve you in this use case. Jam (or "concat") it together with the request URI to get your reconstructed called URL. https://docs.xano.com/what-xano-includes/workspace/settings/environment-variables

  • MattLaro
    MattLaro Member ✭✭
    Options

    @Ray Deck You don't need $request_querystring with $request_uri. I just tested and $request_uri has all except the domain.

    So I guess there is no other way than write the domain in plain text and concat the $request_uri, huh…

  • Ray Deck
    Ray Deck Trusted Xano Expert ✭✭✭
    Options

    THat's what I get for posting before I test. Yes, you are quite correct - I was tackling the wrong end of this. You can get the host (separate from the path/querystring) from $http_headers.Host. And the scheme (https) from X-Scheme.

    Here's a screenshot of putting the full thing back together:

  • MattLaro
    MattLaro Member ✭✭
    Options

    VERY interesting solution :) I'm pretty sure this will do. Thank you @Ray Deck 🙌