Skip to content

Commit

Permalink
feat: add user to master list on AC
Browse files Browse the repository at this point in the history
  • Loading branch information
nomadbitcoin committed Nov 13, 2024
1 parent c2fc163 commit 1fd2e0e
Showing 1 changed file with 22 additions and 3 deletions.
25 changes: 22 additions & 3 deletions functions/active_campaign/active_campaign.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,23 @@ async function makeRequest(endpoint, method = 'GET', body = null) {
return response.json()
}

async function addContactToList(contactId, listId) {
try {
const response = await makeRequest('/contactLists', 'POST', {
contactList: {
list: listId,
contact: contactId,
status: 1,
},
})
console.log(`Contact added to list ${listId} successfully`)
return response
} catch (error) {
console.error(`Error adding contact to list ${listId}:`, error)
throw error
}
}

exports.createActiveCampaignUser = async function (user) {
try {
// Create or update contact
Expand All @@ -41,10 +58,12 @@ exports.createActiveCampaignUser = async function (user) {
},
})

console.log('User added to ActiveCampaign successfully')
await addContactToList(contact.id, 1) // Add to master list

console.log('User added to ActiveCampaign and lists successfully')
return contact
} catch (error) {
console.error('Error creating user in ActiveCampaign:', error)
console.error('Error in ActiveCampaign operations:', error)
throw error
}
}
Expand All @@ -65,7 +84,7 @@ exports.fetchUSer = async function () {
exports.fetchCustomFieldMeta = async function () {
console.log('Fetching custom field metadata from ActiveCampaign...')
try {
const endpoint = '/fields'
const endpoint = '/lists'
const params = '?limit=100'
const response = await makeRequest(endpoint + params)
console.log('Custom field metadata retrieved successfully')
Expand Down

0 comments on commit 1fd2e0e

Please sign in to comment.