• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Passing CF variables in soap request

Community Beginner ,
Jul 03, 2012 Jul 03, 2012

Copy link to clipboard

Copied

Hello,

I have been successful at getting a return from a third party API. Now I need to use that return (session key) on other soap requests in their API in order to retrieve information. I am storing the session key as a variable and was hoping to use this in subsequent calls to their API, however, it is not working. I am getting an error that tells me the session key is 'invalid and is outside the bounds of an array'. Does anyone know if it is possible to store and pass variables in susbsequest soap requests? Any help would be greatly appreciated!!!!

<!--- WSDL --->
<cfset wsdl_url="http://someurl?wsdl">

<!--- Compose SOAP message to send to Web Service--->
    <cfsavecontent variable="soap"><?xml version="1.0" encoding="UTF-8" ?>
         <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
             <soapenv:Body>
                 <Login xmlns="http://www.siretechnologies.com/">
      <LicenseKey>licenseKey</LicenseKey>
      <Username>user</Username>
      <Password>pass</Password>
      <LicenseType>2</LicenseType>
      <APIKey>APIKey</APIKey>
      <SiteKey></SiteKey>
      <CryptKey></CryptKey>
      <WebOnly>false</WebOnly>
    </Login>
              </soapenv:Body>
          </soapenv:Envelope>
    </cfsavecontent>


        <!--- Invoke web service to send message--->
        <cfhttp url="#wsdl_url#" method="post" >
            <cfhttpparam type="header" name="content-type" value="text/xml">
            <cfhttpparam type="header" name="SOAPAction" value="http://www.siretechnologies.com/Login">
            <cfhttpparam type="header" name="content-length" value="#len(soap)#">
            <cfhttpparam type="header" name="charset" value="utf-8">
            <cfhttpparam type="xml" name="message" value="#trim(soap)#">
        </cfhttp>
        <p><cfoutput>#xmlFormat(cfhttp.fileContent)#</cfoutput> </p>
        <cfset MyXml = XmlParse(cfhttp.fileContent)>

  <cfdump var="#MyXml#">
 
<cfset responseNodes = xmlSearch(MyXml,"//*[ local-name() = 'LoginResponse' ]")>
     <cfdump var="#responseNodes#">

<cfoutput>
<cfloop from="1" to="#arraylen(responseNodes)#" index="i">
    <cfset BookXML = xmlparse(responseNodes)>
<cfset SesKey = "#BookXML.LoginResponse.LoginResult.XmlText#">
    <b>SessionKey:</b> #BookXML.LoginResponse.LoginResult.XmlText#<br>
    <b>Session Key:#SesKey#
</cfloop>
</cfoutput>

<!--- GETUserId, Next call to API--->
<cfset wsdl_url="http://someurl/sire.asmx?wsdl">

<cfset sesKey2 = "#SesKey#">

  

<!--- Compose SOAP message to send to Web Service--->
    <cfsavecontent variable="soap"><?xml version="1.0" encoding="UTF-8" ?>
         <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
             <soapenv:Body>
                 <GetUserId xmlns="http://www.siretechnologies.com/">
                 <SessionKey>sesKey2</SessionKey>
      <UserName>user</UserName>
                 </GetUserId>
               </soapenv:Body>
          </soapenv:Envelope>
    </cfsavecontent>

Views

10.9K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Explorer , Jul 06, 2012 Jul 06, 2012

Emily LaMunyon wrote:

When I run the script you provided with the credentials needed. I get a page that reads:

"1st API call did not return XML"

Also I am not getting any other errors.

Hi Emily,

You're welcome, and that message indicates that the 1st call doesn't even return properly.  So we can disregard the 2nd call for the time being.  Could you try this, and let us know what the output is?

<!--- WSDL --->

<cfset wsdl_url="http://someurl/sirewebsvc/sire.asmx?wsdl">

<!--- Compose SOAP message to send

...

Votes

Translate

Translate
Enthusiast ,
Jul 03, 2012 Jul 03, 2012

Copy link to clipboard

Copied

You forgot the # marks around the sesKey2 variable in the SOAP request.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Jul 03, 2012 Jul 03, 2012

Copy link to clipboard

Copied

didn't mean to het send so soon.  I think you are mis-thinking the action of the line of code

<cfset sesKey2 = "#SesKey#">

