Created
February 2, 2023 17:09
-
-
Save abeledovictor/61dd0ef02aac6cea6711ae4dc1c3172a to your computer and use it in GitHub Desktop.
NodeJS Subscribe to Drip workflow example
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 got = require('got'); | |
const subscribeToWorkflow = async ({ email, name, workflow }) => { | |
const payload = { | |
error: null, | |
success: null, | |
}; | |
const sub = { | |
email, | |
}; | |
if (name) { | |
sub.first_name = name; | |
} | |
try { | |
await got(`https://api.getdrip.com/v2/${process.env.DRIP_ACCOUNT_ID}/workflows/${workflow}/subscribers`, { | |
method: 'POST', | |
headers: { | |
'Content-Type': 'application/json', | |
authorization: `Basic ${Buffer.from(process.env.DRIP_API_KEY).toString('base64')}`, | |
}, | |
json: { | |
subscribers: [sub], | |
}, | |
}); | |
payload.error = false; | |
payload.success = true; | |
} catch (e) { | |
payload.error = e.message || true; | |
payload.success = false; | |
} | |
return payload; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment