Skip to content

Instantly share code, notes, and snippets.

@chucknado
Last active August 14, 2021 11:01
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chucknado/2f349571fcbfc7181550dd6433809346 to your computer and use it in GitHub Desktop.
Save chucknado/2f349571fcbfc7181550dd6433809346 to your computer and use it in GitHub Desktop.
Sample JavaScript for the Zendesk Apps tutorial, Accessing external data, at https://support.zendesk.com/hc/en-us/articles/222391587
$(function() {
var client = ZAFClient.init();
client.invoke('resize', { width: '100%', height: '400px' });
showStart();
$("#get-tasks").click(function() {
getTaskData(client);
});
});
function showStart() {
switchTo('start-hdbs');
}
function getTaskData(client) {
var settings = {
url: 'https://app.asana.com/api/1.0/projects/155581874072676/tasks',
headers: {"Authorization": "Bearer {{setting.token}}"},
secure: true,
type: 'GET',
dataType: 'json'
};
client.request(settings).then(
function(data) {
showTaskData(data);
},
function(response) {
showError(response);
}
);
}
function showTaskData(tasks) {
var context = {
project_tasks: tasks.data
};
switchTo('tasks-hdbs', context);
}
function showError(response) {
var context = {
'status': response.status,
'statusText': response.statusText
};
switchTo('error-hdbs', context);
}
function switchTo(template_name, context) {
var template_id = "#" + template_name;
var source = $(template_id).html();
var template = Handlebars.compile(source);
if (context) {
var html = template(context);
} else {
var html = template();
}
$("#content").html(html);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment