How to get yahoo weather information using coldfusion - coldfusion

I am a newbie coldfusion developer.
And I want to get yahoo weather information using coldfusion.
So I made a cfm file like this.
<cfset theURL = "https://weather-ydn-yql.media.yahoo.com/forecastrss?location=sunnyvale,ca">
<cfhttp url="#theURL#" charset="utf-8" method="post">
<cfhttpparam type="formfield" name="appid" value="2a0Lkq6k">
<cfhttpparam type="formfield" name="context" value="dj0yJmk9MkxEcTlzVDNucE5hJnM9Y29uc3VtZXJzZWNyZXQmc3Y9MCZ4PWMx">
<cfhttpparam type="formfield" name="query" value="madonna">
</cfhttp>
And I got a error like this.
Your call to Yahoo Web Services returned an unexpected HTTP status of: 401
I have rich experience in laravel, django or so.
But I don't know coldfusion as well as yahoo weather api.
How can I fix this and get the result?

Related

Docusign API with ColdFusion retrieve PDF - documents/combined

I am trying to retrieve the signed documents from Docusign - and save the PDF file locally.
I have tried multiple ways to attempt to extract the PDF out of the returned cfhttp data.
Seems I can get the correct number of pages in the PDF document I download - but they view as all blank with messages of invalid signature.
My guess is that I am not parsing multiple PDF files from the filecontent in the returned cfhttp variable but not finding how to do this anywhere.
My current code is similar to:
<cfhttp url="https://demo.docusign.net/restapi/v2/accounts/#variables.ACCOUNT#/envelopes/#url.ENVELOPE_ID#/documents/combined" method="GET" resolveurl="Yes" throwonerror="No" result="MY_INFO">
<cfhttpparam name="X-DocuSign-Authentication" type="HEADER" value="<DocuSignCredentials><Username>#variables.userName#</Username><Password>#variables.password#</Password><IntegratorKey>#variables.integratorKey#</IntegratorKey></DocuSignCredentials>">
<cfhttpparam name="Content-Type" type="HEADER" value="application/json">
<cfhttpparam name="Accept" type="HEADER" value="application/json">
</cfhttp>
<cffile action="write" file="D:\Inetpub\Wwwroot\docusign\completed\mypdf.pdf" output="#TRIM(MY_INFO.FileContent)#">
Following up here, based on your comments you've solved this:
"Instead of trying to write the file via the cffile - i added
path="D:\Inetpub\Wwwroot\docusign\completed\" file="#variables.FILE_NAME#"
to the cfhttp call"

Attempting to test Docusign REST API in ColdFusion

I found this example and am using it to test the DocuSign REST API in my ColdFusion app. It is the whole of it. I am not not very familiar with the ColdFusion language and am pretty sure I am not handling a response from the server in any way through this request. I do not receive an error and I think that is why and the document/email are not sent.
Can anyone point out where my errors are and help me build in code that will return the error so that I can further troubleshoot the issue? Thanks!
<cffile action="READBINARY" file="875487865.pdf" variable="docData">
<cfset docData = BinaryEncode(docData,"Base64")>
<cfset envelope = "<envelopeDefinition xmlns=""http://www.docusign.com/restapi"">
<status>Sent</status>
<emailSubject>eSignature request</emailSubject>
<emailBlurb>Please sign the document</emailBlurb>
<recipients>
<signers>
<signer>
<recipientId>1</recipientId>
<name>John Doe>john#doe.com</email>
<tabs>
<signHereTabs>
<signHere>
<anchorString>1SI</anchorString>
<documentId>1</documentId>
</signHere>
</signHereTabs>
</tabs>
</signer>
</signers>
</recipients>
<documents>
<document>
<name>875487865.pdf</name>
<documentId>1</documentId>
<fileExtension>pdf</fileExtension>
<documentBase64>#docData#</documentBase64>
</document>
</documents>
</envelopeDefinition>">
<cfhttp url="https://demo.docusign.net/restapi/v2/login_information/envelopes" method="POST" resolveurl="Yes" throwonerror="No">
<cfhttpparam name="X-DocuSign-Authentication" type="HEADER" value=" <DocuSignCredentials><Username>MY_USER_NAME</Username><Password>MY_PASSWORD</Password><IntegratorKey>MY_INT_KEY</IntegratorKey></DocuSignCredentials>">
<cfhttpparam name="Content-Type" type="HEADER" value="application/xml">
<cfhttpparam name="Accept" type="HEADER" value="application/xml">
<cfhttpparam name="Content-Length" type="HEADER" value="#Len(envelope)#">
<cfhttpparam name="request_body" type="BODY" value="#envelope#">
</cfhttp>
Just as Leigh suspected, you are not hitting a valid DocuSign endpoint. I see your POST URL set to this:
https://demo.docusign.net/restapi/v2/login_information/envelopes
Where did you get this URL from as it's not valid? You need to go through the "Making your First API call" section of the DocuSign Developer Center to learn how to properly login (authenticate) and create an envelope / signature request.
https://www.docusign.com/developer-center/quick-start/first-api-call

