Enter the Share Your Success Sweepstakes 2024 For the Chance to Win Great Prizes!

API v3 Creating contact invalid email address

user845116
Campaign Collaborator

Currently developing a system using the V3 api.
I have a test client connected via OAuth.
When I post to the 'contacts' end point in order to create a contact I get the following errors returned (php).

 

array:3 [▼
  0 => array:2 [▼
    "error_key" => "contacts.api.validation.error"
    "error_message" => "create_source is missing, create_source does not have a valid value"
  ]
  1 => array:2 [▼
    "error_key" => "contacts.api.validation.error"
    "error_message" => "email_address is invalid"
  ]
  2 => array:2 [▼
    "error_key" => "contacts.api.validation.error"
    "error_message" => "email_address[address] is missing, email_address[address] is invalid"
  ]


It does not matter what email I pass they are all invalid. If I do not pass the email I get an email is missing error. If I pass the email I get it is invalid. The value is being passed as
{"email_address":"gum2@testing.com"}

Why is this happening? How am I supposed to create a contact?

7 REPLIES 7
Jimmy_D
Employee
0 Votes

Hello @user845116,

 

Thank you for reaching out to Constant Contact's API Support.

 

I would suggest to take a look at our API Reference page to see a full example of what could be in the body for creating a contact.

 

You do need to include "create_source": "Account" or "create_source": "Contact" depending on whether you want the contact to reflect if it was created by the account owner or created by the contact. The last option is generally used for sign-up forms.

 

You also need your email address to be in the form of an array. I'm not sure exactly how you had it coded, but here is what it should look like in JSON.

{
  "email_address": {
    "address": "gum2@testing.com"
  }

Here is the full JSON for what I added to my own test account.

{
  "email_address": {
    "address": "gum2@testing.com"
  },
"create_source": "Contact",
  "list_memberships": [
    "17d13e10-9550-11e6-84df-d4ae5275b546"
  ]
}

Your listID will of course be different.


Regards,
Jimmy D.
Tier II API Support Engineer
user845116
Campaign Collaborator
0 Votes

Hi Jimmy

Thanks for the quick reply!

In my defence the docs are the first place I looked and looked again.
https://v3.developer.constantcontact.com/api_guide/contacts_create.html

 

I cannot find any mention of a create_source here. And states it only need one of the 3 parameters. first_name, last_name and/or email_address.

I was also unable to find any reference to the method you have used to add contacts at the same time as adding it to a list. 
From what I can see here 
https://v3.developer.constantcontact.com/api_guide/lists_overview.html
I need to pass contact_id when adding to a list.

In fact I cannot find any references to the method you are using. In addition your method fails when adding a contact that already exists. Unfortunantly This does not work with the flow I need.

So using your code as reference I am able to add in a contact. So the flow of the app goes as follows.

- Check if contact exists.
- If not create contact
- Use the contact ID and add that contact to the select list.

Now I cannot add a contact to a list. Im following this here to add contacts to a list
https://v3.developer.constantcontact.com/api_guide/lists_overview.html
Passing to 'https://api.cc.email/v3/activites/add_list_memberships'

{#866   +"source": array:1 [
    "contact_ids" => array:1 [
      0 => "75a8a350-2fab-11e9-9c34-d4ae5275505f"
    ]
  ]
  +"list_ids": array:1 [
    0 => "28a40610-1f9f-11e9-a7ee-d4ae528eb27b"
  ]}


And the return is

array:1 [  0 => array:2 [
    "error_key" => "not_found"
    "error_message" => "The requested resource was not found."
  ]]


Any ideas what is wrong now?


Jimmy_D
Employee
0 Votes

Hi @user845116,

 

I've done various testing and the only way I can replicate this exact error message is when submitting to the incorrect URL i.e. https://api.cc.email/v3/activities/add_list_membership instead of https://api.cc.email/v3/activities/add_list_memberships.

 

If I submit the call with an invalid listID I receive an error calling out the invalid listID. If I submit with a non-existing contactID I receive a 201 due to the bulk request being successfully made, but there is no activity actually taking place.

 

I know your post shows the correct URL, but can you please verify there is no leading or ending spaces or anything along those lines?


Regards,
Jimmy D.
Tier II API Support Engineer
user845116
Campaign Collaborator
0 Votes

Hey  Jimmy

Yeah the URL is correct. ATM its hard coded to elimiate this as a problem.

$url = 'https://api.cc.email/v3/activites/add_list_memberships';
print_r('before add to list<br />');
$results = $this->queryAPI($url, [], 'POST', $c_data, true);

The process is the same for each call. Just different values. The calls to check for the contact is working and such. The only call that is failing is 'https://api.cc.email/v3/activites/add_list_memberships'. I've also outputted the URL just before the call to make sure.

Anything else that can be causing this?

Jimmy_D
Employee
0 Votes

Hi @user845116,

 

Are you able to make this call using the API Reference page?


Regards,
Jimmy D.
Tier II API Support Engineer
user845116
Campaign Collaborator

It worked using this.
After I used this I took the result URL and pasted in my code.

 

$url = 'https://api.cc.email/v3/activites/add_list_memberships';
$url = 'https://api.cc.email/v3/activities/add_list_memberships';

 

The url is different. 'activites' vs 'activities'

I check the documentation doc here: https://v3.developer.constantcontact.com/api_guide/lists_overview.html

And sure enough the URL is not spelt correctly..

Example Request - POST add_list_membership
This call adds five existing contacts to two lists. The contacts are specified in thesource object contacts array of contact_id’s.

POST https://api.cc.email/v3/activites/add_list_memberships

There seem to be another typo in the above as well.
'thesource' I guess should be 'the source'

This has caused me great pain. Its working now.

Jimmy_D
Employee
0 Votes

Hi @user845116,

 

I apologize about that. I did not notice the spelling errors. I will get this to our documentation person and have it corrected. I'll let you know when it is so you can then update your code again to the corrected versions.


Regards,
Jimmy D.
Tier II API Support Engineer
Resources
Developer Portal

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

Visit Page

Announcements

API Updates

Join our list to be notified of new features and updates to our V3 API.

Sign Up