Set Variable from API call

I have a API call that returns the information below -

My question is how can extract the 5.24 part, so I can set it to a variable

Im ok with the variable part just stuck on how to get the 5.24 part out

Thnaks

Can the API return JSON instead of XML? That would make the parsing much easier. :slight_smile:

Otherwise you could try using an expression to find the opening and closing <balance> tag and get the content between them.

Something like:

text ="<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<xml><result>0000</result> <errortext>Success</errortext><balance>5.24</balance><type>Prepay</type> <currency_symbol>£</currency_symbol> <currency_type>GBP</currency_type> </xml>\n"
start = indexOf(text, "<balance>") + 9
finish = indexOf(text, "</balance>")
substring(text, start, finish)

Of course in your example, you could use $context.response.data in place of the hard-coded text value from my example.

1 Like

That’s worked great, Thanks

1 Like