For a while now, Apptivo has allowed customers to integrate their website, or other outside applications using our API. We’re happy to announce a new REST API, which is not only more powerful, but also simpler to implement. While the existing SOAP API allowed for many useful functions, such as placing a form on your website that could generate a lead in your CRM, it had limitations. Customers have been requesting more advanced capabilities, such as being able to not only write data into the system, but pull data out from the system to do things such as customized user portals, special reporting tools, or integrations with other applications.

Using the REST API

While the new API is still under active development, it’s online and available for use. Today we ran our first presentation on using the REST API, and demonstrated how to create a simple web form, that generates a support request inside of Apptivo. Using the REST API the form is able to search for a customer within the CRM, determine if exists and create one if needed, then generate a support ticket linked up with that customer. If you weren’t able to attend the webinar, we’ve recorded everything here for you:

Cases API Workshop – Webinar Recording

Please note, this video is only recommended for programmers or those with moderate technical skills.

Code Example

Here is the example code that was produced during the demonstration in the video above.

<?php

if(isset($_POST['case_subject']))
{
/* START Config Settings */
$api_key = 'cb83cbc3-7efc-4457-9beb-a72871187cea';
$access_key = 'grxPZSZKvEtB-eIArCNDnLNXl-0910a13e-651b-4e63-8175-86cb8f243b2a';
$user_email_address = 'admin@glocialtech.com';
$api_environment = 'https://api.apptivo.com/app/dao/';
/* END Config Settings */

        //Support case info collected from the web form
                $case_subject = $_POST['case_subject'];
                $case_description = $_POST['case_description'];
                $customer_email_address = $_POST['customer_email'];
                $contact_email_address = $_POST['customer_email'];
                
        //Initialize cUrl
                $ch = curl_init();
                curl_setopt($ch, CURLOPT_HEADER, 0);
                curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
                curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,   0);
                curl_setopt($ch, CURLOPT_SSLVERSION, 3);
                curl_setopt($ch, CURLOPT_SSL_VERIFYHOST,   0);
                
        // Check if a customer already exists
        $api_get_customer_url = $api_environment.'customer?a=getAllcustomersByEmailId&apiKey='.$api_key.'&accessKey='.$access_key.'&assigneeId=30389&assignedType=employee&emailId='.$customer_email_address.'&userName='.$user_email_address;
        
        curl_setopt($ch, CURLOPT_URL, $api_get_customer_url);

        $dat_result = curl_exec($ch);
        
        $api_response = json_decode($dat_result);
        
        if(!$api_response->numResults > 0)
        {
                //No customer exists, return an error
                $api_create_customer_url = $api_environment.'customer?a=createNewCustomer&objectId=3&customerData={"customerName":"'.$customer_email_address.'","customerEmail":"'.$customer_email_address.'","customerNumber":"Auto+generated+number","phoneNumber":"","customerCategoryId":"","mobileNumber":"","":"","employeeId":"23463","assigneeType":"employee","faxNumber":"","skypeName":"","description":""}&addressData1:["-1","70","7B/71,23,Tamizhan+Street","New+Ramnad+Road","Madurai","Madurai","Tamil+Nadu","625009","70"]&addressData2:["-1","70","7B/71,24,Meenakshi+Street","New+Ramnad+Road","Madurai","Madurai","Tamil+Nadu","625009","70"]&apiKey='.$api_key.'&accessKey='.$access_key;
                curl_setopt($ch, CURLOPT_URL, $api_create_customer_url);

                $dat_result = curl_exec($ch);
                
                $api_response = json_decode($dat_result);
        }
                
        //A customer was found, create the case and attach to customer
        $case_subject = urlencode($case_subject);
        $case_description = urlencode($case_description);

        $api_request_url = $api_environment.'cases?a=createCase&caseDetails={"caseNumber":"Auto+generated+number","subject":"'.$case_subject.'","description":"'.$case_description.'","customerEmailId":"'.$customer_email_address.'","resType":"mobile"}&apiKey='.$api_key.'&accessKey='.$access_key.'&userName='.$user_email_address;

        curl_setopt($ch, CURLOPT_URL, $api_request_url);
        $api_response = json_decode(curl_exec($ch));

        if($api_response && $api_response->responseCode == '0')
        {
                $form_message = 'Your case was successfully submitted.';
        }else{
                $form_message = 'Sorry, there was an error submitting your information.  Please contact us directly.';
        }
                
}else{
        $form_message = 'Please enter your case details below';
}

/* START Web Form */
        echo('
                <html>
                        <body>
                        '.$form_message.'
                        <form action="'.$_SERVER['PHP_SELF'].'" method="post" name="form">
                                <label>Subject: </label>
                                <input type="text" name="case_subject" />
                                <label>Company Email: </label>
                                <input type="text" name="customer_email" />
                                <label>Description: </label>
                                <textarea name="case_description"></textarea>
                                <input type="submit" value="Submit" />
                        </form>

                        </body>
                </html>
        ');
/* END Web Form */

?>

Latest Blogs

No Image in Post

Apptivo's Integration with Amazon SES for Outgoing Email Server

Amazon Simple Email Service (SES) is an email platform that provides an easy, cost-effective way to send and receive email using your email addresses and domains. Apptivo has migrated its email service to Amazon SES (Simple Email Service) to enhance the performance and reliability of our email services

Read more 
No Image in Post

EXPLORING MULTI CHANNEL CUSTOMER SUPPORT SOFTWARE

1.What is customer service software? 2

Read more 
No Image in Post

Maximize your business performance with seamless CRM Integration

1.What is CRM Integration? 2

Read more