Forums/Community/Community tips & tricks

Widget: Automatically Create Organizations (Zendesk Classic)

Eric Dahl
posted this on September 21, 2011 09:08

I have created a widget that will automatically create organizations for you as your agents respond to tickets. It requires you Base64 Encode your API credentials. For example, if your email is "user@domain.com" and password is "password", you would Base64 encode the string "user@domain.com:password"

You can encode your info here: http://ostermiller.org/calc/encode.html - or with any base64 tool you choose.

Once created, simply add this widget to a ticket page.

I hope some of you find this useful.

Eric Dahl
Groupon.com

 


<div id="orgDIV"></div>
<script type="text/javascript">

var str = $j("ul.options li.email a").text();
var substr = str.split('@');

$j.ajax({
'type': 'POST',
'Content-Type': 'application/xml',
'url': 'http://XXXXX.zendesk.com/organizations.xml', //Change to your Zendesk URL - if your are not XXXXX.zendesk.com, you will need to put your correct URL in place of XXXXX.zendesk.com
'data': '<organization><name>'+ substr[1] +'</name><default>'+ substr[1] +'</default></organization>',
'beforeSend': function(xhr) {
xhr.setRequestHeader("Authentication", "Basic " + "XXXXXXXXXX"); //Insert Base64 Encoded "username:password" here
xhr.setRequestHeader("Content-Type", "application/xml");
},
success: function(response) {

$j("#orgDIV").text("Organization Created");
},
error: function(response) {
$j("#orgDIV").text("Organization Already Exists");
}

});
</script>

 

updated: 2011-12-14

 

Comments

User photo
Glyn Boone
weyerhaeuser
How is this supposed to function? I encoded by login information, updated my URL and created a custom html widget that I put on a page. Nothing seems to happen. What am I missing? What should the agent be able to do if this is functioning properly?
December 09, 2011 11:38
User photo
Eric Dahl
groupon

Did you add this to the page where you view tickets?  If its working, it should create organizations.  Is it not?

December 09, 2011 13:35
User photo
Glyn Boone
weyerhaeuser
Yes, I placed the widget on pages where I create, view and edit tickets. The title of the widget shows up but nothing else. I'm not clear on how it is supposed to function.
December 12, 2011 14:12
User photo
Eric Dahl
groupon

It doesn't "do" anything visible.  It makes API calls in the background.

When you go to Manage > People > Organizations is it creating Org's for your user's domains?

December 12, 2011 14:27
User photo
Eric Dahl
groupon

I have updated the code to now give some feedback:

 

<div id="orgDIV"></div>
<script type="text/javascript">

var str = $j("ul.options li.email a").text();
var substr = str.split('@');

$j.ajax({
'type': 'POST',
'Content-Type': 'application/xml',
'url': 'http://XXXXXX.zendesk.com/organizations.xml', //Change to your Zendesk URL
'data': '<organization><name>'+ substr[1] +'</name><default>'+ substr[1] +'</default></organization>',
'beforeSend': function(xhr) {
xhr.setRequestHeader("Authentication", "Basic " + "XXXXXXXXXX"); //Insert Base64 Encoded "username:password" here
xhr.setRequestHeader("Content-Type", "application/xml");
},
success: function(response) {
$j("#orgDIV").text("Organization Created");
},
error: function(xhr) {
$j("#orgDIV").text("Organization Already Exists");
}


});
</script>

December 12, 2011 14:54
User photo
Glyn Boone
weyerhaeuser

The widget is on the pages and now shows "Organization Already Exists".  But there is no organization for the requester being displayed.  Here is a screen capture.

December 14, 2011 06:05
User photo
Eric Dahl
groupon

When you go to:

http://XXXXXX.zendesk.com/organizations

do you see "barrywensonbuilder.com" listed as an organization?

December 14, 2011 07:39
User photo
Glyn Boone
weyerhaeuser

No.

December 14, 2011 07:47
User photo
Eric Dahl
groupon

Try replacing the error function with:

 

error: function(response) {
xmlDoc = $j.parseXML( response.responseText ),
x=xmlDoc.getElementsByTagName("error");
$j("#orgid").html(x[0]);
}

December 14, 2011 08:51
User photo
Eric Dahl
groupon

it will output the actual error code

December 14, 2011 08:51
User photo
Glyn Boone
weyerhaeuser

I'm still not seeing anything happening.  I guess I'll throw in the towel on it.  Thanks for your help on this!

What I really need is the ability for an Agent to add an organization without me giving them full Admin rights.  I'm not sure if that's something planned from Zendesk or not.

December 14, 2011 08:57
User photo
Eric Dahl
groupon

if you want to contact me off the forums, I could possibly take a look

edahl 'at' groupon 'dot' com

December 14, 2011 09:19
User photo
Eric Dahl
groupon

All, please disregard the code found in my comments.  I have updated the code in the original post

December 14, 2011 11:21
User photo
Alex Vercammen

I am working on a widget using JSON. I need to create a user (successful) with the Organization set. I know the Organization NAME, not the ID. Can you tell what is the object structure?

Here is the successful part: I could not formated in a better way. Commented part is the offender

var apiCall = {};
apiCall.user = {};
apiCall.user.name = $j('#vendorTag').val();
apiCall.user.email = userEmail;     
// apiCall.user.organization = {};     
// apiCall.user.organization.name = $j('#vendorTag').val();          
var userCall = JSON.stringify(apiCall);
// alert("USER: "+userCall);     

create_user(userCall);

 

 //creates new user  
create_user = function(apiCall)  
{
  log_status('User...');
  $j.ajax(
  {
   url: '/users.json',
   dataType: 'JSON',
   type: 'POST',
   data: apiCall,
   contentType: 'application/json',
   statusCode:
   {
    201: function()
    {
     log_status("User Created");
    }
   },
   success: function()
   {
    log_status("User Created");
    fade_status();
   }
  });
 };

June 19, 2012 09:18