Playing with a simple test to write or update a record from a web form.
I get a 401 error when trying to write or update a contact record, but a few lines above it, I was able to use the same cc. instance to query the database to decide to update or add new. hmmm....
response = cc.get_contact_by_email(@email['email_address']) rescue 'Resource not found' contact = ConstantContact::Components::Contact.create(@contact) puts "Just created contact data structure #{contact.to_yaml}" if response && response.respond_to?(:results) && !response.results.empty? puts "trying to update record" contact.id = response.results.first.id.to_s puts "With ID assigned #{contact.to_yaml}" cc.update_contact(contact) else puts "trying to write record" puts contact.email_addresses cc.add_contact(contact) end
First line of the snippet works as I can see it make the subsequent decision to add or update.
I've got 2 yams outputs of the structure. One I created, the other with the added record id proving I communicated with the server and found a match. Do I have API write permissions with a CT trial account? I'm able to read stuff all day long, never write.
Just created contact data structure --- !ruby/object:ConstantContact::Components::Contact first_name: JAmes last_name: last name home_phone: phone email_addresses: - !ruby/object:ConstantContact::Components::EmailAddress email_address: james.hughes@microchip.com addresses: - !ruby/object:ConstantContact::Components::Address line1: line1 line2: line2 line3: line3 city: city state_code: '' postal_code: postal code sub_postal_code: sub postal code country_code: '' lists: - !ruby/object:ConstantContact::Components::ContactList id: '1547811862' - !ruby/object:ConstantContact::Components::ContactList id: '1224370900' trying to update record With ID assigned --- !ruby/object:ConstantContact::Components::Contact first_name: JAmes last_name: last name home_phone: phone email_addresses: - !ruby/object:ConstantContact::Components::EmailAddress email_address: james.hughes@microchip.com addresses: - !ruby/object:ConstantContact::Components::Address line1: line1 line2: line2 line3: line3 city: city state_code: '' postal_code: postal code sub_postal_code: sub postal code country_code: '' lists: - !ruby/object:ConstantContact::Components::ContactList id: '1547811862' - !ruby/object:ConstantContact::Components::ContactList id: '1224370900' id: '1136820859' Completed 401 Unauthorized in 775ms (ActiveRecord: 0.0ms)
Hi @JamesH3676,
We have reached out to you as a case from webservices@constantcontact.com due to requesting some additional information that should remain private. Please look for our email.
I did write back, but have not heard back. I'd like to start out by verifying write privileges with API tester, before sending API key to you privately.
Can you send me a bare-minimum JSON string for trying to write a contact to the database so I can verify write via API tester? I will substitute one of my list-ids. If I can read and don't have write restrictions, then maybe something is wrong with my formation of the JSON, I don't know.
Hi @JamesH3676,
This is the bare minimum that you need to submit in a POST to create a new contact. This will work with our API tester page located at https://constantcontact.mashery.com/io-docs. Make sure to replace the list ID with a valid number from your account.
{ "lists": [ { "id": "1" } ], "email_addresses": [ { "email_address": "username1@example.com" } ], }
OK,
Here's my lists I retrieve in API tester...
But I'm getting a 400 - bad request when I try to write a contact with the example you provided (with list id changed to a valid list_id I have).
Next steps? If you need the API key, I'll be happy to email it.
Hi @JamesH3676,
For some reason your images either did not attach. I would suggest we take this private so you can provide your API key and the Constant Contact username you are submitting the data to; please email us at webservices@constantcontact.com with this information.
The holidays have come and gone. For many seasonal businesses, this means the rush of shoppers has decreased as well. Instead of turning off the lights and waiting for spring, make your email marketi...
See Article