Putting the hash marks inside of the var isn't going to make it automatically evaluate a reference to sesKey2.  All you probalby need to do is to remove that line of code, and in the SOAP replace

<SessionKey>sesKey2</SessionKey>

with

<SessionKey>#sesKey#</SessionKey>

Is the username really "user"? or is that another case where the username is in a var called "user", in which case you'll need hash marks there as well.

-reed


Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jul 03, 2012 Jul 03, 2012

Copy link to clipboard

Copied

Thanks for the response Reed!

I tried your suggestion and am still getting the same error, it is like the variable is not being passed from above.

<SessionKey>#sesKey#</SessionKey>

Also, user is just a filler for the forum, it is really survweb and that seems to be working well.

Any other thoughts?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Jul 03, 2012 Jul 03, 2012

Copy link to clipboard

Copied

What value is being put into the soap xml doc?  Try CFDUMPing it to see. I think you are missing a CFOUTPUT inside of the CFSAVECONTENT tag.  Better yet, stop using the CFSAVECONTENT to create the SOAP document, and use CFXML tag instead.  That way if there are structural problems in the XML doc, you'll get better error reporting.

-reed

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 05, 2012 Jul 05, 2012

Copy link to clipboard

Copied

<cfloop from="1" to="#arraylen(responseNodes)#" index="i">

    <cfset BookXML = xmlparse(responseNodes)>

<cfset SesKey = "#BookXML.LoginResponse.LoginResult.XmlText#">

    <b>SessionKey:</b> #BookXML.LoginResponse.LoginResult.XmlText#<br>

    <b>Session Key:#SesKey#

</cfloop>

Yet another point besides those Reed Powell has discussed. You are looping across the array responseNodes, but overwriting the one value of sesKey each time. Shouldn't you define sesKey as an array, for example, and write the values like this instead?

<cfset sesKey = arrayNew(1)>

<cfloop from="1" to="#arraylen(responseNodes)#" index="i">

    <cfset BookXML = xmlparse(responseNodes)>

    <cfset SesKey = BookXML.LoginResponse.LoginResult.XmlText>

    <b>SessionKey:</b> #SesKey#<br>

</cfloop>

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jul 05, 2012 Jul 05, 2012

Copy link to clipboard

Copied

Thanks BKBK!!

I tried your suggestion and am still not able to pass the seesion key variable correctly in the bolded text below. Do you think the session key is being overwritten, and that is why it won't work twice? Any other ideas????

<cfloop from="1" to="#arraylen(responseNodes)#" index="i">

    <cfset BookXML = xmlparse(responseNodes)>

    <cfset SesKey = "#BookXML.LoginResponse.LoginResult.XmlText#">

    <b>SessionKey:</b> #BookXML.LoginResponse.LoginResult.XmlText#<br>

    <b>Session Key:#SesKey#

</cfloop>

</cfoutput>

<!--- GETFILEPDF --->

<cfset wsdl_url2="http://slcsireapp-tst/sirewebsvc/sire.asmx?wsdl">

    <!--- Compose SOAP message to send to Web Service--->

    <cfsavecontent variable="soap"><?xml version="1.0" encoding="UTF-8" ?>

         <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

             <soapenv:Body>

                 <GetUserId xmlns="http://www.siretechnologies.com/">

                 <SessionKey>#SesKey#</SessionKey>

                  <UserName>survweb</UserName>

                 </GetUserId>

               </soapenv:Body>

          </soapenv:Envelope>

    </cfsavecontent>

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Jul 05, 2012 Jul 05, 2012

Copy link to clipboard

Copied

Emily LaMunyon wrote:

<cfset SesKey = "#BookXML.LoginResponse.LoginResult.XmlText#">

Hi Emily,

If you <cfdump var="#SesKey#" /> are the values identical or unique in every row?

Thanks,

-Aaron

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jul 05, 2012 Jul 05, 2012

Copy link to clipboard

Copied

Thanks Aaron!

When I do a dump of #SesKey# I get only one row.

Does that help?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Jul 05, 2012 Jul 05, 2012

Copy link to clipboard

Copied

Emily LaMunyon wrote:

When I do a dump of #SesKey# I get only one row.

Hi Emily,

You're welcome and that does help.  Next question: Are you wanting to make the 2nd API call for every result returned from the 1st API call?

