Migrate Freshdesk Tickets to Zendesk
If, like me, you were frustrated by the lack of an easy way to migrate your helpdesk tickets from Freshdesk to Zendesk and baffled by the lack of script examples to be found on Google, then this post may be of help to you.
Below is a simple PHP script (it's in PHP because that's the language of the current projects I'm working on), that retrieves the tickets in Freshdesk using the Freshdesk API, then posts them into Zendesk using the Zendesk API, converting field names, etc. in the process.
I don't pretend this is pretty or well executed, but it works and may be a starting point for you that could save some time. You will need to check the fields you need are migrated and check how many pages of tickets you have, etc. It takes time because of the API requests/posts, so be patient (if that's difficult, like me, keep refreshing your Zendesk views and watch the ticket counters increase) ...
Hope it's helpful.
Kearon.
<?php
//Freshdesk details
$f_url = "http://companysub.freshdesk.com//helpdesk/tickets.xml?filter_name=all_tickets&page=";
$f_user = 'my.user@mycompany.com';
$f_pass = 'myFDpassword';
//Zendesk details
$z_url = "https://companysub.zendesk.com/api/v2/imports/tickets.json";
$z_user = 'my.user@mycompany.com';
$z_pass = 'myZDpassword';
//place holders
$sXML = "";
$results = "";
//function to retrieve Freshdesk tickets
function getFreshdeskTickets($path, $user, $pass) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $path);
curl_setopt($ch, CURLOPT_USERPWD, "$user:$pass");
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($ch, CURLOPT_FAILONERROR, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 100);
$retValue = curl_exec($ch);
curl_close($ch);
return $retValue;
}
//function to post single ticket to Zendesk api
function postTicketToZendesk($path, $user, $pass, $json) {
$ch = curl_init($path);
curl_setopt($ch, CURLOPT_USERPWD, "$user:$pass");
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $json);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FAILONERROR, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json', 'Content-Length: ' . strlen($json)));
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); //should probably actually point Curl at the ssl certificate, but this is quicker...
$curl_result = curl_exec($ch);
if($curl_result === false)
{
$curl_result = 'Curl error: ' . curl_error($ch);
}
// else
// {
// $curl_result = 'Operation completed without any errors';
// }
//$curl_result = curl_exec($ch);
curl_close($ch);
return $curl_result;
}
//using paging for the requests (otherwise the Freshdesk API seems to fall over), currently there are 15 pages of tickets (449 tickets), so 15 loops
$page = 1;
while ($page <= 15) {
$t_url = $f_url . $page;
$page++;
$output = getFreshdeskTickets($t_url, $f_user, $f_pass);
//do some cleaning up to make sure it parses properly
$output = str_replace(array("\n", "\r", "\t"), '', $output);
//- remove line breaks, tabs, etc.
$output = trim(str_replace('"', "'", $output));
// - replace double quotes with single and trim
//remove the opening and closing xml tags
$output = str_replace("<?xml version='1.0' encoding='UTF-8'?><helpdesk-tickets type='array'>", "", $output);
$output = str_replace("</helpdesk-tickets>", "", $output);
$sXML = $sXML . $output;
//append this output.
}
//put the opening and closing xml tags back on
$sXML = '<?xml version="1.0" encoding="UTF-8"?>
<helpdesk-tickets type="array">' . $sXML;
$sXML = $sXML . '</helpdesk-tickets>';
//echo $sXML;
//convert to simple xml
$simpleXml = simplexml_load_string($sXML);
//print($simpleXml);
// loop the freshdesk tickets, building zendesk json
// looks like ZenDesk ticket importer might only take one ticket at a
// time, so going to import them as I loop through the output.
$result = "";
$count = 0;
foreach ($simpleXml->{'helpdesk-ticket'} as $ticket) {
$json = "{";
//open json
//some fields need a little pre-processing
//priority
$priority = "low";
switch ($ticket -> priority ) {
case '1' :
$priority = "low";
break;
case '2' :
$priority = "normal";
break;
case '3' :
$priority = "high";
break;
case '4' :
$priority = "urgent";
break;
default :
$priority = "low";
break;
}
//status
$status = "open";
switch ($ticket -> status ) {
case '1' :
$status = "new";
break;
case '2' :
$status = "open";
break;
case '3' :
$status = "pending";
break;
case '4' :
$status = "solved";
break;
case '5' :
$status = "closed";
break;
default :
$status = "open";
break;
}
$json = $json . '"ticket": {' ;
//start ticket
$json = $json . '"external_id": "' . $ticket -> {'display-id'} . '"' ;
$json = $json . ', "subject": "' . $ticket -> subject . '"' ;
$json = $json . ', "created_at": "' . $ticket -> {'created-at'} . '"' ;
$json = $json . ', "updated_at": "' . $ticket -> {'updated-at'} . '"' ;
if ($status == "solved" OR $status == "closed") {
$json = $json . ', "solved_at": "' . $ticket -> {'updated-at'} . '"' ;
}
$json = $json . ', "priority": "' . $priority . '"' ;
$json = $json . ', "status": "' . $status . '"' ;
$json = $json . ', "comments": [{ "author_id": 389931077, "value": "' . $ticket -> {'description'} . '"} ]' ;
//make all comments by Alan - too complicated to bother otherwise
$json = $json . ', "tags": ["' . $ticket -> {'ticket-type'} . '", "freshdesk_import"]' ;
//end ticket
$json = $json . '}';
//close json
$result = $result . postTicketToZendesk($z_url, $z_user, $z_pass, $json);
$count++;
//echo $count . "<br />\n";
}
echo "processed " . $count . " records: \n" . $result;
?>
-
Thanks for all your hard work "special" K :o)
-
I. LOVE. THIS! Thank you very much for sharing!
-
awesome stuff!
-
Out of curiosity, how many tickets did you migrate? And how long did it take?
Thanks -
We only migrated 459 tickets, which took a few minutes. Each Zendesk ticket import is a separate Curl request. I'm sure you could speed it up with multiple API calls, but I opted for slow, but steady (and simple) as we didn't have that many tickets to migrate. I also used paged requests to get details out of Freshdesk because I found the Freshdesk API seemed to give back variable numbers of tickets otherwise ! Now I'm just waiting for the stats to update so I can get a good feel of reporting using GoodData.
-
Can we all call you "Special K?" :) Because that's what I'm thinking right now!
This is so awesome. Thanks for sharing your code! Really.
-
You're welcome. Feeling a little abashed. Was just a quick script knocked together in 5 minutes between other jobs. It's not particularly well done, but got the job done for us and hopefully will be useful to a few people.
-
Impressive. Would love see what amazing things you come up with in 10 minutes. :)
Thanks again and feel free to post more any other scripts that you knock together!
-
I wrote a Python script for that:
https://github.com/mittsh/freshdesk-zendesk-migration
It migrates all Comments / Notes from Freshdesk, and sets the right Author, and adds a last migration comment with infos about the Freshdesk ticket (URL, ID). It also migrates the extra fields...
-
Awesome, thanks for sharing Micha!
-
Now there is an easy way to migrate from Freshdesk to Zendesk - go with the tool that we developed - Import2 ( https://www.import2.com/zendesk/from/freshdesk/). It will automatically import your records saving you tons of effort and time.
-
About to migrate someone from Freshdesk to Zendesk and I found this helpful twice. #winning
-
Glad to hear it, Andrea!
-
I should start getting commission for this :P #anotheroneconverted
-
Hi Everyone,
When I tried to run this script, I got the following results:
processed 0 records:
Any idea why that is?
I ran the script on my personal PC using XAMPP, am I missing something?
I only modified the username, password and URL's for Zendesk / Freshdesk. Was I supposed to modify anything else?
Kind Regards,
Aaron Moffatt -
There is an online service that allows to move data from FreshDesk to ZenDesk without codding. Help Desk Migration Service https://www.help-desk-migration.com/
-
@John
Thanks for your link!
I spent just several hours and moved my data from freshdesk to zendesk without efforts!
The best thing is that service allows to map custom fields.
The best automation ever!
-
Hi,
I was having problem with the ticketing. I failed to migrate the images, the complete conversations within the ticket.How do I solve this? Please help.
-
Fahranim, your best options is still to use 3rd party partner - https://www.import2.com/zendesk/helpdesk/from/freshdesk - this will automate a switch of your ticket data from Freshdesk and will also transfer complete conversation including the attachments.
Hope this helps
-
Third party cost too much since we only have not more than 300 tickets. Is there any other ways to do this?
-
Farhanim, use our service Help Desk Migration.
Our pricing is more flexible :)
-
Hi Team,
i want to migrate my freshdesk tickets to zendesk portal above php scripts where i have to use those please me help out.
Regards,
Mahendar,
9700700399
-
Hey Padah,
You don't need to use any scripts.
Try Help Desk Migration https://help-desk-migration.com/freshdesk-to-zendesk-migration/
Please sign in to leave a comment.
23 Comments