adding contenct in the list is not working and get bad request error with php sdk

0 Votes

Following code for adding contenct in the list is not working

$contact = new Contact();
$contact->id = "12345678";
$contact->first_name = "javed";
$contact->last_name = "khan";
$ctct = new ConstantContact('n4chre33sujpn5ef3*******');
$contacts = $ctct->contactService->addContact('9d2541bf-b864-46e9-990a-***********', $contact, array());

the following error what gets when executing the above code 


An uncaught Exception was encountered

Type: Ctct\Exceptions\CtctException

Message: Bad Request

Filename: C:\xampp\htdocs\vgt-api\application\third_party\vendor-constantcontact\constantcontact\constantcontact\src\Ctct\Services\BaseService.php

Line Number: 78


File: C:\xampp\htdocs\vgt-api\application\third_party\vendor-constantcontact\constantcontact\constantcontact\src\Ctct\Services\ContactService.php
Line: 144
Function: convertException

File: C:\xampp\htdocs\vgt-api\application\controllers\JConstantcontact.php
Line: 81
Function: addContact

File: C:\xampp\htdocs\vgt-api\index.php
Line: 286
Function: require_once

0 Votes

Thank you for reaching out to Constant Contact API Developer Support. My team is here to assist outside software developers with questions about building into Constant Contact's API.


Based on the provided code, there are two areas that may need to be adjusted:


$contact->id = "12345678";
I would remove this line from the code, as we assign an ID automatically upon creating the contact.


This line appears to be identifying the list_id. The V2 API doesn't use the list_id and needs a different value here, as V2 and V3 APIs use different formats for list IDs.


If you are unsure how to get the correct values for the account's lists, you can use this function from the PHP SDK:


You can also just use the V2 API tester to get those values:


If fixing those two items doesn't resolve the issue, we would need to know the new response you’re receiving, preferably with the full error message so that we can look into this further for you.


Courtney E.
Tier II API Support Engineer

Did I answer your question?
If so, please mark my post as an "Accepted Solution" by clicking the Accept as Solution button in the bottom right hand corner of this post.
Developer Portal

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

Visit Page


API Updates

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

Sign Up

How confident are you about the effectiveness of your current marketing strategy?

Top Choice: Not confident at all (78%)