How do I conditionally pass a query string parameter in an HTTP request?

This topic was automatically generated from Slack. You can find the original thread here.

Tim Young : Hi all, new user here. Maybe this is obvious and just missing it but I’m using data from a webhook response to make an HTTP call. Is there a way to set a condition on some of the query paramters I’m passing in the HTTP request? For example, if {{steps.get_dealership_id.$return_value.items[0].id}} is bank, don’t pass it as a param?

Dylan Sather (Pipedream) : Hi , welcome!

In your example, do you still want to pass other params if your data meets that condition, or do you want to stop the workflow completely?

Tim Young : I want to pass all other params

Tim Young : Sometimes the last two params are blank

Tim Young : And I get this as an error and the record is not created via HTTP call

Tim Young : TypeError: Cannot read property ‘id’ of undefined

Dylan Sather (Pipedream) : Try changing those references to use the optional chaining operator:

{{steps.get_dealership.$return_value?.items?.[0]?.id}}

This will return undefined instead of throwing an error if any of the intermediate properties aren’t defined.

Dylan Sather (Pipedream) : (and the HTTP library we use won’t pass on any query string parameters that are undefined, so it removes it)

Tim Young : Wonderful, thank you I will try that

Tim Young : Works great, thanks again!

Dylan Sather (Pipedream) : Great no problem, glad to hear