Using the REST Interface

The Engaged Action Representational State Transfer (REST) interface allows you to construct HTTP request to query campaign data. Engaged Action allows REST clients to authenticate themselves with a user name and password using Basic Authentication.

campaigns method

Purpose

You can use the campaigns method to fetch a list of all user’s campaigns. The method returns JSON by default. Use the /format/<format>/

to get other formats. Supported formats are xml, rawxml, json, jsonp, serialize, php, html, and csv.

Request URL

XML Format:

http://login.grassrootsoncall.com/index.php/api/campaigns/format/xml/

JSON Format:

http://login.grassrootsoncall.com/index.php/api/campaigns/format/json/

campaignstats method

Purpose

You can use the campaignstats method to fetch the status and results of a user’s campaign. The method requires a campaign id, uses /id/<id>/.

Specific Campaign:

http://login.grassrootsoncall.com/index.php/api/campaignstats/id/2e48d145-b65d-8fce-dcca-554c1d95c3e4/format/xml/

EXAMPLES

PHP Example

<!DOCTYPE html>
<html>
  <head>
    <title>PHP GROC API Example</title>
  </head>
  <body>
<?php
$campaigns_request_url = "http://api.grassrootsoncall.com/index.php/api/campaigns";
$campaign_request_base_url = "http://api.grassrootsoncall.com/index.php/api/campaignstats/id/";
$username = "pgriffin";
$password = "groc4762";

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$campaigns_request_url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($ch, CURLOPT_USERPWD, "$username:$password");
$result = curl_exec($ch);
curl_close($ch);  
echo($result);

echo("<br><br>");

$campaigns = json_decode($result, true);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$campaign_request_base_url.$campaigns["campaigns"][1]["id"]);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($ch, CURLOPT_USERPWD, "$username:$password");
$result = curl_exec($ch);
curl_close($ch);  
echo($result);
?>
  </body>
</html>

jQueryExample

<!DOCTYPE html>
<html>
    <head>
        <title>jQuery GROC API Example</title>
        <script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js" type="text/javascript"></script>
        <script>
            var campaigns_request_url = "http://api.grassrootsoncall.com/index.php/api/campaigns/";
            var campaign_request_base_url = "http://api.grassrootsoncall.com/index.php/api/campaignstats/id/";
            var username = "pgriffin";
            var password = "groc4762";

            $.ajax
            ({
              type: "GET",
              url: campaigns_request_url+"format/jsonp/",
              dataType: 'jsonp',
              async: false,
              headers: {
                "Authorization": "Basic " + btoa(username+":"+password)
              },
              success: function (response){
                campaigns = response;
                $("#campaigns").html(JSON.stringify(campaigns));
              },
              error: function(xhtr, eS, eT){
                  alert(eS+":"+eT);
              }
            });


            $.ajax
            ({
              type: "GET",
              url: campaign_request_base_url+"e2ae1051-4493-de09-49f5-554aa1ab7e82"+"/format/jsonp/",
              dataType: 'jsonp',
              async: false,
              headers: {
                "Authorization": "Basic " + btoa(username+":"+password)
              },
              success: function (response){
                campaign_stats = response;
                $("#stats").html(JSON.stringify(campaign_stats));
              }
            });
        </script>
    </head>
    <body>
        <div id="campaigns"></div>
        <p></p>
        <div id="stats"></div>
    </body>
</html>

JSON campaigns

{
    "campaigns": [
        {
            "id": "2e48d145-b65d-8fce-dcca-554c1d95c3e4",
            "name": "Water Rights Issues",
            "description": "We are writing a letter of opposition to stop the passing of AB 1. Ab 1 will take water away from farmers and give it to urban development.  ",
            "tracking_number": "AB 1",
            "start_datetime": "2015-09-24 01:00:00",
            "end_datetime": "2015-09-25 01:00:00",
            "timezone_adjust": "0",
            "call_hours_start": "8",
            "call_hours_end": "17",
            "cc_email": "engagedaction@outlook.com",
            "caller_id": "(916)308-5165",
            "mf_voice": "man",
            "district_matching": "0",
            "campaign_complete": "1"
        },
        {
            "id": "e2ae1051-4493-de09-49f5-554aa1ab7e82",
            "name": "Rain Water Collection",
            "description": "This bill would require rain water to be collected at the property owners expense and returned to the local water agency.",
            "tracking_number": "SB 14",
            "start_datetime": "0000-00-00 00:00:00",
            "end_datetime": "0000-00-00 00:00:00",
            "timezone_adjust": "0",
            "call_hours_start": "8",
            "call_hours_end": "20",
            "cc_email": "engagedaction@outlook.com",
            "caller_id": "(916)308-5165",
            "mf_voice": "man",
            "district_matching": "0",
            "campaign_complete": "0"
        }
    ]
}

JSON campaignstats

{  
   "campaign":{  
      "id":"c1848a39-a1d8-c56c-bb3f-512924873a46",
      "stats":{  
         "calls_made":2,
         "faxes_sent":2,
         "faxes_queued":0,
         "call_minutes":2,
         "minute_cost":0.03,
         "fax_pages_sent":0,
         "page_cost":0.07,
         "number_chose_yes":2,
         "number_requested_info":0,
         "number_chose_no":0,
         "number_no_answer":0,
         "call_logs":[  
            {  
               "first_name":"David",
               "last_name":"Castle",
               "call_attempts":"1",
               "call_minutes":"1",
               "answer":"Send Letter",
               "faxes_sent":"Yes"
            },
            {  
               "first_name":"Wes",
               "last_name":"Krasko",
               "call_attempts":"1",
               "call_minutes":"1",
               "answer":"Send Letter",
               "faxes_sent":"Yes"
            }
         ],
         "fax_logs":[  
            {  
               "from_first_name":"David",
               "from_last_name":"Castle",
               "to_first_name":"Wes",
               "to_last_name":"Krasko",
               "faxed_result":"Sending faxes...",
               "date_sent":"",
               "pages_sent":"0"
            },
            {  
               "from_first_name":"Wes",
               "from_last_name":"Krasko",
               "to_first_name":"Wes",
               "to_last_name":"Krasko",
               "faxed_result":"Sending faxes...",
               "date_sent":"",
               "pages_sent":"0"
            }
         ]
      }
   }
}