Jump to content


Photo

API add note issue

api

  • Please log in to reply
1 reply to this topic

#1 Benbison

Benbison

    Member

  • Members
  • PipPip
  • 17 posts

Posted 10 October 2017 - 08:52 PM

I have an API script that is adding a note to a contact, the script works on the demo version of Zurmo at http://demo.zurmo.com 

but I shows an error on our company site. 

 

Array ( [status] => FAILURE [data] => [message] => Sign in required. [errors] => )

 

Doing a check config on our company site there is only two fails.
Failed Optional Services
APC is not installed.
Minimum version required: 1.0.0
Database does not support LOAD LOCAL INFILE.
 
I don't know if there is still anyone active on this forum.
 
what could cause this error.


#2 Benbison

Benbison

    Member

  • Members
  • PipPip
  • 17 posts

Posted 10 October 2017 - 10:16 PM

I might add the URL is a https://

 

when doing the login request via ARC i get

 

{"status":"SUCCESS","data":{"sessionId":"tr876pjvj48ji8t5dmurrrpqf6","token":"2b63b3d9b3c51a863929e4b6d1a94c84"},"message":null,"errors":null}

 

Here is the complete code that I am using,

<?php
// development
ini_set('error_reporting', 'E_ALL');
// development
ini_set('display_errors', 'On');


$incoming_ph = $_GET['incoming_ph']; //CDR from phone system
$strip = preg_replace('/\s+/', '', $incoming_ph);
//format number with spaces
	if (substr($incoming_ph, 0, 2) === "04") {
		$incoming_ph = substr($strip,0,4)." ".substr($strip,4,3)." ".substr($strip,7);
	} else {
		$incoming_ph = substr($strip,0,2)." ".substr($strip,2,4)." ".substr($strip,6);
	};
		
$call_date = $_GET['call_date'];
$timestamp = strtotime($call_date);
$call_date = date("Y-m-d H:i:s", $timestamp);
$call_time = date("d M Y H:i", $timestamp);

$contact_id = $_GET['custid'];
$customer = $_GET['cidn'];

$description = 'Call received on ' . $call_time . ' from ' . $incoming_ph . ' - ' . $customer;

// ********************************************************************************
class ApiRestHelper
{
    function createApiCall($url, $method, $headers, $data = array())
    {
        if ($method == 'PUT')
        {
            $headers[] = 'X-HTTP-Method-Override: PUT';
        }

        $handle = curl_init();
        curl_setopt($handle, CURLOPT_URL, $url);
        curl_setopt($handle, CURLOPT_HTTPHEADER, $headers);
        curl_setopt($handle, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($handle, CURLOPT_SSL_VERIFYHOST, false);
        curl_setopt($handle, CURLOPT_SSL_VERIFYPEER, false);
		//curl_setopt($handle, CURLOPT_PROXY, false);

        switch($method)
        {
            case 'GET':
                break;
            case 'POST':
                curl_setopt($handle, CURLOPT_POST, true);
                curl_setopt($handle, CURLOPT_POSTFIELDS, http_build_query($data,'','&'));
                break;
            case 'PUT':
                curl_setopt($handle, CURLOPT_CUSTOMREQUEST, 'PUT');
                curl_setopt($handle, CURLOPT_POSTFIELDS, http_build_query($data,'','&'));
                break;
            case 'DELETE':
                curl_setopt($handle, CURLOPT_CUSTOMREQUEST, 'DELETE');
                break;
        }
        $response = curl_exec($handle);
        return $response;
    }
}
// ********************************************************************************
function login($username, $password){
    $headers = array(
        'Accept: application/json',
        'ZURMO-AUTH-USERNAME: ' . $username,
        'ZURMO-AUTH-PASSWORD: ' . $password,
        'ZURMO-API-REQUEST-TYPE: REST',
    );
    $response = ApiRestHelper::createApiCall('https://www.crm.zurmo.url/crm/app/index.php/zurmo/api/login', 'POST', $headers);
    $response = json_decode($response, true);
    if ($response['status'] == 'SUCCESS')
    {
        return $response['data'];
    }
    else
    {
        return false;
    }
}

// ********************************************************************************
$data = login('super', 'super'); # admin is the admin user, not found with api user

$headers = array(
    'Accept: application/json',
    'ZURMO-SESSION-ID: ' . $data['sessionId'],
    'ZURMO-TOKEN: ' . $data['token'],
    'ZURMO-API-REQUEST-TYPE: REST',
);

//add our note
$data = Array(
    'description' => $description,
    'occurredOnDateTime' => $call_date,
    'modelRelations' => array(
    // Attach note to contact
        'activityItems' => array(
            array(
                'action' => 'add', 
                'modelId' => $contact_id, // Replace this with contact Id (or account/opportunity id to which you want to attach note)
                'modelClassName' => 'Contact' // Instead 'Contact' you can attach note to 'Account', 'Opportunity'
            ),
        ),
    ),
);

$response = ApiRestHelper::createApiCall('https://www.crm.zurmo.url/crm/app/index.php/notes/note/api/create', 'POST', $headers, array('data' => $data));
$response = json_decode($response, true);
print_r($response);

if ($response['status'] == 'SUCCESS')
{
    return $response['data'];
    //Do something with note data
	echo "Success";
}
else
{
    // Error
    return $response['errors'];
    // Do something with errors, show them to user
	echo "Error";
}

?>






Also tagged with one or more of these keywords: api

1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users