Twilio Rest API Filtering using Coldfusion11

410 views Asked by At

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<=.

1

There are 1 answers

1
Anit Kumar On

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.