Jump to content

Open support ticket through API


behnam

Recommended Posts

Hello

 

i'm trying to open support ticket through API using this code :

 

 


<?php
/**
* WHMCS Sample API Call
*
* @package    WHMCS
* @author     WHMCS Limited <development@whmcs.com>
* @copyright  Copyright (c) WHMCS Limited 2005-2016
* @license    http://www.whmcs.com/license/ WHMCS Eula
* @version    $Id$
* @link       http://www.whmcs.com/
*/

// The fully qualified URL to your WHMCS installation root directory
$whmcsUrl = "https://-----/";

// Admin username and password
$username = "*****;
$password = "*****";

// Set post values

$postdata = array(
   'username' => $username,
   'password' => md5($password),
   'action' => 'OpenTicket',
   'clientid' => '1',
   'deptid' => '4',
   'subject' => 'Sample API Ticket',
   'message' => 'This is a ticket opened via the API',
   'priority' => 'High',
   'customfields' => base64_encode(serialize(array('8' => 'custom field value')));
   'responsetype' => 'json',
);

// Call the API
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $whmcsUrl . 'includes/api.php');
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
// curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($postfields));
$response = curl_exec($ch);
if (curl_error($ch)) {
   die('Unable to connect: ' . curl_errno($ch) . ' - ' . curl_error($ch));
}
curl_close($ch);

// Attempt to decode response as json
$jsonData = json_decode($response, true);

// Dump array structure for inspection
var_dump($jsonData);

?>


 

 

 

This is the output : NULL

why ? what is wrong ?

 

 

Thanks for help

Edited by behnam
Link to comment
Share on other sites

Hey behnam,

 

Give this code a try as I know this is working:

 

<?php
/**
* This API call is for OpenTicket which
* will open a new support ticket as a client
*
* @package WHMCS
* @link https://www.whmcs.com/
* @author WHMCS Chance
* @see http://docs.whmcs.com/API:Open_Ticket
*/

$url = 'http://yourdomain.tld/includes/api.php';
$user = 'adminuser';
$pass = md5('adminpass');

# Build your request params
$request = array(
   'username' => $user,
   'password' => $pass,
   'action' => 'openticket',
   'clientid' => '1',
   'deptid' => '4',
   'subject' => 'API TEST TICKET',
   'message' => 'Testing API OpenTicket call to see how this works!',
   'priority' => 'high',
   'customfields' => base64_encode(serialize(array('8' => 'Custom Support Field Value'))),
   'responsetype' = 'json',
);

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 60);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($request));

$response = curl_exec($ch);
if (curl_error($ch)) {
die('Conn Error: ' . curl_errno($ch) . ' - ' .curl_error($ch));
}
curl_close($ch);

$decode = json_decode($response);

# Show it on screen
echo '<textarea rows="50" cols="100">'
. 'Request: ' . print_r($request, true) . "\n"
. 'Response: ' . htmlentities($response) . "\n"
. 'Array: ' . print_r($decode, true)
. '</textarea>';

 

That should get you going.

Link to comment
Share on other sites

Hey behnam,

 

Give this code a try as I know this is working:

 

<?php
/**
* This API call is for OpenTicket which
* will open a new support ticket as a client
*
* @package WHMCS
* @link https://www.whmcs.com/
* @author WHMCS Chance
* @see http://docs.whmcs.com/API:Open_Ticket
*/

$url = 'http://yourdomain.tld/includes/api.php';
$user = 'adminuser';
$pass = md5('adminpass');

# Build your request params
$request = array(
   'username' => $user,
   'password' => $pass,
   'action' => 'openticket',
   'clientid' => '1',
   'deptid' => '4',
   'subject' => 'API TEST TICKET',
   'message' => 'Testing API OpenTicket call to see how this works!',
   'priority' => 'high',
   'customfields' => base64_encode(serialize(array('8' => 'Custom Support Field Value'))),
   'responsetype' = 'json',
);

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 60);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($request));

$response = curl_exec($ch);
if (curl_error($ch)) {
die('Conn Error: ' . curl_errno($ch) . ' - ' .curl_error($ch));
}
curl_close($ch);

$decode = json_decode($response);

# Show it on screen
echo '<textarea rows="50" cols="100">'
. 'Request: ' . print_r($request, true) . "\n"
. 'Response: ' . htmlentities($response) . "\n"
. 'Array: ' . print_r($decode, true)
. '</textarea>';

 

That should get you going.

 

Hello

 

Sorry for late reply .

 

This code worked fine after correct this line :

 'responsetype' = 'json', 

to

 'responsetype' => 'json',

 

 

I need to attach files when opening ticket thought api . is it possible ? how ?

 

Thanks for help !

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use & Guidelines and understand your posts will initially be pre-moderated