mirror of
https://github.com/oceanprotocol/webtasks
synced 2025-01-06 20:05:40 +01:00
prototype CRM endpoint
This commit is contained in:
parent
580471f003
commit
230c8ccf73
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,3 +1,4 @@
|
|||||||
node_modules
|
node_modules
|
||||||
package-lock.json
|
package-lock.json
|
||||||
yarn.lock
|
yarn.lock
|
||||||
|
.env
|
||||||
|
@ -10,7 +10,6 @@
|
|||||||
"body-parser": "^1.18.3",
|
"body-parser": "^1.18.3",
|
||||||
"cors": "^2.8.4",
|
"cors": "^2.8.4",
|
||||||
"express": "^4.16.3",
|
"express": "^4.16.3",
|
||||||
"http-proxy-middleware": "^0.18.0",
|
|
||||||
"request": "^2.85.0",
|
"request": "^2.85.0",
|
||||||
"webtask-tools": "^3.2.0"
|
"webtask-tools": "^3.2.0"
|
||||||
},
|
},
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
const express = require('express')
|
const express = require('express')
|
||||||
const Webtask = require('webtask-tools')
|
const Webtask = require('webtask-tools')
|
||||||
const cors = require('cors')
|
const cors = require('cors')
|
||||||
const proxy = require('http-proxy-middleware')
|
|
||||||
const bodyParser = require('body-parser')
|
const bodyParser = require('body-parser')
|
||||||
const request = require('request')
|
const request = require('request')
|
||||||
|
|
||||||
@ -11,6 +10,9 @@ server.use(cors())
|
|||||||
server.listen(4430)
|
server.listen(4430)
|
||||||
server.use(bodyParser.json())
|
server.use(bodyParser.json())
|
||||||
|
|
||||||
|
//
|
||||||
|
// Zoho API urls
|
||||||
|
//
|
||||||
const apiUrlZohoCampaigns = 'https://campaigns.zoho.com/api/'
|
const apiUrlZohoCampaigns = 'https://campaigns.zoho.com/api/'
|
||||||
const apiUrlZohoCRM = 'https://www.zohoapis.com/crm/v2/'
|
const apiUrlZohoCRM = 'https://www.zohoapis.com/crm/v2/'
|
||||||
|
|
||||||
@ -26,7 +28,7 @@ server.get('/newsletter/:data', (req, res) => {
|
|||||||
url: `${apiUrlZohoCampaigns}json/listsubscribe?authtoken=${ZOHO_CAMPAIGNS_TOKEN}&scope=CampaignsAPI&resfmt=JSON&listkey=${ZOHO_CAMPAIGNS_LIST_KEY}&contactinfo=${data}` // eslint-disable-line max-len
|
url: `${apiUrlZohoCampaigns}json/listsubscribe?authtoken=${ZOHO_CAMPAIGNS_TOKEN}&scope=CampaignsAPI&resfmt=JSON&listkey=${ZOHO_CAMPAIGNS_LIST_KEY}&contactinfo=${data}` // eslint-disable-line max-len
|
||||||
}
|
}
|
||||||
|
|
||||||
request(options, (error, response, body) => { // eslint-disable-line consistent-return
|
request(options, (error, response, body) => {
|
||||||
if (error) {
|
if (error) {
|
||||||
res.send(error)
|
res.send(error)
|
||||||
}
|
}
|
||||||
@ -36,19 +38,29 @@ server.get('/newsletter/:data', (req, res) => {
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
const onProxyReqZohoCRM = (proxyReq, req) => {
|
//
|
||||||
|
// Create a new lead via Zoho CRM API
|
||||||
|
// https://www.zoho.com/crm/help/api/v2/#create-specify-records
|
||||||
|
//
|
||||||
|
server.get('/crm/:data', (req, res) => {
|
||||||
const { ZOHO_CRM_TOKEN } = req.webtaskContext.secrets
|
const { ZOHO_CRM_TOKEN } = req.webtaskContext.secrets
|
||||||
|
const { data } = req.params
|
||||||
|
|
||||||
proxyReq.setHeader('Authorization', `Zoho-oauthtoken ${ZOHO_CRM_TOKEN}`)
|
const options = {
|
||||||
}
|
url: `${apiUrlZohoCRM}Leads`, // eslint-disable-line max-len
|
||||||
|
headers: { 'Authorization': `Zoho-oauthtoken ${ZOHO_CRM_TOKEN}` },
|
||||||
|
method: 'POST',
|
||||||
|
formData: data
|
||||||
|
}
|
||||||
|
|
||||||
const configZohoCRM = {
|
request(options, (error, response, body) => {
|
||||||
target: apiUrlZohoCRM,
|
if (error) {
|
||||||
pathRewrite: { '^/zoho/crm/': '/' },
|
res.send(error)
|
||||||
changeOrigin: true,
|
}
|
||||||
onProxyReq: onProxyReqZohoCRM
|
|
||||||
}
|
|
||||||
|
|
||||||
server.use(proxy('/zoho/crm/**', configZohoCRM))
|
res.send(body)
|
||||||
|
res.sendStatus(200)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
module.exports = Webtask.fromExpress(server)
|
module.exports = Webtask.fromExpress(server)
|
||||||
|
Loading…
Reference in New Issue
Block a user