Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion

osTicket v1.10 (stable) and Maintenance Release v1.9.15 are now available! Go get it now

Cron Job not working - 401 Unauthorized Authorization failed

For two days now i am struggling to get cron job to work to fetch mails.

auto-cron works perfect but then mails are fetched only when staff has logged into osTicket.

here is my cron.php

#!/usr/bin/php -q
<?php
/*********************************************************************
rcron.php

PHP script used for remote cron calls.

Peter Rotich <peter@osticket.com>
Copyright (c) 2006-2013 osTicket
http://www.osticket.com

Released under the GNU General Public License WITHOUT ANY WARRANTY.
See LICENSE.TXT for details.

vim: expandtab sw=4 ts=4 sts=4:
**********************************************************************/

# Configuration: Enter the url and key. That is it.
# url => URL to api/task/cron e.g http://yourdomain.com/support/api/task/cron
# key => API's Key (see admin panel on how to generate a key)
#

$config = array(
'url'=>'http://mydomain.com/support/api/task/cron',
'key'=>'My-Api-Key'
);

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

#set timeout
set_time_limit(30);

#curl post
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $config['url']);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, '');
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);
?>


and here is what i have in my cron tab


wget --post-data '' --header='X-API-Key: <My-Api-Key>' http://MyDomain.com/support/api/tasks/cron



I am getting the following error

--2013-09-04 04:14:01-- http://MyDomain.com/support/api/tasks/cron
Resolving MyDomain.com... xxx.xxx.xx.xxx Connecting to MyDomain.com|xxx.xxx.xx.xxx|:80... connected.
HTTP request sent, awaiting response... 401 Unauthorized Authorization failed.

anyone to help please? what am i going wrong?

Comments

  • Is the IP address of the API key assigned to the server making the HTTP POST request?
  • Hello Jared,

    thank you for your readiness to support.

    i upgraded to 1.7.1 and played with the command again, not sure what exactly was the issue but is perfectly working now. mails are being pulled.

    thank you
Sign In or Register to comment.