EZ Text API & ColdFusion - 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[].

Related

Windows Push Notification Services Token request via ColdFusion

I am trying to get the "access token" from WNS via a ColdFusion request but I get a "Bad Request" response. I believe I have everything set up correctly following the instructions here. My devices are registering the URI's to my backend.
Here is a simple code snippet;
(I've hidden the secret key of course)
<cfhttp url="https://login.live.com/accesstoken.srf" method="post" result="httpResp">
<cfhttpparam type="header" name="Content-Type" value="application/x-www-form-urlencoded" />
<cfhttpparam type="URL" name="grant_type" value="client_credentials" />
<cfhttpparam type="URL" name="client_id" value="ms%2Dapp%3A%2F%2Fs%2D1%2D15%2D2%2D1197233413%2D3602308102%2D1084427847%2D2188608249%2D1036687727%2D3580410356%2D2392468796" />
<cfhttpparam type="URL" name="client_secret" value="************************" />
<cfhttpparam type="URL" name="scope" value="notify.windows.com" />
I am also getting failed response when I test the URL directly via the browser. Appreciate your help.
Thank you,
Ian.
I think your cfhttpparam fields now set to "URL" should actually be set to "FORMFIELD" based on the example on MSDN.
<cfhttpparam type="FORMFIELD" name="grant_type" value="client_credentials" />
<cfhttpparam type="FORMFIELD" name="client_id" value="..." />
<cfhttpparam type="FORMFIELD" name="client_secret" value="************************" />
<cfhttpparam type="FORMFIELD" name="scope" value="notify.windows.com" />
The example appears to put thes in the content area (showing a raw post) - so these are form fields of a post, not URL fields right?

Google OAuth Code Contains Hashtag

In my attempts to get the necessary code so I can generate my refresh token, I ran this URL:
https://accounts.google.com/o/oauth2/auth?scope=https://www.googleapis.com/auth/drive.file&redirect_uri=--mywebsite--&response_type=code&client_id=--myclientid--
And my received code contains a trailing hash tag, which throws an (expected) error when I try to execute:
<cfhttp url="https://accounts.google.com/o/oauth2/token" method="post">
<cfhttpparam name="code" value="4/UXF5F5TlIuFsXrav-DvIrebMR8NST9WK-EPmThmx7l0#" type="formfield"> <!-- Sample code value -->
<cfhttpparam name="client_id" value="--myclientid--" type="formfield">
<cfhttpparam name="client_secret" value="[client secret]" type="formfield">
<cfhttpparam name="redirect_uri" value="--mywebsite--">
<cfhttpparam name="grant_type" value="authorization_code" type="formfield">
</cfhttp>
ColdFusion was looking at the following text:formfieldThe CFML compiler was processing:An expression that began on line 2, column 86.The expression might be missing an ending #, for example, #expr instead of #expr#.The tag attribute value, on line 2, column 34.A cfhttpparam tag beginning on line 2, column 10.
I tried adding a second hashtag to make it literal but I receive { "error" : "invalid_grant", "error_description" : "Invalid code." } response.
Am I missing something painfully obvious here? The tutorial I was following is at http://www.brandiandjohn.com/post.cfm/oauth-2-google-and-cfml-without-cfoauth
In order to continue with the existing code, you need to escape #. You can do that, by adding an extra # at the end. For eg
<!---
<cfset value="4/UXF5F5TlIuFsXrav-DvIrebMR8NST9WK-EPmThmx7l0#">
<cfoutput>#value#</cfoutput>
Error
--->
<cfset value="4/UXF5F5TlIuFsXrav-DvIrebMR8NST9WK-EPmThmx7l0##">
<cfoutput>#value#</cfoutput>
Output: 4/UXF5F5TlIuFsXrav-DvIrebMR8NST9WK-EPmThmx7l0#
So, you can try the below code:-
<cfhttp url="https://accounts.google.com/o/oauth2/token" method="post">
<cfhttpparam name="code" value="4/UXF5F5TlIuFsXrav-DvIrebMR8NST9WK-EPmThmx7l0##" type="formfield"> <!-- Sample code value -->
<cfhttpparam name="client_id" value="--myclientid--" type="formfield">
<cfhttpparam name="client_secret" value="[client secret]" type="formfield">
<cfhttpparam name="redirect_uri" value="--mywebsite--">
<cfhttpparam name="grant_type" value="authorization_code" type="formfield">
</cfhttp>
The hashtag error was a red herring. I got around this by making the call to get the code and then the access token as a single action. By passing in url.code I received the necessary credentials.
<cfhttp url="https://accounts.google.com/o/oauth2/token" method="post">
<cfhttpparam name="code" value="#url.code#" type="formfield">
<cfhttpparam name="client_id" value="--myclientid--" type="formfield">
<cfhttpparam name="client_secret" value="[client secret]" type="formfield">
<cfhttpparam name="redirect_uri" value="--mywebsite--">
<cfhttpparam name="grant_type" value="authorization_code" type="formfield">
</cfhttp>
<cfdump var="#foo.filecontent#">
Manually pasting the code into the cfhttpparam tag, even without the hashtag, would throw a 400 error. This way, it does not.
The user agent that sent you the code should have stripped the "#" character, see: Google OAuth service redirects to URL with a # sign at the end. Apparently it did not (and as such that user agent is broken) but you can strip it manually in your code before sending if off.

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

Google Calendar OAuth access_token doesn't work for POST functions

I am having issues calling Calendar:Insert via Google's API
https://www.googleapis.com/calendar/v3/calendars
I don't believe there are authorization/permission issues, the access_token is acquired via a refresh_token with the following scope: "https://www.googleapis.com/auth/calendar"
When I use a valid access_token to perform GET there are no issues, but this is a POST and I consistently get this response:
{"error":
{ "errors":
[{ "domain": "global",
"reason": "authError",
"message": "Invalid Credentials",
"locationType": "header",
"location": "Authorization"
}],
"code": 401,
"message": "Invalid Credentials"
}
}
Here is the Railo code I'm running, I've stripped it of all pretense and nuance:
<cfhttp url="https://www.googleapis.com/calendar/v3/calendars" charset="utf-8" method="post">
<cfhttpparam type="header" name="Authorization" value="bearer #arguments.access_token#" />
<cfhttpparam type="formfield" name="summary" value='hello world' />
</cfhttp>
Here is an example of a get that works just fine:
<cfhttp url="https://www.googleapis.com/calendar/v3/calendars/#arguments.calendarID#/events?access_token=#arguments.access_token#" charset="utf-8" method="get" />
So far I've attempted placing the access_token in a variety of ways. As a query parameter, as a json struct in the cfhttpparam type="body" with no luck
This stackoverflow question indicates that the Google Calendar API documentation neglects to mention a required parameter "minAccessRole". I've fiddled with that too to no avail.
Some time removed from the problem often brings clarity.
With trial and error I was able to get some error code feedback from the API. At some point revealed to me the Content-Type I was sending was "octet-stream".
I added the following line, to specify the Content-Type. I chose "application/json" since the https://developers.google.com/oauthplayground/ had that as the default content-type for the operation: calendar insert.
<cfhttpparam type="header" name="Content-Type" value="application/json" />
Then it occurred to me that I was attempting to send form fields to the API and not JSON.
The final working code for callooks something like this:
<cfhttp url="https://www.googleapis.com/calendar/v3/calendars" charset="utf-8" method="post">
<cfhttpparam type="header" name="Content-Type" value="application/json" />
<cfhttpparam type="header" name="Authorization" value="bearer #arguments.access_token#" />
<cfhttpparam type="body" value='{"summary":"newCalendar"}' />
</cfhttp>

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']#