Parsing SOAP API Response for Key-Value pairs - Need advice

Hi all!

I am setting up some connector functions for a SOAP API and trying to figure out the best way to pull outputs for an array of properties that I don’t know how many items there will be each time.

Response sample is below. When I get to the properties/UnitProperty section, this is where I don’t know how to best handle it. The number of values and each property name could be different for all types of units so I was thinking it would be great to return an array of key-value pairs or at least an array of strings that look like the pairs.

Using the XPath tester at this link (https://www.freeformatter.com/xpath-tester.html#ad-output) I’m able to get myself a set of strings representing the pairs using //UnitProperty/concat(propertyName/text(),’: ',propertyValue/text())

However, putting this in a corresponding Tulip output extractor field and testing the function generates an error: Function test failed: XPath parse error.

Anyone know how to properly structure the XPath to capture this list of strings? Or, do you have a suggestion for a better approach, overall?

Thanks!

1 Like

Hello!

I’m sorry that you had issues with this, but I’m happy to share that since r184 we are returning more information from XML extractors when the xpath output isn’t what Tulip expects.

I suspect that in this situation, the xpath result is returning an array to Tulip and Tulip is expecting a string, so the extraction fails. Now, you can either select to return an array of values directly, or, if Tulip detects a mismatch, you will be returned a concatenation of all of the array values.

I’ve created a demo connector to demonstrate the options. The raw value being returned from the API is the following:

<root>
  <unit>
    <key>Key1</key>
    <value>Value1</value>
  </unit>
  <unit>
    <key>Key2</key>
    <value>Value2</value>
  </unit>
  <unit>
    <key>Key3</key>
    <value>Value3</value>
  </unit>
</root>

and the Connector Function is as follows:

Could you test and verify if this resolves your issue?