how can I using rest api in customCode?

I have added 'customCode' to a field in detailviewdefs.php for campaign module.  I want to populate a dropdown with some other values using a custom endpoint.

'customCode' => '<script type="text/javascript" src="custom/js/custom.js?v13225"></script><script>load_linked_vouchers("' . $focus->id . '")</script>'

so it loads my js file, and then runs a function comtained inside the js file, passing the record ID to the function.

Then in my custom.js I have the function

function load_linked_vouchers(id) {
    $.ajax({
        beforeSend: function (request) {
            request.setRequestHeader("OAuth-Token",SUGAR.App.api.getOAuthToken());
},
url: "rest/v10/Campaigns/" + id + "/link/igsm_igsmk_vouc_campaigns_1",
dataType: "json",
type: "GET",
}).done(function (response) {
console.log(response);
})
}

I get "Cannot read property 'api' of undefined" javascript error. I dont know why it SUGAR.App is undefined because it shows in the console so it must be global. Is the customCode ran seperately? how can I put the SUGAR.App into it? Am I doing this wrong or is there a better way?