Created
September 10, 2017 02:00
-
-
Save jeznag/18aa6e0c8b8c1c89ac539962b6dce4b0 to your computer and use it in GitHub Desktop.
Uploading files to Zoho CRM using Node.js
This file contains 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 request = require('request'); | |
function attachFileToCRM(crmContactID) { | |
const urlForFileToAttach = 'http://example.com/blah.pdf'; | |
const CRM_UPLOAD_FILES_URL = `https://crm.zoho.com/crm/private/json/Contacts/uploadFile?authtoken=${CRM_AUTH_TOKEN}&scope=crmapi&id=${crmContactID}`; | |
// You can use fs.createReadStream for local files | |
const readStream = request.get(urlForFileToAttach); | |
const formData = { | |
content: { | |
value: readStream, | |
options: { | |
filename: fileName | |
} | |
} | |
}; | |
console.log('Uploading PDF for', subscriptionID); | |
request.post({ url: CRM_UPLOAD_FILES_URL, formData: formData }, (err, httpResponse, body) => { | |
if (err) { | |
return console.error('upload failed:', err); | |
} | |
console.log('Upload successful! Server responded with:', body); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Amazing. Thank you.