Programmatically set API Request params from input

Options
paolo.utile
paolo.utile Member
edited June 2023 in ? Help! I'm a Noob

Hi, I'm new to Xano and trying to build a function that takes a params object as an input and maps it to the params of an API Request.

My input is as follows: "Type: object"; "Structure: single"

I tested the input using an object such as:

{ "page":1, "pageSize":1 }

I then add the params variable to the API Request in the params field. This doesn't seem to work: in the debugger, I see "params: [0]". I thought this would work since the API Request function's params argument is an object by default. Any help?

Best Answer

  • Liz Anaya
    Liz Anaya Member, Administrator

    ADMIN

    Answer ✓
    Options

    @paolo.utile

    Changing the input to JSON will allow you to pass in an object with no defined schema as the input.

    Here is an example:

    Let me know if this works for what you are trying to do. 😃

Answers

  • Liz Anaya
    Liz Anaya Member, Administrator

    ADMIN

    Options

    Hi @paolo.utile ! 👋

    Welcome to the Xano Community! 🎉 

    You are seeing an empty array as the response because the schema was not defined in your input object. You should see the desired result once you define the schema in your object.

    1.

    2.

    3.

    Let me know if this helps or if you have any additional questions! 😊

  • paolo.utile
    paolo.utile Member
    Options

    Hi @Liz Anaya , unfortunately that does not answer my question. My idea is to have an input object with no preset structure and pass it on to an API Request as a params object: this way, the function can be used by other functions with their own params object structure. This way, I have a reusable function for making generic API Requests to an API. I understand if this is not possible.

  • paolo.utile
    paolo.utile Member
    Options

    That did it! Thanks @Liz Anaya !

  • Liz Anaya
    Liz Anaya Member, Administrator

    ADMIN

    Options

    Yay! 🎉 Happy to help!