Want more features on Pastebin? Sign Up, it's FREE!
Guest

Untitled

By: a guest on Jan 27th, 2013  |  syntax: None  |  size: 13.55 KB  |  views: 36  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. {"tickets":[{"url":"https://company.zendesk.com/api/v2/tickets/1.json","id":1,"external_id":null,"via":{"channel":"web","source":{"from":{},"to":{},"rel":null}},"created_at":"2012-10-01T16:06:33Z","updated_at":"2012-10-05T19:21:55Z","type":"incident","subject":"This is a sample ticket requested and submitted by you","description":"This is the first comment. Feel free to delete this sample ticket.","priority":"high","status":"closed","recipient":null,"requester_id":270249903,"submitter_id":270249903,"assignee_id":270249903,"organization_id":22242373,"group_id":20363013,"collaborator_ids":[],"forum_topic_id":null,"problem_id":null,"has_incidents":false,"due_at":null,"tags":["sample","zendesk"],"fields":[{"id":21717236,"value":"10/4/2012"}],"custom_fields":[{"id":21717236,"value":"10/4/2012"}],"satisfaction_rating":null},{"url":"https://company.zendesk.com/api/v2/tickets/2.json","id":2,"external_id":null,"via":{"channel":"email","source":{"from":{"address":"noreply@zendesk.com","name":"Zendesk"},"to":{"address":"support@company.zendesk.com","name":"Binary Stream Helpdesk"},"rel":null}},"created_at":"2012-10-01T16:33:58Z","updated_at":"2012-10-05T17:09:37Z","type":null,"subject":"Tudor Hofnar, here is the test ticket you requested","description":"        Hello! This is a Zendesk ticket. We are going to go through the basic support ticket operation in Zendesk.nn        If you are in your email reading this, please click on the link in the header that starts with Ticket #.nn        If you are in your Zendesk reading this, you will see the ticket number, the customer who sent this ticket in, and drop down menus that allow you to set things like status and priority. You'll also notice a blank text box below this comment. That is for you to respond. Let's do that:nn        1. Write: "Thanks for this information, please tell me more."n        2. Change the drop-down field labeled Status to "Pending"nn        If you follow these instructions, you'll get an email response back from us shortly.  You can also always see ticket updates by going back into your unsolved ticket view (click view in the top menu bar).n","priority":null,"status":"closed","recipient":null,"requester_id":270263553,"submitter_id":270263553,"assignee_id":270249903,"organization_id":null,"group_id":20363013,"collaborator_ids":[],"forum_topic_id":null,"problem_id":null,"has_incidents":false,"due_at":null,"tags":[],"fields":[{"id":21717236,"value":"10/4/2012"}],"custom_fields":[{"id":21717236,"value":"10/4/2012"}],"satisfaction_rating":null},{"url":"https://company.zendesk.com/api/v2/tickets/3.json","id":3,"external_id":null,"via":{"channel":"email","source":{"from":{"address":"tudor@binarystream.com","name":"Tudor Hofnar"},"to":{"address":"support@company.zendesk.com","name":"Binary Stream Helpdesk"},"rel":null}},"created_at":"2012-10-01T17:08:37Z","updated_at":"2012-10-05T18:15:01Z","type":null,"subject":"test","description":"testnnTudor Hofnar","priority":null,"status":"closed","recipient":"support@company.zendesk.com","requester_id":270249903,"submitter_id":270249903,"assignee_id":270249903,"organization_id":22242373,"group_id":20363013,"collaborator_ids":[],"forum_topic_id":null,"problem_id":null,"has_incidents":false,"due_at":null,"tags":[],"fields":[{"id":21717236,"value":"10/4/2012"}],"custom_fields":[{"id":21717236,"value":"10/4/2012"}],"satisfaction_rating":null},{"url":"https://company.zendesk.com/api/v2/tickets/5.json","id":5,"external_id":null,"via":{"channel":"web","source":{"from":{},"to":{},"rel":null}},"created_at":"2012-10-01T20:26:34Z","updated_at":"2012-10-06T22:39:09Z","type":"incident","subject":"Window for adding account not opening","description":"The add account window is not opening and it is causing a lot of trouble for our team etc....","priority":"normal","status":"closed","recipient":null,"requester_id":271853958,"submitter_id":271853958,"assignee_id":270249903,"organization_id":22284363,"group_id":20363013,"collaborator_ids":[],"forum_topic_id":null,"problem_id":null,"has_incidents":false,"due_at":null,"tags":["2_2_2","4","ared","end_user_1","var_2"],"fields":[{"id":21704983,"value":"1"},{"id":21708732,"value":"tried this"},{"id":21708742,"value":"1"},{"id":21713331,"value":"10/2/2012"},{"id":21717086,"value":"ared"},{"id":21717236,"value":"10/4/2012"},{"id":21717357,"value":"2_2_2"}],"custom_fields":[{"id":21704983,"value":"1"},{"id":21708732,"value":"tried this"},{"id":21708742,"value":"1"},{"id":21713331,"value":"10/2/2012"},{"id":21717086,"value":"ared"},{"id":21717236,"value":"10/4/2012"},{"id":21717357,"value":"2_2_2"}],"satisfaction_rating":null},{"url":"https://company.zendesk.com/api/v2/tickets/6.json","id":6,"external_id":null,"via":{"channel":"web","source":{"from":{},"to":{},"rel":null}},"created_at":"2012-10-02T21:14:59Z","updated_at":"2012-10-09T18:22:04Z","type":"incident","subject":"Test Ticket","description":"this is a test ticket","priority":"normal","status":"closed","recipient":null,"requester_id":271853958,"submitter_id":271853958,"assignee_id":270249903,"organization_id":22284363,"group_id":20363013,"collaborator_ids":[],"forum_topic_id":null,"problem_id":null,"has_incidents":false,"due_at":null,"tags":["2_2_2","arcb","end_user_1","var_2"],"fields":[{"id":21704983,"value":"1"},{"id":21708732,"value":"tried this"},{"id":21708742,"value":"1"},{"id":21713331,"value":"10/2/2012"},{"id":21717086,"value":"arcb"},{"id":21717236,"value":"10/2/2012"},{"id":21717357,"value":""},{"id":21728942,"value":null},{"id":21732321,"value":"Test End-User"}],"custom_fields":[{"id":21704983,"value":"1"},{"id":21708732,"value":"tried this"},{"id":21708742,"value":"1"},{"id":21713331,"value":"10/2/2012"},{"id":21717086,"value":"arcb"},{"id":21717236,"value":"10/2/2012"},{"id":21717357,"value":""},{"id":21728942,"value":null},{"id":21732321,"value":"Test End-User"}],"satisfaction_rating":null},{"url":"https://company.zendesk.com/api/v2/tickets/7.json","id":7,"external_id":null,"via":{"channel":"web","source":{"from":{},"to":{},"rel":null}},"created_at":"2012-10-09T20:09:50Z","updated_at":"2012-10-11T18:19:42Z","type":"question","subject":"Testing bookmarks","description":"this is a bookmark testn","priority":"normal","status":"open","recipient":null,"requester_id":270249903,"submitter_id":270249903,"assignee_id":270249903,"organization_id":22242373,"group_id":20363013,"collaborator_ids":[],"forum_topic_id":null,"problem_id":null,"has_incidents":false,"due_at":null,"tags":["2010","psm"],"fields":[{"id":21704983,"value":"0"},{"id":21708732,"value":null},{"id":21708742,"value":"1"},{"id":21713331,"value":"10/9/2012"},{"id":21717086,"value":"psm"},{"id":21717236,"value":"10/31/2012"},{"id":21717357,"value":"2010"},{"id":21728942,"value":"Var 1"},{"id":21732321,"value":"End User 2"}],"custom_fields":[{"id":21704983,"value":"0"},{"id":21708732,"value":null},{"id":21708742,"value":"1"},{"id":21713331,"value":"10/9/2012"},{"id":21717086,"value":"psm"},{"id":21717236,"value":"10/31/2012"},{"id":21717357,"value":"2010"},{"id":21728942,"value":"Var 1"},{"id":21732321,"value":"End User 2"}],"satisfaction_rating":null}],"next_page":null,"previous_page":null,"count":6}
  2.        
  3. (function() {
  4.  
  5.   return {
  6.     // Here we define AJAX calls
  7.     requests: {
  8.       fetchTickets: function() {
  9.         return {
  10.           url: '/api/v2/tickets.json',
  11.           type: 'GET'
  12.         };
  13.       }
  14.     },
  15.     // Here we define events such as a user clicking on something
  16.     events: {
  17.       'app.activated': 'requestTickets',
  18.  
  19.       'fetchTickets.always': function(data) {
  20.         this.countEndUserTickets((data || {}).tickets);
  21.       }
  22.     },
  23.     // Below this point, you're free to define your own functions used by the app  
  24.     requestTickets: function() {
  25.       this.ajax('fetchTickets');
  26.     },
  27.  
  28.     countEndUserTickets: function(tickets) {
  29.       var endUser = this.ticket().customField("End-User"); //this will get the end-user of the current ticket that is open in Zendesk
  30.       var ticketCounter = 0;
  31.  
  32.       //this is where I have no idea how to access the 'tickets' array or whatever it is
  33.       for (var i = 0; i <= tickets.length; i++) {
  34.         if (tickets[i].customField("End-User") == endUser){
  35.           ticketCounter = ticketCounter + 1;
  36.         }
  37.       }
  38.  
  39.       alert(endUser);
  40.  
  41.       this.switchTo('list', {
  42.         ticketCounter: this.ticketCounter
  43.       });
  44.     }
  45.   };  
  46. }());
  47.        
  48. ticket.fields.filter(function(field) {
  49.     return field.id == 21732321;
  50. })[0].value;
  51.        
  52. function countTickets(user) {
  53.     var count = 0;
  54.     response.tickets.forEach(function(ticket) {
  55.         var filteredFields = ticket.fields.filter(function(field) {
  56.             return field.id == 21732321;
  57.         });
  58.         if (filteredFields.length > 0 && filteredFields[0].value == user) {
  59.             count++;
  60.         }
  61.     });
  62.     return count;
  63. }
  64.        
  65. var json = '{ "url":"https://test.zendesk.com/api/v2/tickets/6.json", "id":6, "external_id":null, "via":{ "channel":"web", "source":{ "from":{}, "to":{}, "rel":null } }, "created_at":"2012-10-02T21:14:59Z", "updated_at":"2012-10-09T18:22:04Z", "type":"incident", "subject":"Test Ticket", "description":"this is a test ticket", "priority":"normal", "status":"closed", "recipient":null, "requester_id":271853958, "submitter_id":271853958, "assignee_id":270249903, "organization_id":22284363, "group_id":20363013, "collaborator_ids":[], "forum_topic_id":null, "problem_id":null, "has_incidents":false, "due_at":null, "tags":["2_2_2","arcb","end_user_1","var_2"], "fields":[ {"id":21704983,"value":"1"}, {"id":21708732,"value":"tried this"}, {"id":21708742,"value":"1"}, {"id":21713331,"value":"10/2/2012"}, {"id":21717086,"value":"arcb"}, {"id":21717236,"value":"10/2/2012"}, {"id":21717357,"value":""}, {"id":21728942,"value":null}, {"id":21732321,"value":"Test End-User"}], "custom_fields":[{"id":21704983,"value":"1"}, {"id":21708732,"value":"tried this"}, {"id":21708742,"value":"1"}, {"id":21713331,"value":"10/2/2012"}, {"id":21717086,"value":"arcb"}, {"id":21717236,"value":"10/2/2012"}, {"id":21717357,"value":""}, {"id":21728942,"value":null}, {"id":21732321,"value":"Test End-User"}], "satisfaction_rating":null }';
  66.  
  67. var obj = JSON.parse(json);
  68. $('body').append('<div>Tags value: ' + obj.tags + '</div><br>');
  69. var len = obj.custom_fields.length;
  70.  
  71. for(n = 0; n < len; n++)
  72. {
  73.     $('body').append('<div>Custom field value: ' + obj.custom_fields[n].value + '</div>');
  74. }
  75.        
  76. $.getJSON('myfile.json', function(json) {
  77.  
  78.     // do something with json here
  79. });
  80.        
  81. $(document).ready(function () {
  82.     "use strict";
  83.     $.getJSON("getJSON.json", function (data) {
  84.         $("#look").on('click', function () {
  85.             var $output = $("#output");
  86.             var index, id = $("#input").val();
  87.             var filtered = data.custom_fields.filter(function (element) {
  88.                 return element.id.toString() == id;
  89.             });
  90.             $output.empty();
  91.             for (index in filtered) {
  92.                 $output.append("Value: " + filtered[index].value);
  93.             }
  94.             console.log(filtered);
  95.         });
  96.         console.log(data);
  97.     });
  98. });
  99.        
  100. <!DOCTYPE html>
  101. <html>
  102. <head>
  103.     <title></title>
  104.     <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
  105. </head>
  106. <body>
  107.     Pleased input a custom field ID:  <input id="input" type="text" value="21732321" />
  108.     <button id="look">Look Up By ID</button>
  109.     <p id="output"></p>
  110. <script type="text/javascript" src="getJSON.js"></script>
  111. </body>
  112. </html>
  113.        
  114. {
  115.     "url": "https://test.zendesk.com/api/v2/tickets/6.json",
  116.     "id": 6,
  117.     "external_id": null,
  118.     "via": {
  119.         "channel": "web",
  120.         "source": {
  121.             "from": {},
  122.             "to": {},
  123.             "rel": null
  124.         }
  125.     },
  126.     "created_at": "2012-10-02T21:14:59Z",
  127.     "updated_at": "2012-10-09T18:22:04Z",
  128.     "type": "incident",
  129.     "subject": "Test Ticket",
  130.     "description": "this is a test ticket",
  131.     "priority": "normal",
  132.     "status": "closed",
  133.     "recipient": null,
  134.     "requester_id": 271853958,
  135.     "submitter_id": 271853958,
  136.     "assignee_id": 270249903,
  137.     "organization_id": 22284363,
  138.     "group_id": 20363013,
  139.     "collaborator_ids": [],
  140.     "forum_topic_id": null,
  141.     "problem_id": null,
  142.     "has_incidents": false,
  143.     "due_at": null,
  144.     "tags": [
  145.         "2_2_2",
  146.         "arcb",
  147.         "end_user_1",
  148.         "var_2"
  149.     ],
  150.     "fields": [
  151.         {
  152.             "id": 21704983,
  153.             "value": "1"
  154.         },
  155.         {
  156.             "id": 21708732,
  157.             "value": "tried this"
  158.         },
  159.         {
  160.             "id": 21708742,
  161.             "value": "1"
  162.         },
  163.         {
  164.             "id": 21713331,
  165.             "value": "10/2/2012"
  166.         },
  167.         {
  168.             "id": 21717086,
  169.             "value": "arcb"
  170.         },
  171.         {
  172.             "id": 21717236,
  173.             "value": "10/2/2012"
  174.         },
  175.         {
  176.             "id": 21717357,
  177.             "value": ""
  178.         },
  179.         {
  180.             "id": 21728942,
  181.             "value": null
  182.         },
  183.         {
  184.             "id": 21732321,
  185.             "value": "Test End-User"
  186.         }
  187.     ],
  188.     "custom_fields": [
  189.         {
  190.             "id": 21704983,
  191.             "value": "1"
  192.         },
  193.         {
  194.             "id": 21708732,
  195.             "value": "tried this"
  196.         },
  197.         {
  198.             "id": 21708742,
  199.             "value": "1"
  200.         },
  201.         {
  202.             "id": 21713331,
  203.             "value": "10/2/2012"
  204.         },
  205.         {
  206.             "id": 21717086,
  207.             "value": "arcb"
  208.         },
  209.         {
  210.             "id": 21717236,
  211.             "value": "10/2/2012"
  212.         },
  213.         {
  214.             "id": 21717357,
  215.             "value": ""
  216.         },
  217.         {
  218.             "id": 21728942,
  219.             "value": null
  220.         },
  221.         {
  222.             "id": 21732321,
  223.             "value": "Test End-User"
  224.         }
  225.     ],
  226.     "satisfaction_rating": null
  227. }
clone this paste RAW Paste Data