Tag Archives: API

SuiteCRM / SugarCRM Rest API 500 Error get_entry_list

I stumbled upon this problem today when trying out the SuiteCRM Rest API.
When searching for an account by it’s name I was using a search like this:

"name = 'Andrew'"

The API was returning a 500 error.
I dug into the suitecrm.log and found this:

where (name = 'Andrew') AND accounts.deleted=0: MySQL error 1052: Column 'name' in where clause is ambiguous

It seems that because of the joins, it can’t work out which ‘name’ we are talking about. Lets add the table name in and tada it works:

"accounts.name = 'Andrew'"

Xero API pyXero and Anaconda Python

Personal TL;DR notes on getting this to work, not a tutorial.

Download Install Anaconda
– At the time of writing it didn’t create Windows Shortcuts, fix this with openning cmd as admin

‘c:\Anaconda2\scripts\conda.exe install menuinst’

Agree to Updates

‘c:\Anaconda2\scripts\conda.exe install -f console_shortcut ipython ipython-notebook ipython-qtconsole launcher spyder’

Agree to updates.

Now there should be shortcuts in:

C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Anaconda2 (64-bit)

Now onto Xero

  • git clone https://github.com/freakboy3742/pyxero.git
  • Open up Anaconda Prompt (Anaconda2x64)
  • cd into folder with git of pyxero
  • use command: python setup.py install
  • pip uninstall oauthlib
  • pip install oauthlib==0.7.2

The last two commands fix the error: ImportError: No module named jwt.algorithms

Again these are personal notes, not a full blown tutorial.

 

Creating a ticket via the osTicket API using PHP & Crontab (cron job)

I feel that there is very little documentation and examples around of how to do this, and it bugged me for more than 10 minutes, so I thought I’d share my findings.

The documentation can currently be found here: https://github.com/osTicket/osTicket-1.7/blob/develop/setup/doc/api.md and here: https://github.com/osTicket/osTicket-1.7/blob/develop/setup/doc/api/tickets.md

A sample script can be found here: https://github.com/osTicket/osTicket-1.7/blob/develop/setup/scripts/rcron.php (which is what I based the following example off).

But I like to be somewhat lazy and copy and paste a script, test to see it works and then go about tweaking it.

#!/usr/bin/php -q
 URL to api/tickets.json e.g http://yourdomain.com/support/api/tickets.json
# key => API's Key (see admin panel on how to generate a key)
#

$config = array(
'url'=>'http://yourdomain.com/support/api/tickets.json',
'key'=>'[long api key goes here]'
);

#pre-checks
function_exists('curl_version') or die('CURL support required');

#set timeout
set_time_limit(30);

#Sample data for the ticket
# See https://github.com/osTicket/osTicket-1.7/blob/develop/setup/doc/api/tickets.md for full list of variables and options that you can pass.
$data = array("alert" => "true",
       "autorespond" => "true",
       "source" => "API",
       "name" => "Angry User",
       "email" => "[email protected]",
       "subject" => "Testing API 3",
       "message" => "MESSAGE HERE"
);
#Convert the above array into json to POST to the API with curl below.
$data_string = json_encode($data);

#curl post
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $config['url']);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
curl_setopt($ch, CURLOPT_USERAGENT, 'osTicket API Client v1.7');
curl_setopt($ch, CURLOPT_HEADER, TRUE);
curl_setopt($ch, CURLOPT_HTTPHEADER, array( 'Expect:', 'X-API-Key: '.$config['key']));
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, FALSE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
$result=curl_exec($ch);
curl_close($ch);

if(preg_match('/HTTP\/.* ([0-9]+) .*/', $result, $status) && $status[1] == 200)
exit(0);

echo $result;
exit(1);
?>

 

Then follow your hosts instructions for adding a Cron Job.
Mine looks something like this:

php /home/abennett/public_html/sample-api.php