" /> How to parse web service response with a list on Composer 8.1.4? - Genesys CTI User Forum

Author Topic: How to parse web service response with a list on Composer 8.1.4?  (Read 3204 times)

Offline bilge

  • Newbie
  • *
  • Posts: 27
  • Karma: 0
Advertisement
We need to parse the xml response of a SOAP web service and the output xml has a list. We can get the result AppState.Variable.SearchServResponse.SearchServResult["a:BBB"] if there is not a list. But in our example, xml is like the following one I posted and we cannot get the Num[0] for the first response, for instance. Does anybody know how the syntax should be for our case? Composer version is the latest one. We tried to get the response using array but could not be successful.

Thank you in advance,
BR

<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
  <s:Body>
      <SearchServResponse xmlns="http://tempuri.org/">
        <SearchServResult xmlns:a="http://schemas.org" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
            <a:SearchList>
              <a:SearchRow>
                  <a:SearchInfo>
                    <a:CodeNum>111</a:AreaCodeNum>
                    <a:Date>2010-04-10T00:00:00</a:ClaimDate>
                    <a:Num>1111</a:ClaimNum>             
                  </a:SearchInfo>
                  <a:SearchInfo>
                    <a:CodeNum i:nil="true"/>
                    <a:Date>2010-04-10T00:00:00</a:ClaimDate>
                    <a:Num>2222</a:ClaimNum>               
                  </a:SearchInfo>                 
              </a:SearchRow>
            </a:SearchList>
            <a:OutHeader xmlns:b="http://schemas.org">
              <b:IsSuccessfull>true</b:IsSuccessfull>
              <b:ResponseMessage>Success</b:ResponseMessage>
              <b:Responsecode>1</b:Responsecode>
            </a:OutHeader>
        </SearchServResult>
      </SearchServResponse>
  </s:Body>
</s:Envelope>

Offline cavagnaro

  • Administrator
  • Hero Member
  • *****
  • Posts: 7641
  • Karma: 56330
Re: How to parse web service response with a list on Composer 8.1.4?
« Reply #1 on: August 01, 2018, 03:10:11 PM »
Check your MCP logs, enable debug at that block and check the JSON returned by it.


Enviado de meu E6633 usando o Tapatalk


Offline bilge

  • Newbie
  • *
  • Posts: 27
  • Karma: 0
Re: How to parse web service response with a list on Composer 8.1.4?
« Reply #2 on: August 02, 2018, 10:56:09 AM »
Hi cavagnaro,

MCP logs and GVP Debugger results are limited, it can only show us a specific number of characters for JSON. The only thing special is the "[" character after SearchInfo, which means an array is defined at this point.

