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

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

Related

EZ Text API & ColdFusion

Anyone have any experience with the EZ Text API and ColdFusion? I'm trying this call:
<cfhttp url="https://app.eztexting.com/sending/messages?format=JSON"
method="POST" result="objGet" charset="utf-8">
<cfhttpparam type="header" name="Content-Type" value="application/x-www-form-urlencoded">
<cfhttpparam type="formfield" name="User" value="xxx" />
<cfhttpparam type="formfield" name="Password" value="xxx"/>
<cfhttpparam type="formfield" name="PhoneNumbers[]" value="9999999999" />
<cfhttpparam type="formfield" name="MessageTypeID" value="1" />
<cfhttpparam type="formfield" name="Message" value="Hello" />
</cfhttp>
... which is returning a status code of 200 and trying to redirect to their home page.
Their tech support can only tell me that I should use curl which is not installed on the server that I need it on. I have used curl successfully in my devel environment, so I'm sure that the url and credentials are good.
Any thoughts are welcome! Thanks.
I'm guessing you're using the REST API. If yes, the reason it's redirecting you to the home page is because the URL is incorrect. Apparently the format parameter is case sensitive. So ?format=JSON should be changed to ?format=json (all lower case).
Making that minor adjustment to your code example:
<cfhttp url="https://app.eztexting.com/sending/messages?format=json"
method="POST" result="objGet" charset="utf-8">
...
</cfhttp>
... returns the expected JSON response for bogus credentials, instead of the html for the home page:
{
"Response": {
"Status": "Failure",
"Code": 401,
"Errors": [
"Authorization Required"
]
}
}
Once you get past this issue, you may want to double check your formfield names. The API lists the parameter name PhoneNumbers, not PhoneNumbers[].

How to get yahoo weather information using 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?

How to fix "faultString: [Virtuoso SOAP server] There is no such procedure" Webservice cfinvoke CF11?

I am getting the following error when invoking the web service with the <cfinvoke> tag using ColdFusion 11.
faultString: [Virtuoso SOAP server] There is no such procedure
I have passed all of the correct arguments to the method (respecting argument names case).
Calling code
<cfinvoke Webservice="absolute link" method="method name" wsversion="1" refreshwsdl="true">
<cfinvokeargument name="paramone" value="valone">
<cfinvokeargument name="paramtwo" value="valtwo">
</cfinvoke>
Thanks in advance for your help.
I've found the solution. For some reasons, the use of the cfinvoke tag does not work for consuming their web service.
I've used the cfhttp tag as an alternative and added an header parameter called "SOAPAction" and sets it to a specific value which I cannot share here. Also the action attribute needed to be set to "POST".
The final workaround code is the following (where wsRequest variable is the xml to be sent):
<cfhttp method="post" url="#application.WSDLEndpoint#">
<cfhttpparam type="header" name="content-type" value="text/xml">
<cfhttpparam type="header" name="SOAPAction" value="[specific absolute link]">
<cfhttpparam type="header" name="charset" value="utf-8">
<cfhttpparam type="xml" value="#wsRequest#" >
</cfhttp>

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

Syncing database with google fusion table

I am having troubles figuring out the google api.. I am trying to insert data into my fusion table via my coldfusion application..
<cfhttp url="https://www.google.com/accounts/ClientLogin" method="post" charset="utf-8">
<cfhttpparam type="formfield" name="accountType" value="GOOGLE"></cfhttpparam>
<cfhttpparam type="formfield" name="Email" value="MYUSERNAME"></cfhttpparam>
<cfhttpparam type="formfield" name="Passwd" value="MY PASSWORD"></cfhttpparam>
<cfhttpparam type="formfield" name="accountType" value="GOOGLE"></cfhttpparam>
<cfhttpparam type="formfield" name="service" value="fusiontables"></cfhttpparam>
</cfhttp>
this comes back with
SID=DQAAALoAAAC5eSJUrVB_WVchS1plunfW2YPUTadHAxoEbE0xMcOzQxeTloc2RWWBjoJi4jKm6NIiFbGbV_IQ3vuY9bl-Z0RS64OFAy5aUY-Do_nX8DpPhVkEyBzDScJidi73G7ZqWmkdykkIGCBrr7MLa-eBMrXZvLJP0D21xJTjxRWyeM4xuEMQGhEbnWwBL9RnEByr5Rsgzx7dl9n4tsYQOvaGV3ZcMlT0CooS2__orwC12UH7eKCk-REKzbX5Z-bbu4EdLps LSID=DQAAALwAAABV7lz-YRh02pR7IlWkKidScbYTQArBWnaAJpAlZQ9rgtgmdQCSBuIZQQ21QDXZLORwTAyDi-34Mjs8SKvI7ronBSuniDW2SGipYoUhZDEjxwR55DQc1AaI3JgGPMc69YGAVv-_EMwXlS7elWO6lDW-G4PTR6Aqa0DO3y7Iig-L7g2b7zMFq32JIvjUj5rofcykF27T8sOuhd0Z4XTvgO-18Kp2z8o6EK_5qjZcHPmih0GB6LeSElBo2wjah1TM2u0 Auth=DQAAALwAAADYQbciaOLab2Aw_QghTO8hR0DPDOjoWZVKeJ-ApGwoUz7OgcqVtSHMUvRHHZoKys5ygjhm2FiHSh1CvW1SicOvajwRZSstvghtsCQl-y7LeT8TMkeCj5ZIqy8A05wg1YjCz3F3eDz9TImtlvGij7IOdWJ3Ae4NE8WQdC0Js5Laccebhgjj7Lk9FkRgG9c3yRyGhu7LmsRbtLjfv5jwGoozDuCcx6b79bECoR8qABkT-e5HgF7sWjYbLfz667OCeA0
Now I am trying to insert into my table... I am passing the auth value from above.. I can not find anywhere in the google docs what the authentication fields should be.. any help would be greatly appreciated..
<cfhttp url="https://www.google.com/fusiontables/api/query" method="post" charset="utf-8">
<cfhttpparam type="formfield" name="sql" value="INSERT INTO 423555 (id, outcode,lat,lng) VALUES ('1','W14',1231232,-123123);"/>
<cfhttpparam type="header" name="Authorization" value="Auth"></cfhttpparam>
<cfhttpparam type="header" name="token" value="#listtoarray(cfhttp.FileContent,"=")[4]#"></cfhttpparam>
</cfhttp>
The AUTH should be the auth token you received in google's response.
From the docs you should make a header like:
Authorization: GoogleLogin auth=yourAuthToken
So, this would be
<cfhttpparam type="header" name="Authorization" value="GoogleLogin auth=#listtoarray(cfhttp.FileContent,"=")[4]#"></cfhttpparam>
This is assuming the #listtoarray(cfhttp.FileContent,"=")[4]# returns the value of the Auth property - I haven't counted it out to be sure.
I don't think, just glancing at the docs, the "token" header is needed.
But, #listtoarray(cfhttp.FileContent,"=")[4]# is a really fragile way of doing it. If Google were to reorder their response or change it, your code wouldn't work any more.
I would look to a more robust way of parsing the response. I would probably split the response on whitespace and turn it into a struct with the names as keys, then you could use something like
#response['auth']#