cancel
Showing results for 
Search instead for 
Did you mean: 

Need help with managing already registered users through the API

Member

Need help with managing already registered users through the API

Hi there,

 

So I successfully integrated the API into my website, however I am having some issues with trying to update a user that is already on a current list but wants to join other lists.

 

My environment is Ruby on Rails, i use the constant contact gem which I forked here https://github.com/McPants/constant_contact to fix some issues

 

I tried to use that specific gem to do the updating as per their documentation however it is a very old gem and was hard enough to get working on just creating a new user.

 

So basically what I am doing is going to try and create a new user via the gem, then if I get an error back I will make a manual request to get the XML data for that individual and try to update the lists that they belong to.

 

This gave me problems though. I tried following these guidelines: http://community.constantcontact.com/t5/Getting-Started-with-API-s/How-I-can-add-existing-email-id-c...

 

However on the first one I ran into a problem. I was successfully able to get the data for a specific user by accessing https://api.constantcontact.com/ws/customers/winforever1/contacts?email=j3williams@gmail.com, but it will not show me the lists that the user is apart of. Has there been a change in the API that adjusts how lists are retrieved and updated for a specific user? This may be why the gem is breaking for me.

4 REPLIES 4
CTCT Employee

Re: Need help with managing already registered users through the API

Hi Jordan,

 

I will check out that gem and see if I have any luck doing a PUT to update a current contact and get back to you.  As far as the issues you were receiving with getting contact details by emailaddress and missing Lists, this was how the API was designed.  In order to get a list of lists a contact is in, you have to do a get on the collection by ID not by searching for an email address.  

 

If you would like a Ruby example, I can provide you with specifics, just let me know.  

 

Andrew Weber
Associate Product Manager for EventSpot
Member

Re: Need help with managing already registered users through the API

I think I figured it out now, thanks for the quick response!

Occasional Visitor

Re: Need help with managing already registered users through the API

Hey andrew it would be helpful if you can provide a ruby sample for fetching contacts by list_id.

Honored Contributor

Re: Need help with managing already registered users through the API

Hello,

 

In order to get all contacts that are members of a list with our Ruby SDK, you can use the following code snippet:

 

    cc = ConstantContact::Api.new('API_KEY')
    @contacts = []
    request_params = nil

    # By Uncommenting the two lines below, you can add additional parameters
    #params = { modified_since: "2014-12-02T01:43:19Z", limit: 500 }
    #request_params = '?' + ConstantContact::Util::Helpers.http_build_query(params)
    
    result = cc.get_contacts_from_list('ACCESS_TOKEN", LIST_ID, request_params)
    result.results.each { |r| @contacts << r }
    while result.next do
        result = cc.get_contacts_from_list('ACCESS_TOKEN',LIST_ID, result.next)
        result.results.each { |r| @contacts << r }
    end

The result will be all contacts that are members of the list loaded to the @contacts global array.

 

If you have any questions about this snippet, please let me know!

 

Edit: Remove 2 lines of code that accomplished nothing.

 

Sincerely, 

Elijah G.
API Support Engineer