Meaning, should the 2nd API call be within this: <cfloop from="1" to="#arraylen(responseNodes)#" index="i"> 2nd_API_call_in_here </cfloop> ?

Or the 2nd API call will only be made once, regardless of the number of results from the 1st API call?

Thanks,

-Aaron

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jul 05, 2012 Jul 05, 2012

Copy link to clipboard

Copied

Thanks again Aaron.

I think I understand your question correctly. Yes, I am wanting to make the second API call with the results (session key) obtained from the first API call. I need to obtain this session key and use it in subsequest API calls in order to get documents.

I am not sure how to answer this: <cfloop from="1" to="#arraylen(responseNodes)#" index="i"> 2nd_API_call_in_here </cfloop> ?

I was hoping to store the Session Key as a variable and use it to make my next call.

<cfsavecontent variable="soap"><?xml version="1.0" encoding="UTF-8" ?>

         <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

             <soapenv:Body>

                 <GetUserId xmlns="http://www.siretechnologies.com/">

                 <SessionKey>#SesKey#</SessionKey>

                  <UserName>survweb</UserName>

                 </GetUserId>

               </soapenv:Body>

          </soapenv:Envelope>

    </cfsavecontent>

Sorry I am so new to CF ...

Let me know if you need more info.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Jul 05, 2012 Jul 05, 2012

Copy link to clipboard

Copied

Hi Emily,

No problem at all, and you're welcome.  The cfloop may be unnecessary.  Could you please try this?

<cfset responseNodes = xmlSearch(MyXml,"//*[ local-name() = 'LoginResult' ]")>

<cfif arrayLen(responseNodes)>

  <cfset SesKey = responseNodes[1].XmlText>

  <!--- GETUserId, Next call to API--->

  <cfset wsdl_url="http://someurl/sire.asmx?wsdl">

  <!--- Compose SOAP message to send to Web Service--->

  <cfxml variable="soap">

  <cfoutput>

  <?xml version="1.0" encoding="UTF-8" ?>

  <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

    <soapenv:Body>

      <GetUserId xmlns="http://www.siretechnologies.com/">

        <SessionKey>#SesKey#</SessionKey>

        <UserName>survweb</UserName>

      </GetUserId>

    </soapenv:Body>

  </soapenv:Envelope>

  </cfoutput>

  </cfxml>

</cfif>

Thanks,

-Aaron

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 06, 2012 Jul 06, 2012

Copy link to clipboard

Copied

If there is no need for a loop, then you could just do:

<cfset sesKey = responseNodes[1].LoginResponse.LoginResult.XmlText>

<b>SesKey:</b> #sesKey#<br>

However, I can think of one case where the loop is necessary. For example, if the possibility exists that the code will generate more than one value of LoginResult.Xmltext. If so, you may need to validate the value of the session key. For example, by ruling out empty strings. Something like this:

<cfset sessionKey = arrayNew(1)>

<cfloop from="1" to="#arraylen(responseNodes)#" index="i">

    <cfset sessionKey = responseNodes.LoginResponse.LoginResult.XmlText>

    <!--- Validation assumed here is: length of session key > 0. Then set the first non-empty string as session key, and exit the loop --->

    <cfif trim(sessionKey) is not "">

        <cfset sesKey = sessionKey>

        <b>SessionKey:</b> #SesKey#<br>

        <cfbreak>

    </cfif>

</cfloop>

<!--- GETFILEPDF --->

<cfset wsdl_url2="http://slcsireapp-tst/sirewebsvc/sire.asmx?wsdl">

<!--- Compose SOAP message to send to Web Service--->

<cfsavecontent variable="soap"><?xml version="1.0" encoding="UTF-8" ?>

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

     <soapenv:Body>

         <GetUserId xmlns="http://www.siretechnologies.com/">

         <SessionKey>#sesKey#</SessionKey>

          <UserName>survweb</UserName>

         </GetUserId>

       </soapenv:Body>

  </soapenv:Envelope>

</cfsavecontent>

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jul 06, 2012 Jul 06, 2012

Copy link to clipboard

Copied

ERROR.gifHi Aaron,

You are awesome! It makes sense to not use cfloop. I tried your code and am getting the attached error on this line <cfset UserIdXml  = XmlParse(cfhttp.fileContent)> .

It seems to be getting somewhere though, maybe I mistyped something. Here is my full code:

<!--- WSDL --->

