Creating a placeholder contact
The developer framework is currently in BETA
This framework is in beta. Please submit a Github issue if you encounter any problems or have a question.
In the event that no contact could be found with an associated phone number, then the client application will prompt a user to create a placeholder contact. If the user elects to create a placeholder contact, then this interface on the server will be invoked.
Endpoint
- HTTP method: POST
- HTTP endpoint:
<server base URL>/contact
Request parameters
Name | Description |
---|---|
jwtToken |
An encrypted string that includes the current user's ID and the associated CRM. |
phoneNumber |
The phone number associated with the contact that will be created. |
newContactName |
The name of the contact that will be created. |
newContactType |
The type of contact that will be created. |
Response
Name | Description |
---|---|
id |
The ID of the newly created contact in the target CRM. |
name |
The name of the newly created contact in the target CRM. |
Sample code
async function createContact({ user, authHeader, phoneNumber, newContactName, newContactType }) {
// ----------------------------------------
// ---TODO.8: Implement contact creation---
// ----------------------------------------
const postBody = {
name: newContactName,
type: newContactType,
phone_numbers: [
{
name: "Work",
number: phoneNumber,
default_number: true
}
]
}
// const contactInfoRes = await axios.post(
// `https://api.crm.com/contacts`,
// postBody,
// {
// headers: { 'Authorization': authHeader }
// }
// );
mockContact = {
id: 'testContactId',
name: newContactName,
type: newContactType,
phone: phoneNumber,
additionalInfo: {
associatedDeal: [
{
const: 'csA351',
title: 'Christmas special A351'
},
{
const: 'eA22',
title: 'Easter A22'
},
{
const: 'aC92',
title: 'Anniversary C92'
}
]
}
}
const contactInfoRes = {
data: {
id: mockContact.id,
name: mockContact.name
}
}
//--------------------------------------------------------------------------------
//---CHECK.8: In extension, try create a new contact against an unknown number ---
//--------------------------------------------------------------------------------
return {
id: contactInfoRes.id,
name: contactInfoRes.name
}
}
async function createContact({ user, authHeader, phoneNumber, newContactName }) {
const postBody = {
name: newContactName,
phone: phoneNumber
}
const createContactRes = await axios.post(
`https://${user.hostname}/v1/persons`,
postBody,
{
headers: { 'Authorization': authHeader }
});
return {
id: createContactRes.data.data.id,
name: createContactRes.data.data.name
}
}