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

user798673
Rookie
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";
$contact->addEmail("javed.khan@example.com");
$contact->addList('099896ba-0ce6-11eb-81d5-**********');
$ctct = new ConstantContact('n4chre33sujpn5ef3*******');
$contacts = $ctct->contactService->addContact('9d2541bf-b864-46e9-990a-***********', $contact, array());
var_dump($contacts);

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

Backtrace:

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

1 REPLY 1
Courtney_E
Employee
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.

 

$contact->addList('099896ba-0ce6-11eb-81d5-**********');
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:
http://constantcontact.github.io/php-sdk/class-Ctct.Services.ListService.html#_getLists

 

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

https://v2.developer.constantcontact.com/docs/contact-list-api/contactlist-collection.html

 

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.


Regards,

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.
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