Expression [var WSResponse = {"SearchServResponse":{"@xmlns":"http://tempuri.org/","SearchServResult":{"@xmlns:a":"http://schemas.org" xmlns:i="http://www.w3.org/2001/XMLSchema-instance","a:SearchList":{"a:SearchRow":{"a:SearchInfo":[{"a:CodeNum":{"@i:nil":"true"},"a:Date":"2010-10-26T00:00:00","a:Num":"1111"

Thank you,

Offline cavagnaro

  • Administrator
  • Hero Member
  • *****
  • Posts: 7641
  • Karma: 56330
Re: How to parse web service response with a list on Composer 8.1.4?
« Reply #3 on: August 02, 2018, 11:48:10 AM »
Ermmm just do a JSON.stringify at the next block of your variable in the log section with debug level.
Or add a log block after your WS request



Enviado de meu E6633 usando o Tapatalk


Offline bilge

  • Newbie
  • *
  • Posts: 27
  • Karma: 0
Re: How to parse web service response with a list on Composer 8.1.4?
« Reply #4 on: August 02, 2018, 02:22:20 PM »
Hi,

I tried JSON.stringify with debug level but the response is still limited.


Offline cavagnaro

  • Administrator
  • Hero Member
  • *****
  • Posts: 7641
  • Karma: 56330
Re: How to parse web service response with a list on Composer 8.1.4?
« Reply #5 on: August 02, 2018, 02:25:21 PM »
Wireshark then or a soap UI, or at Tomcat logs look for composer logs

Enviado de meu E6633 usando o Tapatalk


Offline bilge

  • Newbie
  • *
  • Posts: 27
  • Karma: 0
Re: How to parse web service response with a list on Composer 8.1.4?
« Reply #6 on: August 07, 2018, 01:39:48 PM »
Sorry for the late response. I converted the xml response to json format.

{
  "s:Envelope": {
    "-xmlns:s": "http://schemas.xmlsoap.org/soap/envelope/",
    "s:Body": {
      "SearchResponse": {
        "-xmlns": "http://tempuri.org/",
        "SearchResult": {
          "-xmlns:a": "http://schemas.org/",
          "-xmlns:i": "http://www.w3.org/2001/XMLSchema-instance",
          "a:SearchList": {
            "a:SearchRow": {
              "a:SearchInfo": [
                {
                  "a:CodeNum": { "-i:nil": "true" },
                  "a:Date": "2010-04-10T00:00:00",
                  "a:Num": "1111",
                  "a:List": {
                    "a:Row": {
                      "a:Info": [
                        {
                          "a:Name": "AAA"                     
                        },
                        {
                          "a:Name": "BBB"                 
                        }
                      ]
                    }
                  },
                  "a:PhoneNum": { "-i:nil": "true" }               
                },
                {
                  "a:CodeNum": { "-i:nil": "true" },
                  "a:Date": "2010-04-01T00:00:00",
                  "a:Num": "2222",
                  "a:List": {
                    "a:Row": {
                      "a:Info": [
                        {
                          "a:Name": "CCC"                     
                        },
                        {
                          "a:Name": "DDD"                     
                        },
                        {
                          "a:Name": "EEE"               
                        }
                      ]
                    }
                  },
                  "a:PhoneNum": { "-i:nil": "true" }               
                }
              ]
            }
          },
          "a:OutHeader": {
            "-xmlns:b": "http://schemas.org",
            "b:IsSuccessfull": "true",
            "b:ResponseMessage": "Success",
            "b:Responsecode": "1"
          }
        }
      }
    }
  }
}

Offline cavagnaro

  • Administrator
  • Hero Member
  • *****
  • Posts: 7641
  • Karma: 56330
Re: How to parse web service response with a list on Composer 8.1.4?
« Reply #7 on: August 07, 2018, 01:43:18 PM »
Wait but this is how MCP converts it? Or you did a manually conversion?
For being a MCP one looks weird


Enviado de meu E6633 usando o Tapatalk


Offline bilge

  • Newbie
  • *
  • Posts: 27
  • Karma: 0
Re: How to parse web service response with a list on Composer 8.1.4?
« Reply #8 on: August 07, 2018, 02:12:52 PM »
MCP did not show the entire JSON in its logs, so I used an online converter. It seems consistent with partial MCP log I posted before.

Offline cavagnaro

  • Administrator
  • Hero Member
  • *****
  • Posts: 7641
  • Karma: 56330
Re: How to parse web service response with a list on Composer 8.1.4?
« Reply #9 on: August 07, 2018, 02:25:20 PM »
Yeah...which is weird because seems the xml is not converted correctly. The JSON should contain only the XML elements, not the whole headers and definitions.
Which block are you using?


Enviado de meu E6633 usando o Tapatalk


Offline bilge

  • Newbie
  • *
  • Posts: 27
  • Karma: 0
Re: How to parse web service response with a list on Composer 8.1.4?
« Reply #10 on: August 08, 2018, 05:33:24 AM »
I need the  first Name of the Info block "AAA" for instance.

Offline René

  • Administrator
  • Hero Member
  • *****
  • Posts: 1832
  • Karma: 62
Re: How to parse web service response with a list on Composer 8.1.4?
« Reply #11 on: August 08, 2018, 07:55:39 AM »
Expression below should return 'AAA' assuming that JSON object (shown in your previous post) is stored in the AppState.Variable.SearchServResponse variable

AppState.Variable.SearchServResponse['s:Envelope']['s:Body']['SearchResponse']['SearchResult']['a:SearchList']['a:SearchRow']['a:SearchInfo'][0]['a:List']['a:Row']['a:Info'][0]['a:Name']

R.

Offline bilge

  • Newbie
  • *
  • Posts: 27
  • Karma: 0
Re: How to parse web service response with a list on Composer 8.1.4?
« Reply #12 on: August 08, 2018, 09:53:32 AM »
Thank you guys, I can get the parameter now. I need to be more patient next time, it was all about json. I thought it is not possible to get the parameter after some trials similar to the right method, so I posted it here.

Best Regards.

Offline cavagnaro

  • Administrator
  • Hero Member
  • *****
  • Posts: 7641
  • Karma: 56330
Re: How to parse web service response with a list on Composer 8.1.4?
« Reply #13 on: August 08, 2018, 03:11:38 PM »
Still looks weird for me...the JSON should be more friendly, without all that info about the WS itself.