<cfset wsdl_url="http://someurl/sirewebsvc/sire.asmx?wsdl">

<!--- Compose SOAP message to send to Web Service--->

    <cfsavecontent variable="soap"><?xml version="1.0" encoding="UTF-8" ?>

         <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

             <soapenv:Body>

                 <Login xmlns="http://www.siretechnologies.com/">

      <LicenseKey>licenseKey</LicenseKey>

      <Username>survweb</Username>

      <Password>survweb</Password>

      <LicenseType>2</LicenseType>

      <APIKey>API</APIKey>

      <SiteKey></SiteKey>

      <CryptKey></CryptKey>

      <WebOnly>false</WebOnly>

    </Login>

              </soapenv:Body>

          </soapenv:Envelope>

    </cfsavecontent>

        <!--- Invoke web service to send message--->

        <cfhttp url="#wsdl_url#" method="post" >

            <cfhttpparam type="header" name="content-type" value="text/xml">

            <cfhttpparam type="header" name="SOAPAction" value="http://www.siretechnologies.com/Login">

            <cfhttpparam type="header" name="content-length" value="#len(soap)#">

            <cfhttpparam type="header" name="charset" value="utf-8">

            <cfhttpparam type="xml" name="message" value="#trim(soap)#">

        </cfhttp>

        <p><cfoutput>#xmlFormat(cfhttp.fileContent)#</cfoutput> </p>

        <cfset MyXml = XmlParse(cfhttp.fileContent)>

        <cfdump var="#MyXml#">

<cfset responseNodes = xmlSearch(MyXml,"//*[ local-name() = 'LoginResult' ]")>

<cfif arrayLen(responseNodes)>

  <cfset SesKey = responseNodes[1].XmlText>

  <!--- GETUserId, Next call to API--->

  <cfset wsdl_url="http://slcsireapp-tst/sire.asmx?wsdl">

  <!--- Compose SOAP message to send to Web Service--->

  <cfxml variable="soap">

  <cfoutput>

  <?xml version="1.0" encoding="UTF-8" ?>

  <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

    <soapenv:Body>

      <GetUserId xmlns="http://www.siretechnologies.com/">

        <SessionKey>#SesKey#</SessionKey>

        <UserName>survweb</UserName>

      </GetUserId>

    </soapenv:Body>

  </soapenv:Envelope>

  </cfoutput>

  </cfxml>

</cfif>

        <!--- Invoke web service to send message--->

        <cfhttp url="#wsdl_url#" method="post" >

            <cfhttpparam type="header" name="content-type" value="text/xml">

            <cfhttpparam type="header" name="SOAPAction" value="http://www.siretechnologies.com/GetUserId">

            <cfhttpparam type="header" name="content-length" value="#len(soap)#">

            <cfhttpparam type="header" name="charset" value="utf-8">

            <cfhttpparam type="xml" name="message" value="#trim(soap)#">

        </cfhttp>

        <p><cfoutput>#xmlFormat(cfhttp.fileContent)#</cfoutput> </p>

      <cfset UserIdXml  = XmlParse(cfhttp.fileContent)>

        <cfdump var="#UserIdXml#">

    <cfset responseNodesUser = xmlSearch(UserIdXml,"//*[ local-name() = 'GetUserIdResponse' ]")>

   <cfdump var="#responseNodesUser#">

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jul 06, 2012 Jul 06, 2012

Copy link to clipboard

Copied

Hi Emily,

Thank you, and I don't mind if you unmark my response as the answer.  Reed and BKBK have also provided valid answers.  Without the API key, login info, etc (which understandably you would not post in a public forum) we can only guess as to what the API should be returning and what it is actually returning.  Example: you may or may not need the cfloop. 

As for 'UserIdXml = XmlParse(cfhttp.fileContent)' throwing an 'error occured while Parsing an XML document', that is b/c the 2nd cfhttp call is not returning XML for some reason.

(side note: Adobe, that should be "occurred" not "occured".)

Could you please try this, and let us know what the output is?

<!--- WSDL --->

<cfset wsdl_url="http://someurl/sirewebsvc/sire.asmx?wsdl">

<!--- Compose SOAP message to send to Web Service--->

<cfxml variable="soap">

