Inputs for the custom function and for the endpoint

Options

I successfully tested my custom function sendgrid_dynamic_send after barely a week on Xano.

Yet I feel something isn't right. I have about a dozen inputs for my function (all tested with the Run&Debug). Now at the endpoint level, I end up creating a few of those inputs again.

I've digged into this doc but that didn't aleviate my doubts:https://docs.xano.com/api/the-basics/custom#how-to-create-an-api-endpoint

Where can I read more (any relevant link in the forum)?

For example, am I correct in setting all the inputs needed for the personalizations array of objects inside the function only, and only a personalizations input at the endpoint level?

Answers

  • Chris Coleman
    Chris Coleman Administrator

    ADMIN

    Options

    In terms of what inputs you need at the API level vs the function level, it really just depends on where the data originates.

    As an example, if I have a custom function that is used to update a user's email address in the database, and the value to use is coming from a user's input on the front-end, I would need that input at the API level so my front-end can pass it along.

    If my custom function needs that data, but maybe I'm pulling it from a database query, or an external API request, that would mean that my endpoint does not need those inputs because they are populated in my function stack.

    So, the tl;dr is that if the data comes from user input, you'll likely need this in your API's inputs. If it comes from a step in the function stack, you probably don't need an input defined in the API for this.

  • Fredk
    Fredk Member
    edited February 2023
    Options

    Chris, thanks.

    I've set all my inputs (data from front end) in the endpoint now, for example ‘subject’.

    But now I also need this input again at the function level too, don't I? (as it is required in the request body of api.sendgrid.com/v3/mail/send)

  • Chris Coleman
    Chris Coleman Administrator

    ADMIN

    Options

    Yep, any of those input you need for that function to run, you will want to set up in your function.