behnam Posted May 16, 2016 Share Posted May 16, 2016 (edited) 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 May 16, 2016 by behnam 0 Quote Link to comment Share on other sites More sharing options...
servetas Posted May 17, 2016 Share Posted May 17, 2016 Why have you commented it out? curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($postfields)); Also, check the $postfields variable you pass. You have set the post values as $postdata. I do not know if this is the issue but it's something as a beginning. http://docs.whmcs.com/API:Example_Usage 0 Quote Link to comment Share on other sites More sharing options...
WHMCS Chance Posted May 20, 2016 Share Posted May 20, 2016 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. 0 Quote Link to comment Share on other sites More sharing options...
behnam Posted May 22, 2016 Author Share Posted May 22, 2016 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 ! 0 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.