<?xml version="1.0" encoding="UTF-8" ?>

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

  <soapenv:Body>

    <Login xmlns="http://www.siretechnologies.com/">

      <LicenseKey>licenseKey</LicenseKey>

      <Username>survweb</Username>

      <Password>survweb</Password>

      <LicenseType>2</LicenseType>

      <APIKey>API</APIKey>

      <SiteKey></SiteKey>

      <CryptKey></CryptKey>

      <WebOnly>false</WebOnly>

    </Login>

  </soapenv:Body>

</soapenv:Envelope>

</cfxml>

<!--- Invoke web service to send message--->

<cfhttp url="#wsdl_url#" method="post" >

<cfhttpparam type="header" name="content-type" value="text/xml">

<cfhttpparam type="header" name="SOAPAction" value="http://www.siretechnologies.com/Login">

<cfhttpparam type="header" name="content-length" value="#len(trim(soap))#">

<cfhttpparam type="header" name="charset" value="utf-8">

<cfhttpparam type="xml" name="message" value="#trim(soap)#">

</cfhttp>

<cfif isXML(cfhttp.fileContent)>

  <cfset MyXml = XmlParse(cfhttp.fileContent)>

  <cfset responseNodes = xmlSearch(MyXml,"//*[ local-name() = 'LoginResult' ]")>

  <cfif arrayLen(responseNodes)>

    <cfset SesKey = responseNodes[1].XmlText>

   

    <!--- GETUserId, Next call to API--->

   

    <cfset wsdl_url="http://slcsireapp-tst/sire.asmx?wsdl">

   

    <!--- Compose SOAP message to send to Web Service--->

   

    <cfxml variable="soap">

    <cfoutput>

    <?xml version="1.0" encoding="UTF-8" ?>

    <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

      <soapenv:Body>

        <GetUserId xmlns="http://www.siretechnologies.com/">

          <SessionKey>#SesKey#</SessionKey>

          <UserName>survweb</UserName>

        </GetUserId>

      </soapenv:Body>

    </soapenv:Envelope>

    </cfoutput>

    </cfxml>

  </cfif>

 

  <!--- Invoke web service to send message--->

 

  <cfhttp url="#wsdl_url#" method="post" >

  <cfhttpparam type="header" name="content-type" value="text/xml">

  <cfhttpparam type="header" name="SOAPAction" value="http://www.siretechnologies.com/GetUserId">

  <cfhttpparam type="header" name="content-length" value="#len(trim(soap))#">

  <cfhttpparam type="header" name="charset" value="utf-8">

  <cfhttpparam type="xml" name="message" value="#trim(soap)#">

  </cfhttp>

  <cfif isXML(cfhttp.fileContent)>

    <cfset UserIdXml  = XmlParse(cfhttp.fileContent)>

    <cfset responseNodesUser = xmlSearch(UserIdXml,"//*[ local-name() = 'GetUserIdResponse' ]")>

   

    <cfdump var="#responseNodesUser#" />

   

    <cfelse>

    2nd API call did not return XML

   

    <cfdump var="#cfhttp.fileContent#" />

   

  </cfif>

  <cfelse>

  1st API call did not return XML

</cfif>

Thanks!,

-Aaron

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jul 06, 2012 Jul 06, 2012

Copy link to clipboard

Copied

You are the best Aaron! I will mark everyone who helped.

When I run the script you provided with the credentials needed. I get a page that reads:

"1st API call did not return XML"

Also I am not getting any other errors.

Thanks!!!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jul 06, 2012 Jul 06, 2012

Copy link to clipboard

Copied

Emily LaMunyon wrote:

When I run the script you provided with the credentials needed. I get a page that reads:

"1st API call did not return XML"

Also I am not getting any other errors.

Hi Emily,

You're welcome, and that message indicates that the 1st call doesn't even return properly.  So we can disregard the 2nd call for the time being.  Could you try this, and let us know what the output is?

<!--- WSDL --->

<cfset wsdl_url="http://someurl/sirewebsvc/sire.asmx?wsdl">

<!--- Compose SOAP message to send to Web Service--->

<cfxml variable="soap">

<?xml version="1.0" encoding="UTF-8" ?>

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

  <soapenv:Body>

    <Login xmlns="http://www.siretechnologies.com/">

      <LicenseKey>licenseKey</LicenseKey>

      <Username>survweb</Username>

      <Password>survweb</Password>

      <LicenseType>2</LicenseType>

      <APIKey>API</APIKey>

      <SiteKey></SiteKey>

      <CryptKey></CryptKey>

      <WebOnly>false</WebOnly>

    </Login>

  </soapenv:Body>

