Zendesk Script – Business hours + Voicemail greetings

No Comments

Not everything that I do is done in JavaScript. Today I bring you a PHP script that will automatically change your voicemail greetings depending if you are within your business hours or not.

The script is not as dynamic as I would like it to have been but due to some API limitations you will need to spend 2 more minutes configuring it. Basically since I can’t retrieve the business hours using the API you will have to set them up on the config file.

A quick summary of what this script does is:

  • If you are within business hours -> Set one voicemail greeting.
  • If you are not withing busines hours -> Set another voicemail greeting.

The script can be found on my GitHub profile as always. All you need to edit is fully explained on the readme in GitHub but here you have a nice copy&paste.

1.Edit the bh-config.php

ZD_SUBDOMAIN

This is the subdomain of your Zendesk account. If your account is https://test.zendesk.com the value should be test.

If you are using hostmapping in your account you have to use the unmapped version.

support.mydomain.com -> test.zendesk.com

The value should be test.

ZD_EMAIL

Your Zendesk user email.

ZD_TOKEN

This is the API token for your Zendesk account. You can get one by going to Admin > Channels >API

TIMEZONE

The timezone of your account. Make sure that the timezone matches the one in Zendesk or otherwise you will change the greetings when you don’t want to. All possible timezone values can be found here.

START_GREETING

This is the greeting ID that will be used when you are within your business hours. To get it you have to:

  1. Right click the edit link for that greeting.
  2. Copy the only number you will see in the URL

e.g.

https://test.zendesk.com/voice/greetings/20025412/edit

The ID for this greeting is 20025412.

END_GREETING

This is the greeting ID that will be used when you are NOT within your business hours. To get it you have to:

  1. Right click the edit link for that greeting.
  2. Copy the only number you will see in the URL

e.g.

https://test.zendesk.com/voice/greetings/20025111/edit

The ID for this greeting is 20025111.

business_hours

Here you can configure the business hours for each day of the week. The days are as follows:

0 -> Sunday 1 -> Monday 2 -> Tuesday 3 -> Wednesday 4 -> Thursday 5 -> Friday 6 -> Saturday

Hour format must be in 24H and can only have o’clock on half-past hours.

e.g.

$business_hours = array(
    '0' => array(
        'start' => '',
        'end' => ''
        ),
    '1' => array(
        'start' => '07:00',
        'end' => '17:30'
        ),
    '2' => array(
        'start' => '07:00',
        'end' => '17:30'
        ),
    '3' => array(
        'start' => '07:00',
        'end' => '17:30'
        ),
    '4' => array(
        'start' => '07:00',
        'end' => '17:30'
        ),
    '5' => array(
        'start' => '07:00',
        'end' => '17:30'
        ),
    '6' => array(
        'start' => '',
        'end' => ''
        )
    );

In this example my office hours are Mon-Fri from 07:00 until 17:00.

2. Create a Cron Job that will run every 30 minutes.

Every 30 minutes we will need to run this script, to do so you can achieve it by creating a Cron Job.

*/30 * * * *    php /path/to/the/script/business_hours.php

I just hope you find it useful. Feedback is more than welcome!

Zendesk Script – Delete all organizations

No Comments

So, this is going to be my first post of 2015. I haven’t had time for anything since holidays but now I have some free time to provide you the latest script.

You know those moments were you are kind of… SCREW EVERYTHING!!! I’m going to start over! Well, one of the steps you will need to do in your Zendesk account at some point is to delete all the organizations. To do so, you just have to use this simple script:

var v_subdomain = "SUBDOMAIN";
var v_orgs_amount = ORGAMOUNTS;

function getOrgs(page) {

    $.ajax({
        url: "https://" + v_subdomain + ".zendesk.com/api/v2/organizations.json?page=" + page,
        type: "GET",
        dataType: "JSON"
    }).done(function(data) {
        console.log(data);
        for (var i = 0; i < data.organizations.length; i++) {
            var orgid = data.organizations[i].id;
            deleteOrg(orgid)
        }
    });
}


function deleteOrg(orgID) {
    setTimeout(function() {
        $.ajax({
            url: "https://" + v_subdomain + ".zendesk.com/api/v2/organizations/" + orgID + ".json",
            type: "DELETE",
            dataType: "JSON"
        }).done(function(data) {
            console.log("Organization " + orgID + " Deleted");
        }).fail(function(data) {
            console.log("Can't delete organization ID " + orgID);
        })
    }, 5000);
}

for (var j = 0; j < Math.ceil(v_orgs_amount / 100); j++) {
    getOrgs(j + 1);
}

