Between 8:00 - 9:00 am ET on 10/25 we need to take our site down to make updates. We recommend logging out before 8:00am ET and not using your account during this time. Thank you for your patience while we make these important updates.

Users Query Updates

SOLVED
Go to solution
Regular Participant

Users Query Updates

Hi,

First time
When i am selecting country with first name and email Id then select training radio button practitioner and click on submit button. then in constant contact shows

Yemen - Training ---- 1

second time
When i am selecting the same country with same first name and same email Id
then select Groups radio button practitioner and click on submit button, then in constant contact shows

Yemen - Training ---- 0
Yemen - Groups ---- 1

but we want

Yemen - Training ---- 1
Yemen - Groups ---- 1

My VB code is below :-

Public Sub MoveContact(ByVal listName As List(Of String))

Try
Dim _nextChunk As String
Dim myEmail As New List(Of String)()
myEmail.Add(emailAddress)
Dim myList As IList(Of Contact) = Utility.SearchContactByEmail(authenticationData, myEmail, _nextChunk)
Dim newList As New ContactOptInList()
Dim contList As New ContactList()
Dim cont As IList(Of ContactList) = GetContacts() '.Where(Function(c) c. = "Global Email List").FirstOrDefault()
Dim firstName As String
firstName = name.Split(" ")(0)
'Dim contacts As IList(Of ContactList) = GetContacts()

For Each contactList As ContactList In cont
'Dim ContactDetail As Contact = Utility.GetContactDetailsById(authenticationData, contactList.Id)
'If (ContactDetail.EmailAddress = emailAddress) Then
' Dim cl As New ContactOptInList()
' myList(0).OptInSource = ContactOptSource.ActionByContact
' cl.ContactList = New ContactList(contactList.Id)
' myList(0).ContactLists.Add(cl)
' 'myList(0).FirstName = txtName.Text
' myList(0).FirstName = firstName.Substring(0, firstName.LastIndexOf(" "))
' myList(0).LastName = name.Substring(name.LastIndexOf(" "), ((name.Length) - (name.LastIndexOf(" "))))

'End If




For Each contactlistItem As String In listName
'Dim ContactDetail As Contact = Utility.GetContactDetailsById(authenticationData, contactList.Id)
'If (ContactDetail.EmailAddress = emailAddress) Then
If contactList.Name = contactlistItem.Trim() Or contactList.Name = "Global Email List" Then
Dim cl As New ContactOptInList()
myList(0).OptInSource = ContactOptSource.ActionByContact
cl.ContactList = New ContactList(contactList.Id)
myList(0).ContactLists.Add(cl)
'myList(0).FirstName = txtName.Text
myList(0).FirstName = firstName.Split(" ")(0)
If firstName.Split(" ").Length > 0 Then
myList(0).LastName = name.Substring(name.IndexOf(" "))
End If

End If
'End If
Next
Next

'Utility.CreateNewContact(authenticationData, myList(0))
Utility.UpdateContactFullForm(authenticationData, myList(0))

Response.Redirect("../")
Catch ex As Exception

End Try
'Try
' Dim _nextChunk As String
' Dim myEmail As New List(Of String)()
' myEmail.Add(emailAddress)
' Dim myList As IList(Of Contact) = Utility.SearchContactByEmail(authenticationData, myEmail, _nextChunk)
' Dim newList As New ContactOptInList()
' Dim contList As New ContactList()
' Dim cont As IList(Of ContactList) = GetContacts()
' For Each contact As ContactList In cont
' For Each contactlistItem As String In listName
' If contact.Name = contactlistItem.Trim() Then
' Utility.GetContactDetailsById(authenticationData, contact.Id)
' newList.ContactList = New ConstantContactBO.ContactList(contact.Id)
' For Each c As Contact In myList
' c.ContactLists.Add(newList)
' ' Utility.UpdateList(contact, authenticationData)
' 'Utility.RemoveContactFromAllLists(authenticationData, contact.Id);
' Utility.UpdateContactFullForm(authenticationData, c)
' Next
' End If
' Next

' Next
' Response.Redirect("../")
'Catch ex As Exception

'End Try

End Sub

1 ACCEPTED SOLUTION

Hi,

 

The issue appears to be that you were calling the contact, but to get the lists that a contact is on, you actually have to call the contact by its ID.  Then you can update with the new lists.  I haven't quite finished the if-else statement to add the contact to one list if they were on another particular list, but here is the idea:

 

 

        Dim basicAuth = New AuthenticationData(apiKey, Username, Password) 
        Dim _nextChunk As String 'Search through contact results
        Dim emailAddress = "test@noemail.com"
        Dim myEmail As New List(Of String)()
        Dim newList As New ContactOptInList() 

        myEmail.Add(emailAddress) 
        Dim myContact As IList(Of Contact) = Utility.SearchContactByEmail(basicAuth, myEmail, _nextChunk)    
        Dim contactByID = Utility.GetContactDetailsById(basicAuth, myContact(0).Id) 
newList.ContactList = New ConstantContactBO.ContactList("1") contactByID.ContactLists.Add(newList)
'Special Condition: To add contact to training list if they were added to the General Interest list
Dim yemenTrainingList As New ContactOptInList() yemenTrainingList.ContactList = New ConstantContactBO.ContactList("4")

'Enter the list ID for the list you want the contact to be on if also on global list
If newList.ContactList.Name = "General Interest" Then contactByID.ContactLists.Add(yemenTrainingList) End If

 

I hope that helps jumpstart you!

 

Shannon W.

API Support

View solution in original post

8 REPLIES 8
Member

Hello,

 