</soapenv:Envelope>

</cfxml>

<!--- Invoke web service to send message--->

<cfhttp url="#wsdl_url#" method="post" >

<cfhttpparam type="header" name="content-type" value="text/xml">

<cfhttpparam type="header" name="SOAPAction" value="http://www.siretechnologies.com/Login">

<cfhttpparam type="header" name="content-length" value="#len(trim(soap))#">

<cfhttpparam type="header" name="charset" value="utf-8">

<cfhttpparam type="xml" name="message" value="#trim(soap)#">

</cfhttp>

<cfdump var="#CFHTTP.FileContent#" />

Thanks!,

-Aaron

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jul 06, 2012 Jul 06, 2012

Copy link to clipboard

Copied

This code seems to be working. I see the output of the login result (session key). Would it help to have the credentials for the API?

XML.gif

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jul 06, 2012 Jul 06, 2012

Copy link to clipboard

Copied

Okay, I am sorry to tell you this, but when I run the second to last script you provided, I now get "2nd API  Call did not return XML. I am not sure why it did not work the first time, but I refreshed my browser and ran it again and this is what I see.XML2.gif

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Jul 06, 2012 Jul 06, 2012

Copy link to clipboard

Copied

Emily LaMunyon wrote:

Okay, I am sorry to tell you this, but when I run the second to last script you provided, I now get "2nd API  Call did not return XML. I am not sure why it did not work the first time, but I refreshed my browser and ran it again and this is what I see.

Hi Emily,

Not a problem.  And that error is a 404 stating that /sire.asmx doesn't exist at whatever domain was specified when making the call.  Is it http://www.siretechnologies.com/sire.asmx?  When I access that, I get a 404.  API credentials may help later (thanks for asking), but for now we just need to know what the correct URL for the 2nd call is.  Is there online documentation for this call that is publicly-viewable?

Thanks,

-Aaron

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jul 06, 2012 Jul 06, 2012

Copy link to clipboard

Copied

The API is installed on an internal server in my department. I am sorry this is internal, not sure if that will make this impossible. The address is http://slcsireapp-tst/sire.asmx?wsdl.

<!--- GETUserId, Next call to API--->

  

   <cfset wsdl_url="http://slcsireapp-tst/sire.asmx?wsdl">

  

    <!--- Compose SOAP message to send to Web Service--->

  

    <cfxml variable="soap">

    <cfoutput>

    <?xml version="1.0" encoding="UTF-8" ?>

    <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

      <soapenv:Body>

        <GetUserId xmlns="http://www.siretechnologies.com/">

          <SessionKey>#SesKey#</SessionKey>

          <UserName>survweb</UserName>

        </GetUserId>

      </soapenv:Body>

    </soapenv:Envelope>

    </cfoutput>

    </cfxml>

  </cfif>

Here is a screenshot of the Second API Call, and what it is expecting from SOAP.. I am afriad there is no public documentation for this call.

2nd_API_Call_Soap.gif

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jul 06, 2012 Jul 06, 2012

Copy link to clipboard

Copied

Oh my gosh Aaron, I think I just got it to work. You were right, the URL in that calls the API was wrong.

I am sooo sorry to waste your time. I think the code you provided is working. This is the return I am getting. The 1060 is the userid I was after with the session key. I need to make yet another call to the API using this information, so in essence I can follow the code I have and recreate it for the next call, correct?

You have been a tremendous help!!!!

solution.gif

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Jul 06, 2012 Jul 06, 2012

Copy link to clipboard

Copied

Emily LaMunyon wrote:

Oh my gosh Aaron, I think I just got it to work. You were right, the URL in that calls the API was wrong.

I am sooo sorry to waste your time. I think the code you provided is working. This is the return I am getting. The 1060 is the userid I was after with the session key. I need to make yet another call to the API using this information, so in essence I can follow the code I have and recreate it for the next call, correct?

Awesome and thanks   I was just about to post a copy of that code w/ the URL changed, to see if it'd work.  Yes, you can follow the same code you have.  BUT, I did find a copy of the API at http://209.6.162.132/SIREWebSvc/sire.asmx  I'm going to follow-up w/ another example for you to try which might be even easier.  Oh, and Reed helped on this thread too btw.