get content sent with cfhttp post

I have a cfc that makes a call to a remote service using cfhttp. The service is returning a failure code, which means that my call to the remote service is not formatted properly. Is there any way to capture the content of a cfhttp post I'm sending? I want to capture the raw post data so I can see where my formatting problem is. Here is a sample of what my code looks like:
<cfhttp url="https://www.webservice.com" method="POST" result="httpResponse">
<cfhttpparam type="formField" name="method" value="doSomething">
<cfhttpparam type="formField" name="user" value="myUserName">
<cfhttpparam type="formField" name="password" value="myPassword">
</cfhttp>
I'd like to do something like this:
<cfset result = structNew() />
<cfset result["response"] = httpResponse />
<cfset result["sentContent"] = cfhttp.sentContent />
Is it possible to get the content of a sent cfhttp without looking at the server logs. My server is offsite and getting the logs will be a PITA.
You could create a template to which you would POST to. That template could return the result of GetHttpRequestData() function.

Can CFHTTP accept a TARGET value?

I'm working on a Coldfusion page that takes information from a form and posts back to the same page. However, I have a CFHTTP URL string that I want to POST to a PHP page and I want to open in a separate page as well (still leaving the original POST page open. I thought CFHTTP would accept a "target - blank" value but it doesn't. Here's my code:
<cfhttp method="Post" url="https://www.foo.com/foocorp/restrict/fpdf/letter.php" result="adverseResponse">
<cfhttpparam type="Header" name="Accept-Encoding" value="deflate;q=0">
<cfhttpparam type="Header" name="TE" value="deflate;q=0">
<cfoutput>
<cfif isdefined( "b_firstname" )><cfhttpparam name="B_FIRSTNAME" type="formField" value="#B_FIRSTNAME#"></cfif>
<cfif isdefined( "b_lastname" )><cfhttpparam name="B_LASTNAME" type="formField" value="#B_LASTNAME#"></cfif>
<cfif isdefined( "prop_address" )><cfhttpparam name="PROP_ADDRESS" type="formField" value="#PROP_ADDRESS#"></cfif>
<cfif isdefined( "prop_city" )><cfhttpparam name="PROP_CITY" type="formField" value="#PROP_CITY#"></cfif>
<cfif isdefined( "prop_state" )><cfhttpparam name="PROP_STATE" type="formField" value="#PROP_STATE#"></cfif>
<cfif isdefined( "prop_zip" )><cfhttpparam name="PROP_ZIP" type="formField" value="#PROP_ZIP#"></cfif>
</cfoutput>
</cfhttp>
Is there another CF element I should be using instead of CFHTTP?
There's a few misconceptions here. CFHTTP does server to server communication. Whatever happens in CF stays in CF (to coin a slogan). What you are referring to with target="_blank" is something that is happening on the client - where a separate "page" is opened in a "browser". CFHTTP doesn't use a browser. It doesn't render content. It just issues HTTP requests with various headers and params and gives you the response back - all on the server within your cf code. You have to "do" something with the content to send it back to the browser.
So what you need to do is either:
Take the response from CF (adverseResponse.filecontent) and place it in your separate page using a popup or whatever. In this way you are acting as a "proxy" for the browser.
Abandon the CFHTTP route and user jquery or Javascript or whatever to impliment the behavior that posts to the PHP directly in the browser.
Hope this helps.

CFHTTP Content-Length Header for post to Google Voice "API"

Greetings.
I'm trying to send a quick sms through google voice using their existing API. I think the api is what's left from the Grand Central days. They don't have much documentation. Here's where I got my documentation: http://posttopic.com/topic/google-voice-add-on-development
I can authenticate using cfhttp and get the correct response. Then I can get the "_rnr_se" value that is required for request from a google voice command.
When I send over the number, message, and required values (Authorization and _rnr_se), I get a "content-length" is required message from google. But since this is a dynamic post with different form fields, not a file, I'm not sure what to post as the content-length.
If I just put some arbitrary value like "1000" for the content-length, the request just sits there and I never get a response. If I put something like "0" or "500" it comes back with a 500 - "Internal Server Error".
Any ideas on how to get the correct value for content-length before I post?
<cffunction name="submitSMS">
<cfhttp url="https://www.google.com/voice/sms/send/" method="post">
<cfhttpparam type="header" name="Content-Length" value="???">
<cfhttpparam type="header" name="Authorization" value="GoogleLogin auth=#SESSION.GoogleAuth#">
<cfhttpparam name="id" value="" type="formfield">
<cfhttpparam name="phoneNumber" value="+1#params.number#" type="formfield">
<cfhttpparam name="text" value="#params.smsMessage#" type="formfield">
<cfhttpparam name="_rnr_se" value="#SESSION.rnr#" type="formfield">
</cfhttp>
<cfdump var="#cfhttp.FileContent#"><cfabort>
</cffunction>
The better way to do this is to just use the google voice java class here:
http://google-voice-java.googlecode.com