1. I’m facing a challenge here while using contact Filter API with multiple dynamic queries
Server File
checkContactInfoByPhoneNumber: async function (options) {
console.log('option from checkContactInfoByPhoneNumber', options)
// options.result = 'checkContactInfoByPhoneNumber'
let phone = options.contact
// let contactId = options.contactId
let customerNumber = encodeURIComponent(phone)
let phoneNumber = JSON.stringify(customerNumber)
console.log('phone ', phoneNumber)
// let contact = options.value
let queryparam = `"phone=${phoneNumber} OR mobile=${phoneNumber}`
console.log(queryparam)
let freshdeskContact = {}
try {
console.log('1')
let data = await $request.invokeTemplate(
'checkContactInfoByPhoneNumber',
{
context: {
phoneNumber: queryparam,
}
}
)
var contactInformationPayload = {}
let { status, response } = data
console.log('server data', data.status, data.response)
let contactInfo = JSON.parse(response)
console.log('contactInfo.results.length', contactInfo.results.length)
if (contactInfo.results.length === 1) {
let info = contactInfo.results[contactInfo.results.length - 1]
let { id, email, name, mobile, phone } = info
console.log('server fInfo', info)
console.log('server fInfo-1', contactInformationPayload)
contactInformationPayload.status = status
contactInformationPayload.id = id
contactInformationPayload.email = email
contactInformationPayload.name = name
contactInformationPayload.mobile = mobile
contactInformationPayload.phone = phone
contactInformationPayload.triggeredFunction =
'checkContactInfoByPhoneNumber'
} else {
console.log('here---------')
// let [firstContactInfo] = contactInfo.results[0]
// console.log('firstContactInfo---1', firstContactInfo)
// let { id, email, name, mobile, phone } = firstContactInfo
// console.log('firstContactInfo', firstContactInfo)
// contactInformationPayload.status = status
contactInformationPayload.id = 0
// contactInformationPayload.email = email
// contactInformationPayload.name = name
contactInformationPayload.name = 'Unknown Caller'
// contactInformationPayload.mobile = mobile
// contactInformationPayload.phone = phone
// contactInformationPayload.triggeredFunction =
// 'checkContactInfoByPhoneNumber'
contactInformationPayload.mobile = phone
contactInformationPayload.phone = phone
}
freshdeskContact.response = contactInformationPayload
console.log('server fInfo-12', freshdeskContact)
renderData({
status: 200,
message: JSON.stringify(freshdeskContact),
})
} catch (error) {
// Use catch instead of .catch ()
console.log('error from checkContactInfoByPhoneNumber', error)
let response = `checkContactInfoByPhoneNumber Server Error:${error}`
renderData({ status: 400, message: response })
}
}
Requests.JSON file
"checkContactInfoByPhoneNumber": {
"schema": {
"protocol": "https",
"method": "GET",
"host": "<%= iparam.freshdesk_url %>.freshdesk.com",
"path": "/api/v2/search/contacts?query=<%= context.phoneNumber %>",
"headers": {
"Authorization": "Bearer <%= encode(iparam.freshdesk_apiKey) %>",
"Content-Type": "application/json"
}
}
}
Error response in terminal
error we faced while using this template in this attached screenshot
Note: apart from this w tried multiple other way but most of the time we get error message as
response: 'error while substituting templates.',
We also have similar request in this link for the same issue Migration Issue in (request.js) - #4 by vangakirankumarreddy