The Community is hosting an End of Summer sweepstakes! Participants must complete tasks to earn tickets that will enter them with a chance to win a free year of Constant Contact and other great prizes!*
*No Purchase Necessary. For Official Rules, visit here. Constant Contact’s End of Summer 2020 Sweepstakes ends on October, 20, 2020 at 11:50 PM EST.

New custom fields not added to existing contacts via bulk API

Highlighted
Occasional Contributor

New custom fields not added to existing contacts via bulk API

Hi, I am trying to update custom fields for contacts between sends.  If I add a contact via the bulk API, send a message, and then add the user again later with additional custom fields (in hopes of updating the user), those new custom fields aren't added.

 

 

Here's a sample test script which adds a user via the bulk API, prints its custom fields, adds it again with a new custom field, and prints its custom fields again.  After "uploading file 2", it should show an additional line, CustomField2 = field2, but does not.

 

 

$ python test/contacttest.py
uploading file 1
CustomField1 = field1
uploading file 2
CustomField1 = field1
 
 
$ cat test/conttacttest.py
#!/usr/bin/env python
 
import requests
import json
import sys
import time
 
api_key='...'
access_token='...'
me='my@email.com'
 
def upload(list_id, contents):
                      params={'api_key': api_key, 'access_token': access_token},
                      data={'lists': [list_id], 'file_name': 'upload.csv'},
                      files={'data': contents})
 
    upload_id = r.json()['id']
 
    for i in xrange(10):
        r = requests.get('https://api.constantcontact.com/v2/activities/%s' % upload_id,
                         params={'api_key': api_key, 'access_token': access_token})
 
        if r.json()['status'].lower() == 'complete':
            return True
        else:
            time.sleep(10)
    return False
 
 
if __name__ == '__main__':
    r = requests.post('https://api.constantcontact.com/v2/lists',
                      params={'api_key': api_key, 'access_token': access_token},
                      data=json.dumps({ 'name': 'test list %s' % int(time.time()), 'status': 'ACTIVE' }))
 
    if r.status_code != 201:
        print r.text
        sys.exit(1)
 
    list_id = r.json()['id']
 
 
    print 'uploading file 1'
 
    file1 = '''
Email,Custom Field 1
%s,field1
    ''' % me
 
    t = upload(list_id, file1)
    if not t:
        print 'problem uploading'
        sys.exit(1)
 
 
                     params={'api_key': api_key, 'access_token': access_token, 'email': me})
 
    if r.status_code != 200:
        print r.status_code
        print r.text
        sys.exit(1)
 
    for record in r.json()['results']:
        if me in [i['email_address'] for i in record.get('email_addresses', [])]:
            for field in sorted(record['custom_fields'], key=lambda v: v['name']):
                print '%s = %s' % (field['name'], field['value'])
 
 
    print 'uploading file 2'
 
    file2 = '''
Email,Custom Field 1,Custom Field 2
%s,field1,field2
    ''' % me
 
    t = upload(list_id, file2)
    if not t:
        print 'problem uploading'
        sys.exit(1)
 
 
                     params={'api_key': api_key, 'access_token': access_token, 'email': me})
 
    if r.status_code != 200:
        print r.status_code
        print r.text
        sys.exit(1)
 
    for record in r.json()['results']:
        if me in [i['email_address'] for i in record.get('email_addresses', [])]:
            for field in sorted(record['custom_fields'], key=lambda v: v['name']):
                print '%s = %s' % (field['name'], field['value'])
3 REPLIES 3
Highlighted
Honored Contributor

Re: New custom fields not added to existing contacts via bulk API

Hello,

 

After looking over your code and your description of what you are seeing, it looks and sounds like you are experiencing a new issue that we are tracking right now. The easiest way to verify this is for you to email us with some additional details at webservices@constantcontact.com so that I can verify. The information that we would need is:

- Constant Contact Username

- Example Email Address used to test the script

 

Please feel free to include any questions that you may have as well.

 

Best Regards,

Elijah G.
API Support Engineer
Highlighted
Consulting & Training

Re: New custom fields not added to existing contacts via bulk API

Any updates on this?  I have a client that is facing a major delay on a pretty big promotion they are running due to this issue.

 

I am assuming the issue mentioned here with the API is related to the same issue that occurs when trying to import new custom field data using the CC web interface, where existing contacts that do not already have a value assigned to that field do not import the new custom field. 

 

I was actually only looking into using the API and building a custom app simply as a workaround to the web interface import bug, but now it looks like it would not work using the API either. Can you please confirm?

 

Thanks,

Mark Mitchell

 

Highlighted
Honored Contributor

Re: New custom fields not added to existing contacts via bulk API

Hi Mark,

 

With the issue you are discussing, it will unfortunately impact an API integration as well. This is because the issue is happening within the system which processes import activities, and thus it will affect both file uploads through the UI and bulk imports from the API. The good news to be had is that we do have developers working on this issue right now, and we hope to have a fix deployed for this near the end of the month.

 

Sincerely,

Elijah G.
API Support Engineer
Developer Portal

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

Visit Page

Constant Contact 2020 End of Summer Community Sweepstakes!

The Constant Contact User Community is hosting a sweepstakes. The more you participate, the more chances you have to win! Read on to learn more...

Read More
Featured