
Mods for HESK version: 3.1.1
HESK version: 2.7.3
Hosting company: N/A
URL of phpinfo.php: provided only if needed
URL of session_test.php: provided if needed
What terms did you try when SEARCHING for a solution: API
Write your message below:
Following are the errors seen in trying to make a ticket and what I did to get the API working to consistently create new tickets. I know this is still beta so I hope this helps in moving it a step forward.
Several areas needed changing in order to get API ticket creation working, but the final result is that it now does (and we can begin integrating this into our apps, etc.)!
body of call is very similar to the API sample (- suggestedArticles and screenResolution)
X-AUTH-TOKEN: token{"name":"My Name","email":"useyourrealeamail@example.com","category":"1","priority":1,"subject":"Billing Inquiry","message":"Here are some comments","html":false,"location":["-0.287","-73.513"],"userAgent":"Mozilla\/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit\/537.36 (KHTML, like Gecko) Chrome\/60.0.3112.113 Safari\/537.36","language":"English"}
NOTE: though the API does say "This endpoint DOES NOT require authentication", the header and token IS needed, but the token does not have to be valid (I put in "123456" and the tickets are generated just as well as a token freshly generated in MFH)
INITIAL API PROBLEM (first API call):
ERROR:
Troubleshooting this, I found that $userContext is empty, so the code/api/BusinessLogic/Categories/CategoryRetriever.php:29 Trying to get property of non-object
Code: Select all
$category->accessible = $userContext->admin ...
I changed it to
Code: Select all
if (!empty($userContext)) {
$category->accessible = $userContext->admin ||
in_array($category->id, $userContext->categories);
}
SECOND ATTEMPT (after bypassing the non-object error)
Received the error
This is due to $ticket->email actually being a string, not an array, so the code/api/BusinessLogic/Emails/EmailTemplateParser.php:182 implode(): Invalid arguments passed
Code: Select all
rawurlencode(implode(';', $ticket->email))
This code may be used in other fashions, though the API documentation clearly states that email should be a string, so I fixed the code to be
Code: Select all
$emails = is_array($ticket->email)? implode(";", $ticket->email) : $ticket->email;
$heskSettings['e_param'] = $heskSettings['email_view_ticket'] ? '&e=' . rawurlencode( $emails) : '';
Code: Select all
$msg = str_replace('%%EMAIL%%', implode(';',$ticket->email), $msg);
Code: Select all
$msg = str_replace('%%EMAIL%%', $emails, $msg);