Start a new topic
Solved

Access custom_fields with JS API

Hello,


I have created a custom field alled "dringid" on my contacts.


It appears when I perform a curl requet : 


 

curl -u APIKEY:X -X GET https://dring.freshdesk.com/api/v2/contacts/43000011679 

{"active":false,"address":null,"company_id":null,"view_all_tickets":null,"description":null,"email":"matt.rogers@freshdesk.com","id":43000011679,"job_title":null,"language":"en","mobile":null,"name":"Matt Rogers","phone":null,"time_zone":"Eastern Time (US & Canada)","twitter_id":null,"custom_fields":{"dringid":"189"},"tags":[],"other_emails":[],"facebook_id":null,"created_at":"2018-05-11T12:47:15Z","updated_at":"2018-05-11T14:19:06Z","other_companies":[],"avatar":null}

 I'd like to use it in my custom app with the JS library.

 

$(document).ready( function() {
    app.initialized()
        .then(function(_client) {
          var client = _client;
          client.events.on('app.activated',
            function() {
                client.data.get('contact')
                    .then(function(data) {
                        console.log(data.contact.custom_fields.dringid);                        
                    })
                    .catch(function(e) {
                        console.log('Exception - ', e);
                    });
        });
    });
});

 But unfortunately, data.contact.custom_fields.dringid seems undefined.


How should I access this custom field ?


Regards,


Hi Jérémie,


Can you please let us know from which page you are trying to access this custom field?


You won't be able to access custom fields of a contact from the tickets detail page. You can access custom fields of a contact only from contacts detail page. 


Please refer the following documentation for further clarity :


https://developers.freshdesk.com/v2/docs/data-api#ticket_details_page_apis - Refer to the contacts section under this.


https://developers.freshdesk.com/v2/docs/data-api#contact_details_page_apis - Refer to the contacts section under this.


Please reach out for any help needed.


Thanks,

Vinay Karthikk S

Hi,


Indeed, I was trying to access a contact custom field from the ticket details page. It works from the contact details page.

So you mean this is not possible at all accessing contact custom fields from a ticket details ? I can access any contact info there, except the custom fields ?


Thanks, 


Regards

Hi Jérémie,


Yes. Its not possible to access contact custom fields from the ticket details page.


You can go through https://developers.freshdesk.com/v2/docs/data-api/#contactAPI and refer the attributes table for the list of attributes that can be accessed for contacts from a tickets detail page.


Thanks,

Vinay Karthikk S

OK, so I understand this is not possible to access custom fields from ticket details page.


For my business, this is very necessary to do so. 


Do you think of any other solution / way to achieve this ?


Thanks,

Hi Jérémie,


You can try this using the freshdesk contact API for custom fields as mentioned in this document https://developer.freshdesk.com/api/#contacts . You will need to use request API to implement this. You can refer usage of request API here : https://developer.freshdesk.com/v2/docs/request-api/


Thanks,

Vinay Karthikk S

Login or Signup to post a comment