Twilio Rest API Filtering using Coldfusion11 - coldfusion

I am trying to use the following code to access the Twilio Rest API to retrieve a list of incoming calls to my twilio number for a given date range.
https://www.twilio.com/docs/api/rest/call
<cfhttp url="https://api.twilio.com/2010-04-01/Accounts/xxxxxxxxxxxxxxxxx/Calls" method="get" resolveurl="no" username="xxxxxx" password="xxxxx1">
<cfhttpparam name="To" type="url" value="myphone">
<cfhttpparam name="StartTime>=" type="url" value="2015-05-01">
<cfhttpparam name="StartTime<" type="url" value="2015-06-01">
</cfhttp>
When I try to connect with the above, I get a "Connection" error in coldfusion. It doesn't like the ">". I have also tried to put the StartTime> into a variable perform urlencodedformat() on it, but it didn't give the desired result.
When I query an individual day it works fine.
<cfhttp url="https://api.twilio.com/2010-04-01/Accounts/xxxxxxxxxxxxxxxxx/Calls" method="get" resolveurl="no" username="xxxxxx" password="xxxxx1">
<cfhttpparam name="To" type="url" value="myphone">
<cfhttpparam name="StartTime" type="url" value="2015-05-01">
</cfhttp>
Based off Twilio code examples (I was referencing PHP examples) it appears the the variable name can be StartTime>, StartTime>=, StartTime<, StartTime<=.

In you code, you are calling the "StartTime"
<cfhttp url="https://api.twilio.com/2010-04-01/Accounts/xxxxxxxxxxxxxxxxx/Calls" method="get" resolveurl="no" username="xxxxxx" password="xxxxx1">
<cfhttpparam name="To" type="url" value="myphone">
<cfhttpparam name="StartTime>=" type="url" value="2015-05-01">
<cfhttpparam name="StartTime<" type="url" value="2015-06-01">
</cfhttp>
As per https://www.twilio.com/docs/api/rest/call, you should use StartTime & EndTime. I am able to dump the httpResponse with the below code:-
<cfhttp url="https://api.twilio.com/2010-04-01/Accounts/xxxxxxxxxxxxxxxxx/Calls" method="get" resolveurl="no" username="xxxxxx" password="xxxxx1" result="httpResponse">
<cfhttpparam name="To" type="url" value="myphone">
<cfhttpparam name="StartTime" type="url" value="2015-05-01">
<cfhttpparam name="EndTime" type="url" value="2015-06-01">
</cfhttp>
<cfdump var="#httpResponse#" label="httpResponse">
Also, https://www.twilio.com requires two SSL certificates. You need to import these to the keystore.

Related

cfhttp to the stats.ezhostingserver website not working

I have the following Updated code where I am trying to connect to the website using the username/password and siteid combination, i am passing all values using get method and trying to fetch cookie to authenticate and go ahead but somehow i am again getting redirected to the login screen
My Code
<cfhttp method="get" url="https://stats.ezhostingserver.com/Login.aspx" resolveurl="true" redirect="false">
<cfhttpparam type="URL" name="ctl00$MPH$txtUserName" value="********">
<cfhttpparam type="URL" name="ctl00$MPH$txtPassword" value="********">
<cfhttpparam type="URL" name="ctl00$MPH$txtSiteId" value="*****">
<cfhttpparam type="Header" name="Accept-Encoding" value="deflate;q=0">
<cfhttpparam type="Header" name="TE" value="deflate;q=0">
</cfhttp>
<cfset stm_cookies = cfhttp.responseHeader['Set-Cookie'] />
<cfset stm_temp = REReplace(stm_cookies, ";.*", "")>
<cfset stm_cookieName = listfirst(stm_temp,'=')>
<cfset stm_cookievalue = listlast(stm_temp,'=')>
<cfhttp method="get" url="https://stats.ezhostingserver.com/default.aspx" charset="utf-8" result="results" redirect="no">
<cfhttpparam type="cookie" name="#stm_cookieName#" value="#stm_cookievalue#">
</cfhttp>
<cfoutput>#results.filecontent#</cfoutput>
But it is saying me object moved error

How do I create a new folder in Google Drive using the API via ColdFusion?