As always you will just need to fill your v_subdomain and the amount of organizations you have. Open the Chrome console while you are logged in your Zendesk account, paste the code and run it! :)

I’ve tried to add some waiting time on the AJAX call to avoid reaching the API limits in case you have a lot of Organizations but I think I did it wrong. May you reach the limit, wait a few and run it again. (Make sure you change the amount of Orgs since you have already deleted some). I’ll investigate a bit more and I will update all the scripts once I find out the best solution for it.

Remember that as always you can see the latest code in my GitHub profile and that…

with-great-power-comes-great-responsibility-and-great-drama

 

Zendesk Script – List all suspended Users.

No Comments

It’s been long since I last updated the blog. I’ve been “busy” with christmas parties and traveling between Dublin and Cork (and Spain!). Yay, I’m now home for the holidays. :)

Today I bring you a small script that can be pasted in the Developer Tools console once you are logged into your Zendesk account and will list all the suspended users for your account with a link to see their profiles.

var v_subdomain = "SUBDOMAIN";
var v_users_amount = USERCOUNT;

function getUsers(page) {

    $.ajax({
        url: "https://"+v_subdomain+".zendesk.com/api/v2/users.json?role=end-user&page=" + page,
        type: "GET",
        dataType: "JSON"
    }).done(function(results) {

        var userList = results.users;
        for (var i = 1; i < results.users.length; i++) {
            if(userList[i].suspended){
                console.log('User: '+userList[i].name + ' - https://'+v_subdomain+'.zendesk.com/agent/users/'+userList[i].id+'/requested_tickets'  );
            }
        }
    });
}

for (var j = 0; j < Math.ceil(v_users_amount/100); j++) {
    getUsers(j + 1);
}

It’s really easy to use.

  1. Edit the values for v_subdomain and v_users_amount.
  2. Log in into your Zendesk account. (I always use Google Chrome)
  3. Open the Developer Tools.
  4. Paste the code and press enter.
  5. Enjoy!

As always, you can find this script with the other ones in my GitHub Profile.

I almost forget! The progress on the Taskmanager ruby app has been amazing and I hope I will have a post coming out soon! ^_^

Happy coding and enjoy the holidays!!

Zendesk Script – Delete all user tickets!

No Comments

Have you ever come across that moment where you want to delete all the tickets from a user but there are so many you don’t want to spend 10 minutes doing so?  Well, I have done a small script  that will allow you to delete all tickets from an specific user. Remember that you can always get the latest code in my GitHub profile .

This is the code:

var v_subdomain = "SUBDOMAIN";
var v_user_id = USERID;
var v_tickets_amount = AMOUNTOFTICKETS;

function getTickets(page) {

    $.ajax({
        url: "https://"+v_subdomain+".zendesk.com/api/v2/users/"+v_user_id+"/tickets/requested.json?page=" + page,
        type: "GET",
        dataType: "JSON"
    }).done(function(data) {
        var ticketIDs = data.tickets[0].id + "";
        for (var i = 1; i < data.tickets.length; i++) {
            ticketIDs += "," + data.tickets[i].id;
        }
        deleteTickets(ticketIDs);
    });
}


function deleteTickets(ticketIDs) {

    $.ajax({
        url: "https://"+v_subdomain+".zendesk.com/api/v2/tickets/destroy_many.json?ids=" + ticketIDs,
        type: "DELETE",
        dataType: "JSON"
    }).done(function(data) {
        console.log("Page Deleted");
    }).fail(function(data) {
        console.log("Can't delete page with ticket ID's " + ticketIDs);
    });
}

for (var j = 0; j < Math.ceil(v_tickets_amount/100); j++) {
    getTickets(j + 1);
}

It’s quite simple and what you need to do in order to make it to work is edit 3 simple things.

//Replace v_subdomain with your subdomain. If your account is myaccount.zendesk.com just type myaccount. Leave the quotation marks!
var v_subdomain = "SUBDOMAIN";

/*
*Replace v_user_id with the user ID for whom you want to delete all tickets. Go to Admin -> Manage -> People and click on the user. You will see that the url looks like this:
*https://myaccount.zendesk.com/agent/users/590180702/requested_tickets
*The USERID would be 590180702
*/
var v_user_id = USERID;

// Change AMOUNTOFTICKETS for the amount of tickets that the user has. If he has 4893 just write 4893 there.
var v_tickets_amount = AMOUNTOFTICKETS;

There is no confirmation for the action you are going to do so please make sure that the User ID is the correct one or you may delete the tickets for another user and there is no way to revert this. I will try to add some other verifications to avoid data loss but for the moment being remember:

with-great-power-comes-great-responsibility-and-great-drama