Skip to content

Commit

Permalink
feat: Added crm tracking (#581)
Browse files Browse the repository at this point in the history
  • Loading branch information
chavda-bhavik authored Jun 2, 2024
2 parents 1c65df5 + a71f3d0 commit 9dcbaf9
Showing 1 changed file with 30 additions and 7 deletions.
37 changes: 30 additions & 7 deletions apps/api/src/app/shared/services/lead.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,24 +36,47 @@ export class LeadService {
public async createLead(data: ILeadInformation): Promise<any> {
const accessToken = await this.getAccessToken();
if (accessToken) {
// eslint-disable-next-line max-len
const url = `https://marketingautomation.zoho.com/api/v1/json/listsubscribe?listkey=${
// Add Lead to marketing automation
const maUrl = `https://marketingautomation.zoho.com/api/v1/json/listsubscribe?listkey=${
process.env.LEAD_LIST_KEY
}&leadinfo=${JSON.stringify(data)}&topic_id=${process.env.LEAD_TOPIC_ID}`;
if (this.log) console.log(url);
if (this.log) console.log(maUrl);

const response = await axios.post(
url,
const maResponse = await axios.post(
maUrl,
{},
{
headers: {
Authorization: `Zoho-oauthtoken ${accessToken}`,
},
}
);
if (this.log) console.log('Lead created', response.data);
if (this.log) console.log('Lead created', maResponse.data);

// Add Lead to Zoho CRM
const crmUrl = `https://www.zohoapis.com/crm/v6/Leads`;
if (this.log) console.log(crmUrl);

const crmResponse = await axios.post(
crmUrl,
{
data: [
{
Last_Name: data['Last Name'],
First_Name: data['First Name'],
Email: data['Lead Email'],
},
],
},
{
headers: {
Authorization: `Zoho-oauthtoken ${accessToken}`,
},
}
);
if (this.log) console.log('Lead created', crmResponse.data);

return response.data;
return crmResponse.data;
}
}
}

0 comments on commit 9dcbaf9

Please sign in to comment.