cancel
Showing results for 
Search instead for 
Did you mean: 
Constant Contact wants to help you succeed! We’re celebrating our professional service programs on the Constant Contact Community this month and you have a chance to try one of the services for free! Learn more.

Using Java API to update contacts

Occasional Participant

Using Java API to update contacts

I am new to Constant Contact API. I am using Java API to try to read and update/add contacts. I am able to get existing contact without any issue. However, when I tried to update existing contact or add new contact I always get exceptions. Can you please let me know why this is happeneing? What esle do I need to do first in order to update or add new contacts? Thanks

 

 

com.constantcontact.exceptions.service.ConstantContactServiceException: com.constantcontact.exceptions.service.ConstantContactServiceException: Response came with errors from WebService. Please see error info.
    at com.constantcontact.services.contacts.ContactService.updateContact(ContactService.java:369)
    at AceeeSync.main(AceeeSync.java:40)
Caused by: com.constantcontact.exceptions.service.ConstantContactServiceException: Response came with errors from WebService. Please see error info.
    at com.constantcontact.util.ConstantContactExceptionFactory.createServiceException(ConstantContactExceptionFactory.java:13)
    at com.constantcontact.services.contacts.ContactService.updateContact(ContactService.java:366)
    ... 1 more

5 REPLIES 5
Occasional Participant

Re: Using Java API to update contacts

can someone from Constant Contact please help me with this?

 

Here are the simple code I wrote:

 

.....................

        ContactService cs = new ContactService(token,api);
        
        Contact c = new Contact();
      
        try{

            c =cs.getContact("1");
     
            System.out.println(c);
           
            c.setCellPhone("xxxxxxxxxx");
            c = cs.updateContact(c, true);     
            System.out.println(c);
        }

        catch(ConstantContactServiceException ccse) {
            ccse.printStackTrace();
            
        }

Honored Contributor

Re: Using Java API to update contacts

Hello,

 

The quickest way to get additional information is to catch the exception and get the actual error message. The easiest way to do that would be to implement a try/catch block in a format similar to this:

        try {
            // Constant Contact service calls here
        }
        catch (ConstantContactServiceException e)
        {
                ConstantContactServiceException c = (ConstantContactServiceException)e.getCause();
                for (Iterator<RawApiRequestError> i = c.getErrorInfo().iterator(); i.hasNext(); ) {
                    RawApiRequestError item = i.next();
                    System.out.println(item.getErrorKey() + " : " + item.getErrorMessage());
                }
                e.printStackTrace();
        }

As a side-note, it's possibl that some required field is missing when you're attempting to add/update contacts. If you are comfortable with it, I would be happy to review any code that you have which builds the contact data to see if there is anything that can be quickly addressed. You can also review what fields are required for create a contact here: http://developer.constantcontact.com/docs/contacts-api/contacts-collection.html?method=POST

 

If you have any questions or issues, please let me know!

 

Sincerely,

 

Elijah G.
API Support Engineer
Honored Contributor

Re: Using Java API to update contacts

Hello,

 

Since you replied with some of the info I was looking for while I was typing up my reply, another very real possibility is that your account may not have a contact with an ID of "1". While some older Constant Contact accounts may still have a contact with the ID of 1, for new accounts we no longer start contacts at ID 1 and that may be the source of your problem. If you are trying to find a specific contact, I would suggest using the getContactByEmail method of the ContactService class.

 

Please let me know if you have any questions!

 

Sincerely,

Elijah G.
API Support Engineer
Occasional Participant

Re: Using Java API to update contacts

HI: thanks very much for your help. I only used "1" in the code I posted here but I used a real contact ID. I put in the code you suggested to catch more error messages and this is what I got below. I am not very clear regarding what is "ACTION_BY_VISITOR" as I did not use it in my code. Can you please elaborate? Also, how can I get the list_ids information? Thanks very much for your help.

 

 

 

contact.action_by_visitor.invalid : You must provide valid list_ids when using 'ACTION_BY_VISITOR'.
url : https://api.constantcontact.com/v2/contacts/119035?action_by=ACTION_BY_VISITOR
com.constantcontact.exceptions.service.ConstantContactServiceException: com.constantcontact.exceptions.service.ConstantContactServiceException: Response came with errors from WebService. Please see error info.
    at com.constantcontact.services.contacts.ContactService.updateContact(ContactService.java:369)
    at AceeeSync.main(AceeeSync.java:44)
Caused by: com.constantcontact.exceptions.service.ConstantContactServiceException: Response came with errors from WebService. Please see error info.
    at com.constantcontact.util.ConstantContactExceptionFactory.createServiceException(ConstantContactExceptionFactory.java:13)
    at com.constantcontact.services.contacts.ContactService.updateContact(ContactService.java:366)
    ... 1 more

Honored Contributor

Re: Using Java API to update contacts

Hello,

 

Whenever you create or update a contact, there is an action_by parameter that is passed to our API. for the methods in our Java SDK, those are handled as a true/false parameter on the method call.

 

For example, the following code uses action_by_visitor(true):

cs.updateContact(c, true)

To break is down very simply, here is what the action_by parameter indicates:

  • ACTION_BY_VISITOR - The action was initiated by the contact being changed. The most common use-case for this is a signup form. If the contact's list preferences change, they will receive a notification email. New contacts added will receive welcome emails. This is required to res-subscribe a contact who has opted out.
  • ACTION_BY_OWNER - The action was initiated by the Constant Contact account owner or an application acting on his behalf. A good example of this is an automated sync process. The contact being changed will not receive any notification of changes.

As a general rule you will want to use ACTION_BY_OWNER as the default (which means passing false as the second parameter of the updateContact method) so that contacts are not receiving notification mail for actions that they did not initiate. This also prevents any accidental resubscription of opted out contacts that they did not initiate.

 

Additionally, there is a special rule that a contact must have at least 1 list membership if they are being updated as ACTION_BY_VISITOR. This is to prevent an accidental optout action from taking place, as the act of a contact removing themselves from all lists is equivalnet to an optout. In our API, we have implemented a separate method for opting out a contact that is implemented in the SDKs as deleteContact.

 

Given the information above, you can resolve this problem by either changing the second parameter of updateContact from true to false, or by verifying that the contact has at least one list membership.

 

If you have any questions, please let me know!

 

Sincerely,

Elijah G.
API Support Engineer