Skip navigation
Emily LaMunyon
Currently Being Moderated

Passing CF variables in soap request

Jul 3, 2012 9:35 AM

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[i])>
<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>

 
Replies 1 2 Previous Next
  • Currently Being Moderated
    Jul 3, 2012 10:31 AM   in reply to Emily LaMunyon

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

     
    |
    Mark as:
  • Currently Being Moderated
    Jul 3, 2012 10:34 AM   in reply to Reed Powell

    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


     
    |
    Mark as:
  • Currently Being Moderated
    Jul 3, 2012 11:20 AM   in reply to Emily LaMunyon

    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

     
    |
    Mark as:
  • Currently Being Moderated
    Jul 5, 2012 3:10 AM   in reply to Emily LaMunyon

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

        <cfset BookXML = xmlparse(responseNodes[i])>

    <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[i])>

        <cfset SesKey[i] = BookXML.LoginResponse.LoginResult.XmlText>

        <b>SessionKey:</b> #SesKey[i]#<br>

    </cfloop>

     
    |
    Mark as:
  • Currently Being Moderated
    Jul 5, 2012 2:06 PM   in reply to Emily LaMunyon

    Emily LaMunyon wrote:

     

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

    Hi Emily,

     

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

     

    Thanks,

    -Aaron

     
    |
    Mark as:
  • Currently Being Moderated
    Jul 5, 2012 2:46 PM   in reply to Emily LaMunyon

    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

     
    |
    Mark as:
  • Currently Being Moderated
    Jul 5, 2012 4:22 PM   in reply to Emily LaMunyon

    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

     
    |
    Mark as:
  • Currently Being Moderated
    Jul 6, 2012 5:07 AM   in reply to itisdesign

    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[i] = responseNodes[i].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[i]) is not "">

            <cfset sesKey = sessionKey[i]>

            <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>

     
    |
    Mark as:
  • Currently Being Moderated
    Jul 6, 2012 11:31 AM   in reply to Emily LaMunyon

    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

     
    |
    Mark as:
  • Currently Being Moderated
    Jul 6, 2012 1:26 PM   in reply to Emily LaMunyon

    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

     
    |
    Mark as:
  • Currently Being Moderated
    Jul 6, 2012 2:56 PM   in reply to Emily LaMunyon

    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

     
    |
    Mark as:
  • Currently Being Moderated
    Jul 6, 2012 3:54 PM   in reply to Emily LaMunyon

    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

     
    |
    Mark as:
  • Currently Being Moderated
    Jul 6, 2012 9:14 PM   in reply to Emily LaMunyon

    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#&P assword=#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=#usernam e# 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=#cab inetName#&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

     
    |
    Mark as:
  • Currently Being Moderated
    Jul 9, 2012 12:09 PM   in reply to Emily LaMunyon

    Emily LaMunyon wrote:

     

    I plugged in my credentials and am getting the following.

    Hi Emily,

     

    I had a mistake at the end of the URL strings.  Could you please try this and let me know the result?

     

    <cfscript>
      apiURLBase = "http://slcsireapp-tst/sirewebsvc/sire.asmx";
      licenseKey = "##W3b5vc|<3y##";
      username = "survweb";
      password = "survweb";
      licenseType = 2;
      apiKey = "api";
      siteKey = "";
      cryptKey = "";
      webOnly = false;
      pdfDestination = expandPath("./PDFFromAPI.pdf");
    </cfscript>

    <!--- Get Session Key --->
    <cfhttp url="#apiURLBase#/Login?LicenseKey=#licenseKey#&Username=#username#&P assword=#password#&LicenseType=#licenseType#&APIKey=#apiKey#&SiteKey=# siteKey#&CryptKey=#cryptKey#&WebOnly=#webOnly#" />

    <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>
      <cfoutput>#CFHTTP.FileContent#</cfoutput>
      <cfabort />
    </cfif>

    <!--- Get User ID --->
    <cfif structKeyExists(variables, "sessionKey") and len(trim(variables.sessionKey))>
      <cfhttp url="#apiURLBase#/GetUserId?SessionKey=#sessionKey#&Username=#usernam e#" />
      <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>
        <cfoutput>#CFHTTP.FileContent#</cfoutput>
        <cfabort />
      </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 = "Surveys" />
      <cfset fileID = "105684" />
      <cfset tifOnly = false />
      <!--- or true --->
      <cfhttp url="#apiURLBase#/GetFilePDF?SessionKey=#sessionKey#&CabinetName=#cab inetName#&FileId=#fileID#&TIFOnly=#tifOnly#&UserId=#userID#" />
      <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>
        <cfoutput>#CFHTTP.FileContent#</cfoutput>
        <cfabort />
      </cfif>
      <cfelse>
      <p>2nd API call did not return a valid value</p>
    </cfif>

     

    Thanks!,

    -Aaron

     
    |
    Mark as:
  • Currently Being Moderated
    Jul 9, 2012 2:06 PM   in reply to Emily LaMunyon

    Hi Emily,

     

    Yes, we're getting closer!  Could you please try this?  I updated the URL attribute of the 3 cfhttp tags (using CF9 syntax, as it appears you're on CF9?).

     

    <cfscript>

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

      licenseKey = "##W3b5vc|<3y##";

      username = "survweb";

      password = "survweb";

      licenseType = 2;

      apiKey = "api";

      siteKey = "";

      cryptKey = "";

      webOnly = false;

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

    </cfscript>

     

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

    <cfhttp url="#apiURLBase#/Login?LicenseKey=#urlEncodedFormat(licenseKey)#&Use rname=#urlEncodedFormat(username)#&Password=#urlEncodedFormat(password )#&LicenseType=#urlEncodedFormat(licenseType)#&APIKey=#urlEncodedForma t(apiKey)#&SiteKey=#urlEncodedFormat(siteKey)#&CryptKey=#urlEncodedFor mat(cryptKey)#&WebOnly=#urlEncodedFormat(webOnly)#" />

     

    <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>

      <cfoutput>#CFHTTP.FileContent#</cfoutput>

      <cfabort />

    </cfif>

     

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

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

      <cfhttp url="#apiURLBase#/GetUserId?SessionKey=#urlEncodedFormat(sessionKey)# &Username=#urlEncodedFormat(username)#" />

      <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>

        <cfoutput>#CFHTTP.FileContent#</cfoutput>

        <cfabort />

      </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 = "Surveys" />

      <cfset fileID = "105684" />

      <cfset tifOnly = false />

      <!--- or true --->

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

      <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>

        <cfoutput>#CFHTTP.FileContent#</cfoutput>

        <cfabort />

      </cfif>

      <cfelse>

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

    </cfif>

     

    Thanks,

    -Aaron

     
    |
    Mark as:
  • Currently Being Moderated
    Jul 9, 2012 3:40 PM   in reply to Emily LaMunyon

    Emily LaMunyon wrote:

     

    ##W3b5vc|<3y##

    Hi Emily,

     

    Did they provide you with ##W3b5vc|<3y## or with #W3b5vc|<3y#  ?

     

    Meaning, two or one # at both ends?

     

    Thanks,

    -Aaron

     
    |
    Mark as:
  • Currently Being Moderated
    Jul 9, 2012 3:46 PM   in reply to itisdesign

    itisdesign wrote:

     

    Emily LaMunyon wrote:

     

    ##W3b5vc|<3y##

    Did they provide you with ##W3b5vc|<3y## or with #W3b5vc|<3y#  ?

    I'll assume the former (w/ 2 # at both sides)..  Could you try this?

     

    <cfscript>

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

      licenseKey = "####W3b5vc|<3y####";//CF converts each ## to # (# is a special character in CF)

      username = "survweb";

      password = "survweb";

      licenseType = 2;

      apiKey = "api";

      siteKey = "";

      cryptKey = "";

      webOnly = false;

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

    </cfscript>

     

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

    <cfhttp url="#apiURLBase#/Login?LicenseKey=#urlEncodedFormat(licenseKey)#&Use rname=#urlEncodedFormat(username)#&Password=#urlEncodedFormat(password )#&LicenseType=#urlEncodedFormat(licenseType)#&APIKey=#urlEncodedForma t(apiKey)#&SiteKey=#urlEncodedFormat(siteKey)#&CryptKey=#urlEncodedFor mat(cryptKey)#&WebOnly=#urlEncodedFormat(webOnly)#" />

     

    <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>

      <cfoutput>#CFHTTP.FileContent#</cfoutput>

      <cfabort />

    </cfif>

     

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

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

      <cfhttp url="#apiURLBase#/GetUserId?SessionKey=#urlEncodedFormat(sessionKey)# &Username=#urlEncodedFormat(username)#" />

      <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>

        <cfoutput>#CFHTTP.FileContent#</cfoutput>

        <cfabort />

      </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 = "Surveys" />

      <cfset fileID = "105684" />

      <cfset tifOnly = false />

      <!--- or true --->

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

      <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>

        <cfoutput>#CFHTTP.FileContent#</cfoutput>

        <cfabort />

      </cfif>

      <cfelse>

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

    </cfif>

     

    Oh and you're welcome btw.

     

    Thanks!,

    -Aaron

     
    |
    Mark as:
  • Currently Being Moderated
    Jul 9, 2012 3:55 PM   in reply to Emily LaMunyon

    Emily LaMunyon wrote:

     

    This is the original license key they provided me, two # on each end.

     

    ##W3b5vc|<3y##

     

    I was able to get ##W3b5vc|&lt;3y## to work with soap, replacing the < with &lt; and it seemed okay. Not sure why cfhttp doesn’t like either of the license keys.

     

    I am looking into charsets on cfhttp now, not getting much info though.

    Hi Emily,

     

    I see you just sent this reply right before my last reply.  Very cool, I assumed it should have 2 # on each side in my last example.  So please go ahead and try that last example I posted.  The issue was the #.  And the issue is described in the last example on this doc page about escaping quotation marks and number signs.

     

    Thanks,

    -Aaron

     
    |
    Mark as:
  • Currently Being Moderated
    Jul 10, 2012 11:38 AM   in reply to Emily LaMunyon

    Hi Emily,

     

    Good to hear the # sign issue is resolved.  I have no idea what it wants for fileID and cabinetName, so hopefully the Sire people will be able to help w/ that.  I'm _guessing_ the issue may be the cabinetName.. perhaps there is a 'tree' of cabinets (like a folder structure) and perhaps the Surveys cabinet is located w/in another cabinet?  As in CabinetName="/path/to/Surveys" or something like that.  Dunno, just guessing.

     

    And you're welcome!

     

    Thanks,

    -Aaron

     
    |
    Mark as:
  • Currently Being Moderated
    Jul 10, 2012 12:20 PM   in reply to itisdesign

    Apparently, the last isXML(CFHTTP.FileContent) test is false. Processing therefore moves to the cfelse block. My suggestion is to print out and examine the URL of the HTTP call. Something like this:

     

    <cfelse>

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

    <cfoutput>

        <p>CFHTTP.FileContent: #CFHTTP.FileContent#</p>

        <p>url="#apiURLBase#/GetFilePDF?SessionKey=#urlEncodedFormat(sessionK ey) #&CabinetName=#urlEncodedFormat(cabinetName)#&FileId=#urlEncodedForma t  (fileID)#&TIFOnly=#urlEncodedFormat(tifOnly)#&UserId=#urlEncodedForma t (userID)#"</p>

    </cfoutput>

        <cfabort />

      </cfif>

     

    Where does the extraneous string "--->" in the error message come from? If it is coming in as part of CFHTTP.FileContent, then it could be pointing to a problem in the called page.

     
    |
    Mark as:
  • Currently Being Moderated
    Jul 12, 2012 9:52 PM   in reply to Emily LaMunyon

    Emily LaMunyon wrote:

     

    First, I forgot that I have to call the Logout method

    Hi Emily,

     

    Sorry, the logout response isn't the same format as the others.  It doesn't return an XML response at all.  Instead, it just returns an HTTP status code.  Could you please try this?

     

    <!--- Logout --->

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

      <cfhttp url="#apiURLBase#/Logout?SessionKey=#urlEncodedFormat(sessionKey)#"/>

      <cfif CFHTTP.statuscode is "200 OK">

        <p>Logout successful</p>

      </cfif>

      <cfelse>

      <p>Logout unsuccessful</p>

    </cfif>

     

    I'll follow-up regarding your second question.

     

    Thanks,

    -Aaron

     
    |
    Mark as:
  • Currently Being Moderated
    Jul 13, 2012 12:45 AM   in reply to Emily LaMunyon

    Emily LaMunyon wrote:

     

    Second, I am interested in the ability to have the file_id be dynamic, where the user is able to select the file through a query, instead of having to hard-code it in. Is this pocssible in this scenario?


    That immediately suggests replacing the block:

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

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

      <cfset cabinetName = "Surveys" />

      <cfset fileID = "105684" />

      <cfset tifOnly = false />

    ...

    ...

     

    with something like

     

    <cfquery name="getID">

    SELECT id

    FROM appropriate_file_TBL

    WHERE etc., etc.

    </cfquery>

     

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

    <!--- User validation assumes cflogin/cfloginuser was used --->

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

      <cfset cabinetName = "Surveys">

      <cfset fileID = getID.id>

      <cfset tifOnly = false>

    ...

    ...

     
    |
    Mark as:
1 2 Previous Next

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points