Skip to content

Instantly share code, notes, and snippets.

@abeledovictor
Created February 2, 2023 17:09
Show Gist options
  • Save abeledovictor/61dd0ef02aac6cea6711ae4dc1c3172a to your computer and use it in GitHub Desktop.
Save abeledovictor/61dd0ef02aac6cea6711ae4dc1c3172a to your computer and use it in GitHub Desktop.
NodeJS Subscribe to Drip workflow example
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