I've been trying to follow the documentation at https://developers.google.com/drive/v2/reference/files/insert and https://developers.google.com/drive/web/folder. However, I'm not clear on exactly what information I need to be passing during the http call. When I run the following code it simply creates a file that Drive says it doesn't know how to open:
<cfhttp method="post" url="https://www.googleapis.com/upload/drive/v2/files">
<cfhttpparam type="header" name="Content-Type" value="application/json" />
<cfhttpparam type="URL" name="key" value="#myKey#">
<cfhttpparam type="URL" name="access_token" value="#myAccessToken#">
<cfhttpparam type="URL" name="corpus" value="DEFAULT">
<cfhttpparam type="URL" name="uploadType" value="multipart">
<cfhttpparam type="URL" name="Content-Type" value="application/json; charset=UTF-8 {""title"": ""Test 001"", ""parents"": [{""id"":""#validParentID#""}]}">
<cfhttpparam type="URL" name="Content-Type" value="application/vnd.google-apps.folder">
</cfhttp>
This code was derived from my call that successfully creates an empty file (although I've not yet gotten the title to work).
UPDATE
I updated the code per Jedihomer Townend's suggestion:
<cfhttp method="post" url="https://www.googleapis.com/upload/drive/v2/files">
<cfhttpparam type="header" name="Content-Type" value="application/json" />
<cfhttpparam type="URL" name="key" value="#myKey#">
<cfhttpparam type="URL" name="access_token" value="#myAccessToken#">
<cfhttpparam type="URL" name="corpus" value="DEFAULT">
<cfhttpparam type="URL" name="uploadType" value="multipart">
<cfhttpparam type="URL" name="Content-Type" value="application/json; charset=UTF-8 {""mimeType"": ""application/vnd.google-apps.folder"" ""title"": ""Test 001"", ""parents"": [{""id"":""#validParentID#""}]}">
</cfhttp>
This had the same result as my original code.
BOUNTY
I'm starting a bounty on this now. In addition to resolving this particular problem, I'd also appreciate insights on how to apply Google's documentation to direct http calls. Despite REST being a technology designed around http requests, Google's docs (pun intended) seem to cover only an OOP approach to using it.

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?

Credly API get SDK builder temp_token using ColdFusion

I am trying to get temp_token for credly API's badge builder SDK. I am using ColdFusion as server side language. My code look like,
<cfhttp method=”post” result=”objGet”
url=”https://developers.credly.com/badge-builder/code” >
<cfhttpparam type=”formfield” name=”access_token” value=”my_access_token” />
</cfhttp>
As well as, I have tried
<cfhttp method=”post” result=”objGet”
url=”https://developers.credly.com/badge-builder/code” >
<cfhttpparam type="header" name="Authorization" value="access_token=(my_access_token)” />
</cfhttp>
<cfhttp method=”post” result=”objGet”
url=”https://developers.credly.com/badge-builder/code” >
<cfhttpparam type="header" name="access_token" value="(my_access_token)” />
</cfhttp>
<cfhttp method=”post” result=”objGet”
url=”https://developers.credly.com/badge-builder/code” >
<cfhttpparam type="header" name="access_token" value="my_access_token” />
</cfhttp>
All of them are giving me response as,
{
“success”:false,
”error”:”You must pass an access_token to retrieve a badge builder embed code”
}
Am I missing something?
Update:
I have checked their official wordpress plugin, they are using type as body. I have tried that too, but gave the same result.

ColdFusion CFHTTP GET strips cookie

I'm running into issues trying to pass a cookie in my CFHTTP GET Statement.
Has anyone else experienced this? Pointers would be appreciated. BTW - I am using the x-http-method-override, because I saw this on a few other sites that were discussing this topic.
<cfhttp url="#this.apiServer#/api/v#this.version#/user.json"
method="POST" result="jorn">
<cfhttpparam type="COOKIE" name="ms_user" value="#arguments.patAppSession#" />
<cfhttpparam type="header" name="Content-Type" value="application/json" />
<cfhttpparam type="header" name="x-http-method-override" value="GET" />
<cfhttpparam type="body" value='#variables.dataFields#' />
</cfhttp>
<cfdump var = "#jorn#">