Skip to content

findContactWithName

Searches CRM contacts by name when a phone-number lookup did not find the right contact.

Optional interface

Implement this when users should be able to manually search CRM contacts from App Connect.

Signature

async function findContactWithName({
  user,
  authHeader,
  name,
  proxyConfig
}) {
  return {
    successful: true,
    matchedContactInfo: []
  };
}

Input

Field Description
user Connected CRM user.
authHeader Prepared CRM auth header.
name User-entered search text.
proxyConfig Proxy configuration when applicable.

Return

Return the same contact shape used by findContact:

return {
  successful: true,
  matchedContactInfo: [
    {
      id: 'contact-id',
      name: 'Jane Smith',
      type: 'Contact',
      phone: '+14155550100',
      email: 'jane@example.com',
      additionalInfo: null
    }
  ],
  returnMessage: null
};

Core treats an empty list as "no contact found" and can show a default warning if you do not provide returnMessage.

Reference

const axios = require('axios');

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;