Created
August 31, 2015 23:34
-
-
Save tstachl/cb78c9bef2e1f3504c59 to your computer and use it in GitHub Desktop.
Updating the draft using Desk.com Canvas.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!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