Best way to get the output of an API in a task?

Options
Georges Duverger
Georges Duverger Trusted Xano Expert
I have a task that posts a report daily to Slack. The content of that report comes from Xano endpoints. Should I be using the “External API Request” in that case, even though it's all inside my Xano workspace (see screenshot attached)?[Screen Shot 2022-03-08 at 2.22.22 PM.png]

Comments

  • Lachlan McPherson
    Options
    Hey Georges,

    If you're looking to access information from your database, within the same workspace, you'd probably look at doing this through a database request. (Add function -> Database Requests -> Query All records or Get record perhaps ) - Docs here: https://docs.xano.com/working-with-data/functions/database-requests

    You'd then call the external API to post to Slack.  
  • Georges Duverger
    Georges Duverger Trusted Xano Expert
    Options
     Right. That makes sense. It's just that I've already created all those “functions” in my API endpoints. I would like to keep all that logic in one spot. Maybe adding Functions that I reuse in both the API and the Tasks is the way to go. 🤔
  • Georges Duverger
    Georges Duverger Trusted Xano Expert
    Options
    Reading more about Functions, it doesn't feel like it's what you would use it for.
  • Lachlan McPherson
    Options
    You're able to convert your API endpoint to a function, then you can use this within your Backend Tasks. (which is perhaps what you've done already by the looks of it)   

    The difference with the API endpoint is that this would be setup to receive an input to act as the trigger. Such as a post you could send from Slack saying trigger this report now. 

    The backend task you'll create the trigger in xano such as (every 24 hours at 9am) 

    Assuming that your api calls are working correctly, I don't see that there's any harm in using it as you are. But for best practices moving forward it's probably more efficient to do a direct database query. (not certain this is the case but I presume so) 
  • Georges Duverger
    Georges Duverger Trusted Xano Expert
    Options
     That's helpful. Thanks. I was under the impression that Functions were meant to be a little more agnostic of the DB, and that I probably shouldn't do DB queries in them. But maybe I'm limiting myself with this perspective.
  • Lachlan McPherson
    Options
     

    I think you're certainly limiting yourself with that view. Functions are more so re-usable elements that you can populate your API's and Backend tasks with.  

    You're able to do any of the functions within the function stack (within a function) there isn't any limitations there. Including DB Queries :) 
  • Georges Duverger
    Georges Duverger Trusted Xano Expert
    Options
     Then, that's probably what I'm going to do. Thank you, Lachlan.
  • Lachlan McPherson
    Options
     hopefully this helps! :)