[Ruby] ContanstContact API

Participant

[Ruby] ContanstContact API

Hi all, I'm using constantcontact ruby sdk. I'm got an error to call get_lists 

NoMethodError: undefined method `created_date=' for #<ConstantContact::Components::ContactList:0x937e37c>. How to fix it, I have a question about bulk import contacts(I need import more than 50 contacts everytime i press an button). How to solve it.

 update: RestClient::BadRequest: 400 Bad Request when insert new contact. Here is the code to add contact

 

contact = { 'first_name'=>"a",'last_name' => "b",'middle_name' => "c"}
email = {'email_address' => "a@abc.com"}
address = { 'line1' => "line1",'line2' => "",'line3' => "",'city' => "",'state_code' => "",'country_code' => "",'postal_code' => "",'sub_postal_code' => ""}
contact['email_addresses'] =[]
contact['addresses'] = []
contact['lists']= []
contact['email_addresses'] << email
contact['addresses'] << address
contact['lists']<< {"id" =>1}
new_contact = ConstantContact::Components::Contact.create(contact)
cc.add_contact("8f522ea9-bd25-479e-94f2-33ddbda4d064", new_contact)

 

Thanks

6 REPLIES 6
Employee

Hi,

 

Have you tried using the contact example code found here?  It makes a call to get lists and then assigns selected lists to the contact.  I would recommend copying the example code there and seeing if you can get that to work, then modify from there to make your own example.  Let me know if you have issues getting the example file working.

 

If you are updating that many contacts at once, I would strongly encourage the use of the create_add_contacts_activity service to add contacts in bulk, which will be much less data intensive and will require fewer http calls.

 

Best Regards,

Shannon W.

API Support Specialist

I'm using CC ruby gem v1, I use bulk import and get error 400,  please help me.

Code:

ConstantContact::Base.user = constant_user
ConstantContact::Base.api_key = constant_api_key
ConstantContact::Base.password = constant_pass
existed_list = ConstantContact::List.find_by_name("test")
@contacts = []
3.times do |n|
@contacts << ConstantContact::Contact.new(:first_name => "Fred#{n}",:last_name => "Test#{n}",:email_address => "email#{n}@gmail.com")
end
a = ConstantContact::Activity.new(:activity_type=>"SV_ADD")
a.contacts=@contacts
a.lists=[existed_list]
a.save

Hi,

 

I didn't realize you were using a V1 ruby wrapper.  We didn't write a ruby wrapper that uses our V1 API, so the library would have been written and supported outside of Constant Contact.

 

We can help you troubleshoot the output of the code.  If you post the payload (XML) that is sent over to us with any personal details redacted, we can likely tell you what is wrong with it.  It should meet the specifications listed on this page for the V1 API.

 

I do want to mention that it would be better to build on our V2 API, since the V1 API will be deprecated in the future.  We don't have a firm date for that yet, but it will likely be in about a year.

 

Best Regards,

Shannon W.

API Support Specialist

Not sure what the resolution was for the creator of the thread, but here's the issue I've had with the same gem.

 

Firstly, the Ruby SDK linked, although it is the CC API V2 gem, is the 1st version of the 'constantcontact' gem (ConstantContact::SDK::VERSION = "1.0.0").  

 

It looks to be fixed in the development branch on github.  It just needs to be merged into master and then published.

 

I too was getting the same error (NoMethodError 'created_date=').  I didn't see anything in the code to handle it so I went ahead and wrote a quick stub module:

 

module ConstantContact
	module Components
		class ContactList
			def created_date= date 
				ap date
			end
			def modified_date= date 
				ap date
			end
		end
	end
end

 

After adding this stub, the error went away, I properly received my lists, and I had the following in my servers stdout:

 

"2013-06-09T22:01:11.868Z"
"2013-06-09T22:01:11.935Z"

 

So, if you don't need the dates you can probably use the stub.  Otherwise poke the Ruby SDK maintainer?

Hi,

 

Thanks for helping to clarify!  I just merged an outstanding pull request to the master, and the development and master branches are now up to date (the same).  The ruby-sdk library that is maintained by us is here, for reference.

 

Best Regards,

Shannon W.

API Support Specialist

After few days, i had integrated with v1 api. It's running well.  I'm using rails 3.2.11. Now start to use v2 api. Thanks for new update.

Developer Portal

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

Visit Page