Dynamic module body definition based on parameters?

Hi,

I’m making an app for an API that uses GraphQL. One of the modules has a body that looks something like this:

"body": {
	"query": "query getInvoiceList($input: ListInfoInput!) { getInvoiceList(input: $input) { invoices { client invoiceId invoiceDate statusEnum } } }",
	"variables": {
		"input": {
			"pageSize": 100,
			"condition": {
				"joinOperator": "AND",
				"operands": [
					{
						"attribute": "statusEnum",
						"operator": "is",
						"value": "DRAFT"
					},
					{
						"attribute": "client.accountId",
						"operator": "is",
						"value": "{{parameters.customerID}}"
					}
				]
			}
		}
	}
},

So far so good, but I would like for the customerID parameter to be optional, and I cannot pass null for a value there. Instead I need to omit the whole object.

{
	"attribute": "client.accountId",
	"operator": "is",
	"value": "{{parameters.customerID}}"
}

Any way to achieve this?

I almost figured it out. I can use a temporary variable together with inline functions.

"operands": [
	"{{if(parameters.customerID, temp.accountIdCondition, ignore)}}",
	{
		"attribute": "statusEnum",
		"operator": "is",
		"value": "DRAFT"
	}
]
"temp": {
	"accountIdCondition": {
		"attribute": "client.accountId",
		"operator": "is",
		"value": "{{parameters.customerID}}"
	}
},

However this inserts null into the array when the parameter is not defined, which is not a valid request. Both ignore and undefined does the same.

1 Like