Skip to main content
Closed for Voting

Client is not defined in a Request API

Related products:Freshdesk
  • November 4, 2019
  • 1 reply
  • 100 views

Hi. Im building an app to bring information from an crm but I got this error: 


app.js:484 Uncaught ReferenceError: client is not defined


This is my code in app.js: 


 

$(document).ready( function() {
    app.initialized()
        .then(function(_client) {
          var client = _client;
          client.events.on('app.activated',
            function() {
                client.data.get('contact')
                    .then(function(data) {
                        $('#apptext').text("Ticket created by " + data.contact.name);
                    })
                    .catch(function(e) {
                        console.log('Exception - ', e);
                    });
                    client.events.on("ticket.customFieldChanged", eventCallback);
        });

    });
});
var eventCallback = function(event) {
  var customField = event.data; // { cf_single_line: { new: "1234", old: undefined } }
  var test = customField.cf_numero_fp.new;
var headers = {"Authorization": "eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJhYjQwMzIwM2MzNDE0MjYyOWVmNjcyMTUwZGQ4OGUxNCIsInJvbGUiOiJCUUFBQVFBQUFBQUFBQUFBQUFBQUFBQUFBQUE9IiwibmFtZSI6IkZyZXNoZGVzayBBUEkiLCJleHAiOjE1NzI4ODYxNjB9.xrYMTEoVfPSceb1HG6znsrgL5P617xiseyfy6fQoKB8"};
  var options = { headers: headers };
  var url = "https://ngapi.freedompop.mx/api/freshdesk/phone/" + test;
  client.request.get(url, options)
  .then (
  function(data) {
    console.log('Esto funciona');
    //client.interface.trigger("setValue", { id: "cf_number", value:data.cf_serie_sim_iccid})
    //client.interface.trigger("setValue", { id: "cf_number", value:data.iccid})
  },
  function(error) {
    console.log(error);
  });
}


I will be grateful if you can help me. 


Thanks 



1 reply

Hello,  

Apologies for the delay in response. Are you still facing trouble with building this custom app?
If yes, please write to support(at)freshdesk.com and one of our support folks will assist you further on this.

Cheers!