How do you make an object type input not required in API

Options

I have an API input that is an object type. For some reason, even though I have it marked as not required, I get the error:

{"code":"ERROR_CODE_INPUT_ERROR","message":"Missing param: external_id","param":"external_id"}

Inputs:

id [required], name (text) [not required], external_id (object - keys: type (text) [not required], value (text) [not required]) [not required]

If I test with just id, I get that error. The name is not required as expected.

Any thoughts on what I'm doing wrong?

Answers

  • Pawel Magdanski
    Pawel Magdanski Member ✭✭✭
    Options

    Hi,

    Are you using this external id to get, edit, delete, etc record in the database? Because the error might appear because some field in your function stuck that is required and have this external_id as an input is empty when your input is empty.

  • waggy_d
    waggy_d Member
    Options

    Hi Pawel, no unfortunately that is not the case. The records are queried by another ID and there are no other dependancies on the external_id. In fact, there isn't anything different than the name column which seems to work fine if not included.

  • Pawel Magdanski
    Pawel Magdanski Member ✭✭✭
    Options

    Interesting,

    can you share your function stack?

  • waggy_d
    waggy_d Member
    Options

    I'm not sure the best way to do that, but I think I did it right with a snippit:

    https://www.xano.com/snippet/d4p8UxmO

  • Pawel Magdanski
    Pawel Magdanski Member ✭✭✭
    Options

    I meant a screen shot of function stack and maybe of debugger.

  • waggy_d
    waggy_d Member
    Options

    Hi Pawel, thank you for sticking with me on this. Ok, so…

    I don’t that is what is happening here because it is happening before it even enters the function stack as it is an input error:

    {code: ERROR_CODE_INPUT_ERROR,message: Missing param: external_id,param: external_id}

    I would send some debugging info but there is none because the error happens before anything happens.

    I’ve added some screenshots. This is what I’m doing:

    The input is an object that requires a cross_id, but does not require any other values. In fact they can omit the key as well. I then in the function stack look up the record by cross_id. Then, using a custom lambda, I merge the input object with object from the record search where it replaces the key/value pairs only for those present in the input json object. Then it writes the entire output object back to the database. So the external_id input value in this test case isn’t present but is never used anywhere in the function stack. When it is written back to the database, I use func_1.external_id that is the result of the lambda function. And once again, it can’t be that part because this error is happening right art the very top.

    DW

  • Pawel Magdanski
    Pawel Magdanski Member ✭✭✭
    Options

    In run and debug when you have inputs, you have just an object that I assume is external_id, but it is not specified as external_id. Try this "external_id": {"cross_id":"…", "name": "…."}

  • waggy_d
    waggy_d Member
    Options

    Hi Pawel. The point is that it is suppose to be optional. I have that input set to required=false

  • Pawel Magdanski
    Pawel Magdanski Member ✭✭✭
    Options

    But you are using this input in your function stack right? That might be the source of this error

  • waggy_d
    waggy_d Member
    Options

    No, I am not using this input in my function stack. I first query the record by cross_id. Then I use that record to fill in the value if the api call does NOT provide that in the input. Also, I know it is not the issue because the error is a an INPUT error code. The error is happening BEFORE it enters the function stack.

  • waggy_d
    waggy_d Member
    Options

    I've since discovered that it has to do with if the database field is required. The odd thing is that the behavior is different depending on the database field type. For instance a text database field set to required=yes while the api input is required=no, will not cause this input error. The same thing with an object type field causes this input error.