cancel
Showing results for 
Search instead for 
Did you mean: 

http.status.bad_request:No contacts to send with "Import Contacts Endpoint"

Occasional Contributor

http.status.bad_request:No contacts to send with "Import Contacts Endpoint"

I am using this logic: "Import Contacts Endpoint"; but when programming the campaign I have always this message:

 

Error message: http.status.bad_request:No contacts to send.

 

The campaign is created in Draf mode, and the corresponding contacts list also is created;but does not allow me to program the campaign

 

We program in C #

 

img.jpg

7 REPLIES 7
Honored Contributor

Re: http.status.bad_request:No contacts to send with "Import Contacts Endpoint"

Hello,

 

In order to resolve this issue, your email campaigns must be assigned a list which it will send contacts to. This can be done by setting the Lists property of the campaign before calling ConstantContact.AddCampaign. The type for this property is IList<SentContactList> and you can see the definition for the SentContactList class here.

 

For existing campaigns, you can use the GetCampaign and UpdateCampaign methods of the ConstantContact class to address the problem.

 

If you have any questions for me about this, please let me know!

 

Sincerely,

 

Elijah G.
API Support Engineer
Occasional Contributor

Re: http.status.bad_request:No contacts to send with "Import Contacts Endpoint"

thanks for replying,

We are using the IList<SentContactList> instructions to assign the corresponding list to the campaign, this is the logic:

- Contact list : IDLits

1. Verify if IDList already exists: if not it will be created using AddList(ContactList)
2. We will add contacts one by one to IDList using AddContact(Contact, false)
3. We instance a EmailCampaign: IDCamp class object
4. Setup data like Name, Subject, FromName, EmailContent for IDCamp
5. Link IDList with IDCamp : IDCamp.Lists = List<SentContactList>;
6. Schedule campaign and save


But when we change the logic (item 2) to add contacts using "Import Contacts Endpoint" method to make mass contact mailling - POST(url, jsonContent), I get an error when I schedule the campaign.

We added an extra 30 seconds after  POST(url, jsonContent)  method for massive contact mailing so it is successful before adding and scheduling a campaign; but the issue is still there: we can create the campaign, and contacts, but both are not linked.

Honored Contributor

Re: http.status.bad_request:No contacts to send with "Import Contacts Endpoint"

Hello,

 

In this case, the error is occurring because the add contacts process has not yet populated the desired contacts to the list. When using the Import Contacts bluk activity, it is important to note that it is an asynchronous bulk processing job. Once the POST request is complete, then that job is placed in a queue and normally started within 10-20 seconds if there is not already a job processing for that account.

 

Once the job has begun processing, the time to completion can vary a decent amount based on the number of contacts being imported. If you would prefer to simply detect if the activity is completed, you can do so by using the GetActivity(id) method of the ConstantContact class. This method requires an activity ID as a parameter, and the ID is returned from the API call which created the import activity. In order to determine the status of your activity, you can check the status property of the returned object from this call. You can find the possible statuses here: http://developer.constantcontact.com/docs/bulk_activities_api/bulk-activities-status-detail-report-a...

 

If there is any more information that I can provide to help with this, please let me know. Have a great holiday!

 

Sincerely,

 

 

Elijah G.
API Support Engineer
Visitor

Re: http.status.bad_request:No contacts to send with "Import Contacts Endpoint"

I have created a contact list in runtime.Then imported a csv file containing information of users using createAddContactsActivityFromFile method with the following parameters.

1-> ACCESS_TOKEN

2 -> File name

3-> fileLocation

4-> list ID

 

when i am calling getList Method on the basid of list id, it showing me all the contacts that i have added to the list.but After attaching this list to the campaign when i am trying to schedule it. An error like "No contacts to send" and "Bad Request "is coming every time.

 

 

 

Honored Contributor

Re: http.status.bad_request:No contacts to send with "Import Contacts Endpoint"

Hello,

 

Is it possible for you to provide a sample of the code you're using to attach the list to the campaign? It is important to note that using our SDKs you would be required to add the list to the campaign object and update the campaign at Constant Contact before scheduling the campaign. This is because the change to add the contact list must be saved to Constant Contact in order for the scheduling to succeed.

 

Please also let me know if you have any questions!

 

Sincerely,

Elijah G.
API Support Engineer
Visitor

Re: http.status.bad_request:No contacts to send with "Import Contacts Endpoint"

Here is the sample code :-

 

$cc = new ConstantContact(APIKEY);
$campaign=new Campaign();
$request=$this->getRequest();
if($request->isPost())
{
try
{
$campaign->name = $request-> getPost('name');
$campaign->subject= $request-> getPost('subject');
$campaign->from_name= $request-> getPost('from_name');
$campaign->from_email=$request-> getPost('from_addr');
$campaign->greeting_string = $request-> getPost('greeting_string');
$campaign->reply_to_email = $request-> getPost('reply_to_addr');
$campaign->text_content= $request-> getPost('text_content');
$campaign->email_content= $request-> getPost('email_content');
$campaign->email_content_format= $request-> getPost('format');
$time=$request->getPost('schedule_time');
$lists=$request->getPost('lists');

// Create a new Contact List while creating a Campaign
$contactList=new ContactList();
$contactList->id=uniqid();
$contactList->name="Donor List".uniqid();
$contactList->status="ACTIVE";
$contactList->created_date=date('Y-m-d\TH:i:s\.000\Z');
$contactList->modified_date=date('Y-m-d\TH:i:s\.000\Z');

try
{

$listInfo=$cc->listService->addList(ACCESS_TOKEN,$contactList);
$listId=$listInfo->id;

}
catch (Exception $ex)
{
echo 'Error in Creating list';
print_r($ex->getErrors());
die();
}
if($listId)
{
try
{

$path = getcwd() . '/public/contact.csv';

$importList=$cc->activityService->createAddContactsActivityFromFile(ACCESS_TOKEN,'contact.csv',$path,$listId);

}
catch (CtctException $ex)
{
echo 'Error in Adding contact';
print_r($ex->getErrors());
die();
}



$campaign->addList($listId);

}



$CampaignId=$cc->emailMarketingService->addCampaign(ACCESS_TOKEN,$campaign);
}

catch (CtctException $ex)
{
echo 'Error Creating Campaign';
print_r($ex->getErrors());
die();
}

try
{
if($CampaignId->id)
{


$campaignId = $CampaignId->id;
$schedule = new Schedule();
$schedule->scheduled_date = $time;
$result= $cc->campaignScheduleService->addSchedule(ACCESS_TOKEN, $campaignId, $schedule);


}
}

catch (CtctException $ex)
{
echo 'Error Scheduling Campaign';
print_r($ex->getErrors());
die();
}



}

 

How much time an activity takes  to change its status from QUEUED to COMPLETE?My status is always coming QUEUED after importing a list.For scheduling a campaign it should be COMPLETE.

Honored Contributor

Re: http.status.bad_request:No contacts to send with "Import Contacts Endpoint"

Hello,

 

Based on your code, you definitely have the order of operations correct, and you have identified the issue with your question at the end. In this case, there are no contacts to send because the import activity has not completed. When a file is uploaded to Constant Contact it is normal that it may take 1-3 minutes to process the file. If your application flow requires that the list is created at the same time as the email campaign, you will need some way to continue processing as a background task.

 

Processing in the background would allow you to poll the activity(for example, checking once every 20 seconds) to see if it has completed before scheduling the campaign, which should resolve the issue. If you're not familiar with running background jobs in PHP, Gearman is a great tool that you can use.

 

If you have any questions, please let me know!

 

Sincerely,

Elijah G.
API Support Engineer