Created
July 21, 2019 19:45
-
-
Save thebigredgeek/280c412a8c06176cce1261ebcdd9d2d1 to your computer and use it in GitHub Desktop.
Overload Lead Gen API
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const express = require('express'); | |
const helmet = require('helmet'); | |
const axios = require('axios'); | |
const bodyParser = require('body-parser') | |
const client = axios.create({ | |
baseURL: 'https://api.prosperworks.com/developer_api', | |
headers: { | |
'X-PW-AccessToken': process.env.COPPER_CRM_API_KEY, | |
'X-PW-Application': 'developer_api', | |
'X-PW-UserEmail': process.env.COPPER_CRM_USEREMAIL, | |
'Content-Type': 'application/json' | |
} | |
}) | |
const app = express(); | |
app.use(helmet()); | |
app.get('/ping', (req, res) => res.status(200).send('pong')) | |
app.post('/submit_lead', bodyParser(), async (req, res, next) => { | |
try { | |
const { name, email, companyName: company_name, title, tags } = req.body | |
console.log('creating lead in copper', JSON.stringify({ | |
name, | |
email: { | |
email, | |
category: 'work' | |
}, | |
company_name, | |
title, | |
tags, | |
date_created: Date.now() | |
})) | |
await client.post('/v1/leads', { | |
name, | |
email: { | |
email, | |
category: 'work' | |
}, | |
company_name, | |
title, | |
tags, | |
date_created: Date.now() | |
}) | |
console.log('lead created in copper') | |
return res.status(201).send({ | |
success: true | |
}) | |
} catch (err) { | |
console.log('error creating lead in copper') | |
console.error(err) | |
next(err) | |
} | |
}) | |
module.exports = app; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment