6 Replies Latest reply on Jan 13, 2010 10:40 PM by BKBK

    Submit values and retrieve responses from xml api

    lovewebdev Level 1

      I use this code to submit to an api

       

      <cfhttp url="<api url>" method="GET" resolveurl="No" ></cfhttp>

       

      I get back

       


      <VerifySignatureResponse>
      −<VerifySignatureResult>
      <VerificationStatus>Success</VerificationStatus>
      </VerifySignatureResult>
      </VerifySignatureResponse>

       

      How do I retrieve the response? I ned to get back the Success for the VerificationStatus parameter

        • 1. Re: Submit values and retrieve responses from xml api
          -==cfSearching==- Level 4

          If the response is xml, try parsing it with XMLParse(). It returns a "structure-like" object. You can then access the elements with dot/array notation. Cfdump the results of XMLParse() to visualize how to access the element you need.

           

          http://livedocs.adobe.com/coldfusion/8/htmldocs/help.html?content=functions_t-z_23.html

          http://livedocs.adobe.com/coldfusion/8/htmldocs/functions_t-z_23.html

          • 2. Re: Submit values and retrieve responses from xml api
            BKBK Adobe Community Professional & MVP

            <!--- general case --->


            <!--- <cfxml variable="xmlString"><cfoutput>#cfhttp.FileContent#</cfoutput></cfxml> --->

             

            <cfxml variable="xmlString">
            <VerifySignatureResponse>
            <VerifySignatureResult>
            <VerificationStatus>Success</VerificationStatus>
            </VerifySignatureResult>
            </VerifySignatureResponse>
            </cfxml>

             

            <cfset statusArray=xmlSearch(xmlString,"//VerificationStatus")>
            <cfdump var="#statusArray#">
            status: <cfoutput>#statusArray[1].xmlText#</cfoutput>
            • 3. Re: Submit values and retrieve responses from xml api
              lovewebdev Level 1

              I don't really understand this cfxml code

               

              In this case you hard coded the word Success.

               

              In the real application the xml is hosted on another server. I send some variables in the URL querystring to the url.

               

              When I enter the url directly in the address bar o the browser I see the xml sheet and the response.

               

              I want to automatically read what was returned through coldfusion

              • 4. Re: Submit values and retrieve responses from xml api
                ilssac Level 5

                He was showing you and example of how to parse and view XML data.  Since he did not have access to your web service to get the xml he created an example of it in his code so that he had some xml data to parse and show you.

                 

                You can assume everthing in between the <cfxml...> tags is the same as your <cfhttp...> tag.  It creates some xml data to be utilized.

                • 5. Re: Submit values and retrieve responses from xml api
                  lovewebdev Level 1

                  Thanks I used some working code I had on another page and rebuild around this app.

                   

                  I always need to have these resources next to me because I forget how to build the code

                   

                  this works for me

                   

                   

                  <cfhttp url="<api url>" method="GET" resolveurl="No" ></cfhttp>

                   

                  <cfset mydoc = XmlParse(CFHTTP.FileContent)>
                  <cfset pb = mydoc.variable1.XmlChildren>
                  <cfset size = ArrayLen(pb)>
                  <cfset myquery = QueryNew("variable1,variable2, variable3")>
                  <cfset temp = QueryAddRow(myquery, #size#)>
                  <cfset temp = QuerySetCell(myquery, "variable3", #mydoc.variable3.XmlText#)>

                   

                  <cfif #mydoc.variable1.variable2.variable3.XmlText# eq "Success">

                  Action
                  </cfif>

                  • 6. Re: Submit values and retrieve responses from xml api
                    BKBK Adobe Community Professional & MVP

                    this works for me

                     

                     

                    <cfhttp url="<api url>" method="GET" resolveurl="No" ></cfhttp>

                     

                    <cfset mydoc = XmlParse(CFHTTP.FileContent)>
                    <cfset pb = mydoc.variable1.XmlChildren>
                    <cfset size = ArrayLen(pb)>
                    <cfset myquery = QueryNew("variable1,variable2, variable3")>
                    <cfset temp = QueryAddRow(myquery, #size#)>
                    <cfset temp = QuerySetCell(myquery, "variable3", #mydoc.variable3.XmlText#)>

                     

                    <cfif #mydoc.variable1.variable2.variable3.XmlText# eq "Success">

                    Action
                    </cfif>


                    You apparently didn't take the hint, Ian's or mine. What you've done may be correct, it unnecessarily involves too many functions. You could really do it more efficiently, like this

                     

                    <cfxml variable="xmlString"><cfoutput>#cfhttp.FileContent#</cfoutput></cfxml>

                    <cfset statusArray=xmlSearch(xmlString,"//VerificationStatus")>

                    <cfif statusArray[1].xmlText eq "Success">
                    Action
                    </cfif>