findContactWithName
Optional interface
If this interface is implemented, "Search contacts" (with name) would be provided as an option in contact matching.
It is not uncommon that when logging a call, a contact cannot be found using the findContact interface which attempts to lookup a contact into the target CRM via a phone number. Sometimes however, a contact cannot be found, but is in fact known to be in the CRM. This is when this interface comes into play.
When a contact cannot be found, users are given the option to search the CRM for a contact by name. This allows users to associate calls with contacts in a more manual fashion when a contact is not found via a phone number.
This interface is called to facilitate that search process.
Request parameters
| Parameter | Description |
|---|---|
user |
An object describing the Chrome extension user associated with the action that triggered this interface. |
authHeader |
The HTTP Authorization header to be transmitted with the API request to the target CRM. |
name |
The text entered by the user that should be searched for within the CRM. |
Return value(s)
This interface returns a single object. That object describes the contacts that were found. It has following properties:
| Parameter | Description |
|---|---|
successful |
True or false is a contact was found or not. |
matchedContactInfo |
An array of objects containing id, name and optionally additionalInfo and isNewContact. |
Example
{
successful: true,
matchedContactInfo:[
{
id: 'contact id',
name: 'John Doe',
phone: '(123) 456-7890',
type: 'Lead',
additionalInfo: null,
isNewContact: false
}
]
}
Reference
async function findContactWithName({ user, authHeader, name }) {
const matchedContactInfo = [];
//--------------------------------------
//--- TODO: Add CRM API call here ------
//--------------------------------------
// const personInfo = await axios.get(`https://${user.hostname}/api/v4/contacts.json?type=Person&query=${name}&fields=id,name,title,company,primary_phone_number`, {
// headers: { 'Authorization': authHeader }
// });
// const matchedContactInfo = personInfo.data.filter(contact => contact.name.includes(name)).map(contact => {
// return {
// id: contact.id,
// name: contact.name,
// type: contact.type,
// phone: contact.primary_phone_number
// }
// });
return {
successful: true,
matchedContactInfo
}
}
module.exports = findContactWithName;
async function findContactWithName({ user, authHeader, name }) {
let extraDataTracking = {};
const personInfo = await axios.get(
`https://${user.hostname}/api/v2/persons/search?term=${name}&fields=name`,
{
headers: { 'Authorization': authHeader }
});
extraDataTracking = {
ratelimitRemaining: personInfo.headers['x-ratelimit-remaining'],
ratelimitAmount: personInfo.headers['x-ratelimit-limit'],
ratelimitReset: personInfo.headers['x-ratelimit-reset']
};
const matchedContactInfo = [];
for (const person of personInfo.data.data.items) {
// console.log({ Item: person.item })
const dealsResponse = await axios.get(
`https://${user.hostname}/api/v2/deals?person_id=${person.item.id}&&status=open`,
{
headers: { 'Authorization': authHeader }
});
extraDataTracking = {
ratelimitRemaining: dealsResponse.headers['x-ratelimit-remaining'],
ratelimitAmount: dealsResponse.headers['x-ratelimit-limit'],
ratelimitReset: dealsResponse.headers['x-ratelimit-reset']
};
const relatedDeals = dealsResponse.data.data ?
dealsResponse.data.data.map(d => { return { const: d.id, title: d.title } })
: null;
let leadsResponse = null;
try {
leadsResponse = await axios.get(
`https://${user.hostname}/v1/leads?person_id=${person.item.id}`,
{
headers: { 'Authorization': authHeader }
});
extraDataTracking = {
ratelimitRemaining: leadsResponse.headers['x-ratelimit-remaining'],
ratelimitAmount: leadsResponse.headers['x-ratelimit-limit'],
ratelimitReset: leadsResponse.headers['x-ratelimit-reset']
};
}
catch (e) { leadsResponse = null; }
const relatedLeads = leadsResponse?.data?.data ?
leadsResponse.data.data.map(l => { return { const: l.id, title: l.title } })
: null;
matchedContactInfo.push(formatContact({
person: person.item,
relatedDeals,
relatedLeads
}));
}
return {
successful: true,
matchedContactInfo,
extraDataTracking
};
}