Skip to content

Instantly share code, notes, and snippets.

@tstachl
Created August 31, 2015 23:34
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 tstachl/cb78c9bef2e1f3504c59 to your computer and use it in GitHub Desktop.
Save tstachl/cb78c9bef2e1f3504c59 to your computer and use it in GitHub Desktop.
Updating the draft using Desk.com Canvas.
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Update Draft</title>
<meta name="description" content="A Desk.com canvas app example that updates a draft.">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>
<script src="//ajax.deskapi.com/libs/desk/canvas/1.0.0/desk-canvas-all.js"></script>
<script>
Desk.canvas(function() {
Desk.canvas.client.refreshSignedRequest(function(data) {
if (data.status === 200) {
var sr = data.payload.response.split('.')[1]
, ctx = JSON.parse(Desk.canvas.decode(sr))
, url = ctx.context.environment.case.url + '/replies/draft'
$('button').click(function() {
Desk.canvas.client.ajax(url, {
client: ctx.client,
method: 'PATCH',
contentType: 'application/json',
data: JSON.stringify({ body: 'This is the text for a reply to a case.' + Date.now() }),
success: function(rsp) {
console.log(rsp)
}
})
})
}
})
})
</script>
</head>
<body>
<button>Update Draft</button>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment