mirror of
https://github.com/oceanprotocol/webtasks
synced 2025-01-07 20:35:30 +01:00
Data updation to zoho
This commit is contained in:
parent
150c9bd9ba
commit
d546631dc0
@ -3,9 +3,7 @@ const Webtask = require('webtask-tools')
|
|||||||
const cors = require('cors')
|
const cors = require('cors')
|
||||||
const bodyParser = require('body-parser')
|
const bodyParser = require('body-parser')
|
||||||
const request = require('request')
|
const request = require('request')
|
||||||
|
|
||||||
const server = express()
|
const server = express()
|
||||||
|
|
||||||
server.listen(4430)
|
server.listen(4430)
|
||||||
server.use(bodyParser.json())
|
server.use(bodyParser.json())
|
||||||
|
|
||||||
@ -54,19 +52,43 @@ server.get('/newsletter', (req, res) => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
server.get('/newsletter/:data', (req, res) => {
|
server.get('/newsletter/:data', (req, res) => {
|
||||||
const { ZOHO_CAMPAIGNS_TOKEN, ZOHO_CAMPAIGNS_LIST_KEY } = req.webtaskContext.secrets
|
const {
|
||||||
|
ZOHO_CAMPAIGNS_TOKEN,
|
||||||
|
ZOHO_CAMPAIGNS_LIST_KEY
|
||||||
|
} = req.webtaskContext.secrets
|
||||||
const { data } = req.params
|
const { data } = req.params
|
||||||
|
console.log(ZOHO_CAMPAIGNS_TOKEN)
|
||||||
|
|
||||||
const options = {
|
const options = {
|
||||||
url: `${apiUrlZohoCampaigns}json/listsubscribe?authtoken=${ZOHO_CAMPAIGNS_TOKEN}&scope=CampaignsAPI&resfmt=JSON&listkey=${ZOHO_CAMPAIGNS_LIST_KEY}&contactinfo=${decodeURIComponent(data)}`
|
url: `${apiUrlZohoCampaigns}json/listsubscribe?ZOHO_CRM_TOKEN=${ZOHO_CAMPAIGNS_TOKEN}&scope=CampaignsAPI&resfmt=JSON&listkey=${ZOHO_CAMPAIGNS_LIST_KEY}&contactinfo=${decodeURIComponent(
|
||||||
|
data
|
||||||
|
)}`
|
||||||
}
|
}
|
||||||
sendRequest(options, res)
|
sendRequest(options, res)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
server.get('/:Contacts/search', (req, res) => {
|
||||||
|
const { ZOHO_CRM_TOKEN } = req.webtaskContext.secrets.ZOHO_CRM_TOKEN
|
||||||
|
let { email } = req.query.email
|
||||||
|
let urls = `${apiUrlZohoCRM}Contacts/search?email=${email}`
|
||||||
|
console.log('Auth - ' + ZOHO_CRM_TOKEN)
|
||||||
|
const options = {
|
||||||
|
url: urls,
|
||||||
|
method: 'GET',
|
||||||
|
headers: {
|
||||||
|
Authorization: ZOHO_CRM_TOKEN,
|
||||||
|
'content-type': 'application/json'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
sendRequest(options, res)
|
||||||
|
})
|
||||||
|
//
|
||||||
//
|
//
|
||||||
// Create a new lead via Zoho CRM API
|
// Create a new lead via Zoho CRM API
|
||||||
// https://www.zoho.com/crm/help/api/v2/#create-specify-records
|
// https://www.zoho.com/crm/help/api/v2/#create-specify-records
|
||||||
//
|
//
|
||||||
|
/*
|
||||||
server.get('/crm', (req, res) => {
|
server.get('/crm', (req, res) => {
|
||||||
res.send(`<h3>Please pass your data in the following format</h3>
|
res.send(`<h3>Please pass your data in the following format</h3>
|
||||||
- <code>/crm/{First Name:First Name, Last Name:Last Name,Contact Email:info@oceanprotocol.com}</code>`)
|
- <code>/crm/{First Name:First Name, Last Name:Last Name,Contact Email:info@oceanprotocol.com}</code>`)
|
||||||
@ -78,11 +100,41 @@ server.get('/crm/:data', (req, res) => {
|
|||||||
|
|
||||||
const options = {
|
const options = {
|
||||||
url: `${apiUrlZohoCRM}Leads`,
|
url: `${apiUrlZohoCRM}Leads`,
|
||||||
headers: { 'Authorization': `Zoho-oauthtoken ${ZOHO_CRM_TOKEN}` },
|
headers: { 'Authorization': `Zoho-oZOHO_CRM_TOKEN ${ZOHO_CRM_TOKEN}` },
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
formData: data
|
formData: data
|
||||||
}
|
}
|
||||||
sendRequest(options, res)
|
sendRequest(options, res)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
server.post('/:Contacts', (req, res) => {
|
||||||
|
const { ZOHO_CRM_TOKEN } = req.webtaskContext.secrets.ZOHO_CRM_TOKEN
|
||||||
|
const options = {
|
||||||
|
url: `${apiUrlZohoCRM}Contacts`,
|
||||||
|
method: 'POST',
|
||||||
|
headers: {
|
||||||
|
Authorization: ZOHO_CRM_TOKEN,
|
||||||
|
'content-type': 'application/json'
|
||||||
|
},
|
||||||
|
body: JSON.stringify(req.body)
|
||||||
|
}
|
||||||
|
sendRequest(options, res)
|
||||||
|
})
|
||||||
|
server.put('/:Contacts', (req, res) => {
|
||||||
|
const { ZOHO_CRM_TOKEN } = req.webtaskContext.secrets.ZOHO_CRM_TOKEN
|
||||||
|
// const { ZOHO_CAMPAIGNS_TOKEN, ZOHO_CAMPAIGNS_LIST_KEY } = req.webtaskContext.secrets
|
||||||
|
// console.log(process.env.API_ZOHO_CRM_SCRT_KEY)
|
||||||
|
const options = {
|
||||||
|
url: `${apiUrlZohoCRM}Contacts`,
|
||||||
|
method: 'PUT',
|
||||||
|
headers: {
|
||||||
|
Authorization: ZOHO_CRM_TOKEN,
|
||||||
|
'content-type': 'application/json'
|
||||||
|
},
|
||||||
|
body: JSON.stringify(req.body)
|
||||||
|
}
|
||||||
|
sendRequest(options, res)
|
||||||
|
})
|
||||||
module.exports = Webtask.fromExpress(server)
|
module.exports = Webtask.fromExpress(server)
|
||||||
|
Loading…
Reference in New Issue
Block a user