In order to add a second list/interest attribute to an existing contact in an account, you need to submit the API request to update the contact with both the old and the new lists included in your request. Updating contacts through the API replaces current information with new information provided.

 

The behavior you're seeing is typically caused by the second request including only the new list you wish to add the contact to, which replaces the previous list. 

 

I hope this helps you get things working as you would like. Let us know if you have additional questions.

 

 

 

 

Mark Coleman
Support Engineer
Regular Participant

Can you modify my code.

 

thanks

Hi,

 

We don't typically have the resources to troubleshoot and modify developers' code, but I am taking a look at your code as time allows in my test environment, to see if we can help you out.  

 

It will take some time to troubleshoot, but I will respond here when I have more information for you.

 

Regards,

Shannon W.

API Support

Regular Participant

Actually its very urgent for us so take it on the high-priority.  we are waiting for you valuable feedback. Thanks

Regular Participant

If I understand you correctly, removing this line "' 'Utility.RemoveContactFromAllLists(authenticationD

ata, contact.Id);" at the end should do the trick.

Hi,

 

The issue appears to be that you were calling the contact, but to get the lists that a contact is on, you actually have to call the contact by its ID.  Then you can update with the new lists.  I haven't quite finished the if-else statement to add the contact to one list if they were on another particular list, but here is the idea:

 

 

        Dim basicAuth = New AuthenticationData(apiKey, Username, Password) 
        Dim _nextChunk As String 'Search through contact results
        Dim emailAddress = "test@noemail.com"
        Dim myEmail As New List(Of String)()
        Dim newList As New ContactOptInList() 

        myEmail.Add(emailAddress) 
        Dim myContact As IList(Of Contact) = Utility.SearchContactByEmail(basicAuth, myEmail, _nextChunk)    
        Dim contactByID = Utility.GetContactDetailsById(basicAuth, myContact(0).Id) 
newList.ContactList = New ConstantContactBO.ContactList("1") contactByID.ContactLists.Add(newList)
'Special Condition: To add contact to training list if they were added to the General Interest list
Dim yemenTrainingList As New ContactOptInList() yemenTrainingList.ContactList = New ConstantContactBO.ContactList("4")

'Enter the list ID for the list you want the contact to be on if also on global list
If newList.ContactList.Name = "General Interest" Then contactByID.ContactLists.Add(yemenTrainingList) End If

 

I hope that helps jumpstart you!

 

Shannon W.

API Support

View solution in original post

Regular Participant

Hi,

 

I need the solution urget

 


In First time
When i am selecting country with first name and email Id then select training radio button practitioner and click on submit button. then in constant contact email listing shows

Yemen - Training ---- 1

second time
When i am selecting the same country with same first name and same email Id
then select Groups radio button practitioner and click on submit button, then in constant contact shows

Yemen - Training ---- 0
Yemen - Groups ---- 1

but we want the result

Yemen - Training ---- 1
Yemen - Groups ---- 1

My VB code is below :-

Public Sub MoveContact(ByVal listName As List(Of String))

Try
Dim _nextChunk As String
Dim myEmail As New List(Of String)()
myEmail.Add(emailAddress)
Dim myList As IList(Of Contact) = Utility.SearchContactByEmail(authenticationData, myEmail, _nextChunk)
Dim newList As New ContactOptInList()
Dim contList As New ContactList()
Dim cont As IList(Of ContactList) = GetContacts() '.Where(Function(c) c. = "Global Email List").FirstOrDefault()
Dim firstName As String
firstName = name.Split(" ")(0)
'Dim contacts As IList(Of ContactList) = GetContacts()

For Each contactList As ContactList In cont
'Dim ContactDetail As Contact = Utility.GetContactDetailsById(authenticationData, contactList.Id)
'If (ContactDetail.EmailAddress = emailAddress) Then
' Dim cl As New ContactOptInList()
' myList(0).OptInSource = ContactOptSource.ActionByContact
' cl.ContactList = New ContactList(contactList.Id)
' myList(0).ContactLists.Add(cl)
' 'myList(0).FirstName = txtName.Text
' myList(0).FirstName = firstName.Substring(0, firstName.LastIndexOf(" "))
' myList(0).LastName = name.Substring(name.LastIndexOf(" "), ((name.Length) - (name.LastIndexOf(" "))))

'End If



For Each contactlistItem As String In listName
'Dim ContactDetail As Contact = Utility.GetContactDetailsById(authenticationData, contactList.Id)
'If (ContactDetail.EmailAddress = emailAddress) Then
If contactList.Name = contactlistItem.Trim() Or contactList.Name = "Global Email List" Then
Dim cl As New ContactOptInList()
myList(0).OptInSource = ContactOptSource.ActionByContact
cl.ContactList = New ContactList(contactList.Id)
myList(0).ContactLists.Add(cl)
'myList(0).FirstName = txtName.Text
myList(0).FirstName = firstName.Split(" ")(0)
If firstName.Split(" ").Length > 0 Then
myList(0).LastName = name.Substring(name.IndexOf(" "))
End If

End If
'End If
Next
Next

'Utility.CreateNewContact(authenticationData, myList(0))
Utility.UpdateContactFullForm(authenticationData, myList(0))

Response.Redirect("../")
Catch ex As Exception

End Try

End Sub

 

Hello,

 

We have provided the solution to your issue multiple times in this thread. Unfortunately, we do not have the resources to correct all segments of your code that are not working. We offer solutions and suggestions, and we cannot always create and repair code.

 

When updating a contact, any fields left empty will overwrite the fields in contact details. If you do not want this to happen, you must gather all current contact info, add your new information, then push the update.

Nick Galbraith
Support Engineer
Developer Portal

View API documentation, code samples, get your API key.

Visit Page