Created
September 1, 2016 05:46
-
-
Save dineshprabu-freshdesk/180bb6abc479ec3236ba0d404fe5d92c to your computer and use it in GitHub Desktop.
Custom Field Updation with API v2
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
<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