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>
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
...Copy link to clipboard
Copied
Thanks so much again guys, this looks like it will do the trick. I plugged in my credentials and am getting the following.

It may have to do with my license key, I was having problems with it before using this http post method. The license key is ##W3b5vc|<3y##, and in the soap request I had to escape the < character and use ##W3b5vc|<3y## instead. I have tried both in the code you provided and still get the same result as above. Do you think this could be causing problems? Here is the code I used, maybe I missed something.
<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#&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 = "Surveys" />
<cfset fileID = "105684" />
<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>
Copy link to clipboard
Copied
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#&Password=#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=#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=#sessionKey#&CabinetName=#cabinetName#&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
Copy link to clipboard
Copied
Hey Aaron,
Okay, I think we are getting closer. I am now getting the following error. I checked the username and it is correct, survweb.

<cfscript>
apiURLBase = "http://slcsireapp-tst/sirewebsvc/sire.asmx";
licenseKey = "##W3b5vc|<3y##";
username = "survweb";
password = "survweb";
licenseType = 2;
apiKey = "AP1";
siteKey = "";
cryptKey = "";
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#" />
<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=#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=#sessionKey#&CabinetName=#cabinetName#&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>
Copy link to clipboard
Copied
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)#&Username=#urlEncodedFormat(username)#&Password=#urlEncodedFormat(password)#&LicenseType=#urlEncodedFormat(licenseType)#&APIKey=#urlEncodedFormat(apiKey)#&SiteKey=#urlEncodedFormat(siteKey)#&CryptKey=#urlEncodedFormat(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
Copy link to clipboard
Copied
I think this one is the closest so far. Now I am getting an error concerning my license key. I have tried both ##W3b5vc|<3y## and ##W3b5vc|<3y## in this new script. Does anything about this license key string seem like it would not work? I asked Sire about changing it and they said it was hard-coded so it is not possible. Any ideas?
Thanks a trillion!!!

Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
This is the original license key they provided me, two # on each end.
##W3b5vc|<3y##
I was able to get ##W3b5vc|<3y## to work with soap, replacing the < with < 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.
Copy link to clipboard
Copied
Emily LaMunyon wrote:
This is the original license key they provided me, two # on each end.
##W3b5vc|<3y##
I was able to get ##W3b5vc|<3y## to work with soap, replacing the < with < 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
Copy link to clipboard
Copied
Hi Aaron,
The issue with the # signs seems to be solved. I am having problems with the GetFilePDF credentials, even when I test it outside of the code, which is why I think I am getting the following error. I am meeting with Sire on Thursday morning to see why the credentials they provided are not working. I think that is what is behind the Append to PDF error. I will let you know if it works when I get the correct information.
You guys have been so beyond kind for your time and effort on this! ![]()

Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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(sessionKey) #&CabinetName=#urlEncodedFormat(cabinetName)#&FileId=#urlEncodedFormat (fileID)#&TIFOnly=#urlEncodedFormat(tifOnly)#&UserId=#urlEncodedFormat (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.
Copy link to clipboard
Copied
Hey guys,
I solved the problem of the credentials for the GetFilePDF, it turns out that the files weren't even on the server I was testing, so the code could not find them, but they are there now. That part seems to be working. However, I have a couple of other questions.
First, I forgot that I have to call the Logout method after all of this is finished so I do not tie up a license. I took a stab at it and seem to be having issues, I am getting the error in that block that reads "4th API call did not return valid XML". I think I am close though..any thoughts?
<!--- Logout --->
<cfif structKeyExists(variables, "sessionKey") and len(trim(variables.sessionKey))>
<cfhttp url="#apiURLBase#/Logout?SessionKey=#urlEncodedFormat(sessionKey)#"/>
<cfif isXML(CFHTTP.FileContent)>
<cfset responseXML = xmlParse(CFHTTP.FileContent) />
<cfset logout = responseXML.xmlRoot.xmlText />
<cfelse>
<p>4th 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>
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?
Thanks!
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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>
...
...
Copy link to clipboard
Copied
Thanks for all your help BKBK!
I got the logout method working and I think I am getting close on the query part, but I am still having issues. The problem is, I do not have a form for the user to chose their pdf. I want to pass it in a string like this, the coldfusionpage.cfm is the code from above that takes all the credentials.
http://localhost/coldfusionpage.cfm?subdir=23&page_id=624010.pdf
Where the page_id is the fileID in the API request.
<!--- Get PDF File --->
<cfif structKeyExists(variables, "sessionKey") and len(trim(variables.sessionKey))>
<cfset cabinetName = "Surveys" />
<cfset fileID = "624010" />
<cfset tifOnly = false />
I know I need a select staement, something like this:
<cfquery name="getID" datasource="sire_2" dbtype="odbc">
SELECT page_id
FROM slco_sire.dbo.surveys_page
</cfquery>
and you suggested using
<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>
I am just having a hard-time tying this all together.
You all have gone above and beyond and I understand if I have maxed you out.![]()
Copy link to clipboard
Copied
Based on the information you've just provided, I will advise you to ignore my suggestion about the query. If, as you say, the file ID is coming in via the URL
http://localhost/coldfusionpage.cfm?subdir=23&page_id=624010.pdf
then simply replace
<cfset fileID = "624010" />
with
<cfset fileID = listGetAt(URL.page_id, 1, ".") />
That is dynamic enough. With no CPU-consuming query in sight!
Copy link to clipboard
Copied
Thanks BKBK.
So I tried your suggestion and the API seems to not like using this <cfset fileID = listGetAt(URL.page_id, 1, ".") /> instead of a hard-coded fileID. If I pass something like this, http://localhost/coldfusionpage.cfm?subdir=23&page_id=624010.pdf,
are the values suppossed to be exchanged for hard-coded ones? Does it treat this call like a variable?
Thanks!
Copy link to clipboard
Copied
Emily LaMunyon wrote:
So I tried your suggestion and the API seems to not like using this <cfset fileID = listGetAt(URL.page_id, 1, ".") />
Pease expand on what you mean by "seems not to like". If the code
<cfset fileID = "624010" />
works, then I expect
<cfset fileID = listGetAt(URL.page_id, 1, ".") />
to work, too.
I assume that you intend, in every case, to extract the fileID from the file-name of the PDF that comes in through the URL. In the URL you've given, that file-name is the variable URL.page_id. Its value is "624010.pdf". You could treate this as a list with delimiter ".". In that case, "624010" will be the first list element. This is what the last line of code does.
Copy link to clipboard
Copied
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)#&Username=#urlEncodedFormat(username)#&Password=#urlEncodedFormat(password)#&LicenseType=#urlEncodedFormat(licenseType)#&APIKey=#urlEncodedFormat(apiKey)#&SiteKey=#urlEncodedFormat(siteKey)#&CryptKey=#urlEncodedFormat(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
Get ready! An upgraded Adobe Community experience is coming in January.
Learn more