Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save dineshprabu-freshdesk/180bb6abc479ec3236ba0d404fe5d92c to your computer and use it in GitHub Desktop.
Save dineshprabu-freshdesk/180bb6abc479ec3236ba0d404fe5d92c to your computer and use it in GitHub Desktop.
Custom Field Updation with API v2
<script>
var api_key = "API-KEY";
function update_custom_field(ticket_field_id, callback){
var payload = '{"custom_fields":{"account": "{{ticket.company.account}}"}}';
var url = 'https://'+window.location.hostname+window.location.pathname.replace('/helpdesk','/api/v2')
jQuery.ajax({
type: 'PUT',
url: url,
data : payload,
contentType: 'application/json',
headers: {"Authorization": "Basic " + btoa(api_key+":"+'X')},
success: function(data){
callback(ticket_field_id);
},
error: function(jqxhr, text_status, error_thrown) {
console.log(text_status, error_thrown);
callback(ticket_field_id);
}
});
}
function update_ticket_field(ticket_field_id){
jQuery('#'+ticket_field_id).val("{{ticket.company.account}}");
}
update_custom_field('CUSTOM-FIELD-ID', update_ticket_field);
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment