cancel
Showing results for 
Search instead for 
Did you mean: 

How to exclude xml tags when value is null while handling xml requests in SDK Connector

ricardomatsumot
Deputy Chef I
Deputy Chef I

Hi, I am building a SDK Connector that calls an API with XML payload.

I am following the Handling XML documentation

However, I want to know how I can exclude the xml tag whenever the input value is not provided. Is there a way we can do that?

For example, I have 2 optional input fields: key1 and key2

And I am using this code to create the xml payload

"content": [
{
"data1": [{ "content!": input["key1"] }],
"data2": [{ "content!": input["key2"] }]
}
]

And I am expecting to get this xml

<content>
<data1>key1Value</data1>
<data2>key2Value</data1>
<content>

However, when the input for key2 is not provided, I want to get this xml:

<content>
<data1>key1Value</data1>
<content>

 

1 ACCEPTED SOLUTION

chris-wiechmann
Workato employee
Workato employee

Hi @ricardomatsumot,  

You need to build your structure with some conditions before converting it into XML. For example like this. 

object = {}
object['data1'] = _input['key1'] if _input['key1'].present?
object['data2'] = _input['key2'] if _input['key2'].present?

Hope this helps you!

Cheers,
Chris

View solution in original post

2 REPLIES 2

chris-wiechmann
Workato employee
Workato employee

Hi @ricardomatsumot,  

You need to build your structure with some conditions before converting it into XML. For example like this. 

object = {}
object['data1'] = _input['key1'] if _input['key1'].present?
object['data2'] = _input['key2'] if _input['key2'].present?

Hope this helps you!

Cheers,
Chris

Thanks Chris!! It worked pretty well