Hi
This is my code please check I am getting status but I am not able get merchant id as it’s a custom field I think
if (args[‘data’][‘ticket’][‘group_id’] == ‘1082000658705’) {
let options = {
method: ‘POST’,
headers: {
‘Content-Type’: ‘application/x-www-form-urlencoded’
},
body: username=freshdeskintegrationuser2%40razorpay.com.produat&password=Freshdesk%40123454JvwhcZkpSWI807pJbnzke0E&grant_type=password&client_id=3MVG9qT0j3YAi4EtQRW.9zA7hFNf4UjR7_k.2GXDGvUjOwY_h2pxBIaX9ksP0hx2kXg07FdGfKGbxPWwnk9ze&client_secret=7F7A2DE605376391878EACF26698C6278E2D330404C9942FB216E0279E9A5E7C
};
try {
const response = await fetch(‘https://razorpay--produat.sandbox.my.salesforce.com/services/oauth2/token’, options);
const data = await response.json();
console.log(data);
let access_token = 'Bearer ’ + data.access_token;
console.log(data.access_token);
await updateSalesforceRecord(access_token, args);
} catch (error) {
console.log('error at ', error);
}
async function updateSalesforceRecord(access_token, args) {
try {
console.log(‘ard’ + args[‘data’][‘ticket’][‘id’]);
let options = {
method: ‘PATCH’,
headers: {
Authorization: access_token,
‘Content-Type’: ‘application/json;charset=UTF-8’
},
body: JSON.stringify({
Status__c: args[‘data’][‘ticket’][‘status’],
MID__c: args[‘data’][‘ticket’][‘custom_fields’][‘cf_merchant_id’],
})
};
console.log(https://razorpay--produat.sandbox.my.salesforce.com/services/data/v55.0/sobjects/Tech_Support_Ticket__c/FreshDesk_Ticket_Number__c/${args['data']['ticket']['id']}
);
console.log(options);
const updateResponse = await fetch(https://razorpay--produat.sandbox.my.salesforce.com/services/data/v58.0/sobjects/Tech_Support_Ticket__c/FreshDesk_Ticket_Number__c/${args['data']['ticket']['id']}
, options);
console.log(updateResponse);
const updateData = await updateResponse.json();
console.log(‘Update Response’, updateData);
} catch (error) {
console.log(‘Error updating Salesforce record’, error);
}
}
}