I'll follow-up.

Thanks!,

-Aaron

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jul 06, 2012 Jul 06, 2012

Copy link to clipboard

Copied

Thanks Reed as well!!!

Yes , the Sire link you provided is exactly what I am coding against in order to finally make the GETFilePDF call. That is the one I am trying to get to in order to pull a pdf document. I have to make two API calls, Login, GetUserId, and then I can enter the credentials for GetFielPDF.

Have a great weekend!!!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Jul 06, 2012 Jul 06, 2012

Copy link to clipboard

Copied

Emily LaMunyon wrote:

Yes , the Sire link you provided is exactly what I am coding against in order to finally make the GETFilePDF call. That is the one I am trying to get to in order to pull a pdf document. I have to make two API calls, Login, GetUserId, and then I can enter the credentials for GetFielPDF.

Have a great weekend!!!

Hi Emily,

Could you please try this?  Just enter your credential information at the top, and then it should create a file named 'PDFFromAPI.pdf' in the same directory as your script.  If it doesn't, we'll get it sorted.  But based on the API doc I saw, you shouldn't have to use SOAP.  If the file isn't created, just let me know what the result was.

<cfscript>

  apiURLBase = "http://slcsireapp-tst/sirewebsvc/sire.asmx";

  licenseKey = "license_key_here";

  username = "survweb";

  password = "password_here";

  licenseType = 2;

  apiKey = "api_key_here";

  siteKey = "site_key_here";

  cryptKey = "crypt_key_here";

  webOnly = false;

  pdfDestination = expandPath("./PDFFromAPI.pdf");

</cfscript>

<!--- Get Session Key --->

<cfhttp url="#apiURLBase#/Login?LicenseKey=#licenseKey#&Username=#username#&Password=#password#&LicenseType=#licenseType#&APIKey=#apiKey#&SiteKey=#siteKey#&CryptKey=#cryptKey#&WebOnly=#webOnly# HTTP/1.1" />

<cfif isXML(CFHTTP.FileContent)>

  <cfset responseXML = xmlParse(CFHTTP.FileContent) />

  <cfset sessionKey = responseXML.xmlRoot.xmlText />

  <cfelse>

  <p>1st API call did not return valid XML</p>

</cfif>

<!--- Get User ID --->

<cfif structKeyExists(variables, "sessionKey") and len(trim(variables.sessionKey))>

  <cfhttp url="#apiURLBase#/GetUserId?SessionKey=#sessionKey#&Username=#username# HTTP/1.1" />

  <cfif isXML(CFHTTP.FileContent)>

    <cfset responseXML = xmlParse(CFHTTP.FileContent) />

    <cfset userID = responseXML.xmlRoot.xmlText />

    <cfelse>

    <p>2nd API call did not return valid XML</p>

  </cfif>

  <cfelse>

  <p>1st API call did not return a valid value</p>

</cfif>

<!--- Get PDF File --->

<cfif structKeyExists(variables, "userID") and len(trim(variables.userID))>

  <cfset cabinetName = "cabinet_name_here" />

  <cfset fileID = "file_ID_here" />

  <cfset tifOnly = false /><!--- or true --->

  <cfhttp url="#apiURLBase#/GetFilePDF?SessionKey=#sessionKey#&CabinetName=#cabinetName#&FileId=#fileID#&TIFOnly=#tifOnly#&UserId=#userID# HTTP/1.1" />

  <cfif isXML(CFHTTP.FileContent)>

    <cfset responseXML = xmlParse(CFHTTP.FileContent) />

    <cfset pdfBinaryBase64 = responseXML.xmlRoot.xmlText />

    <!--- CF does not have an isBase64() function. The mod 4 check and the try/catch are workarounds for this. --->

    <cfif !(len(pdfBinaryBase64) % 4)>

      <cftry>

        <!--- Save PDF file --->

        <cffile action="write" file="#pdfDestination#" output="#binaryDecode(pdfBinaryBase64, 'base64')#" />

        <cfcatch type="any"></cfcatch>

      </cftry>

    </cfif>

    <cfelse>

    <p>3rd API call did not return valid XML</p>

  </cfif>

  <cfelse>

  <p>2nd API call did not return a valid value</p>

</cfif>

Have a great weekend yourself!,

-Aaron

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation