Python API, how to send draft campaign?

davidstein

New Member
Since the API doesn't let me set "campaign actions upon subscriber event" i manually created a campaign with all desired preferences and i just copy it via the API Copy endpoint,
after the copy ends, the campaign appears as draft, i update it using API update endpoint, it get updated but it remains as draft (i also tried to update the campaign status to "pending-sending" but it didn't work).
If i use the same "campaign object" i use for update endpoint in create campaign endpoint the campaign will be start sending automatically.
I wonder what field do i need to update in order execute a draft campaign.
Please advise...

Thanks
 

laurentiu

Active Member
Staff member Support Staff MailWizz 2.0 Tester
Since the API doesn't let me set "campaign actions upon subscriber event" i manually created a campaign with all desired preferences and i just copy it via the API Copy endpoint,
after the copy ends, the campaign appears as draft, i update it using API update endpoint, it get updated but it remains as draft (i also tried to update the campaign status to "pending-sending" but it didn't work).
If i use the same "campaign object" i use for update endpoint in create campaign endpoint the campaign will be start sending automatically.
I wonder what field do i need to update in order execute a draft campaign.
Please advise...
This has been fixed and will be available in the next release, so to start sending an updated campaign is necessary to add:
"status" : "pending-sending",

PHP:
// UPDATE CAMPAIGN
$response = $endpoint->update('CAMPAIGN-UNIQUE-ID', [
    'name'          => 'My API Campaign UPDATED', // optional at update
    'from_name'     => 'John Doe', // optional at update
    'from_email'    => 'john.doe@doe.com', // optional at update
    'subject'       => 'Hey, i am testing the campaigns via API', // optional at update
    'reply_to'      => 'john.doe@doe.com', // optional at update
    'send_at'       => date('Y-m-d H:i:s', strtotime('+1 hour')), //optional at update, this will use the timezone which customer selected
    'list_uid'      => 'LIST-UNIQUE-ID', // optional at update
    'segment_uid'   => 'SEGMENT-UNIQUE-ID',// optional, only to narrow down
    'status'        => 'pending-sending',

Also if you need now this change you can open web/apps/api/controllers/CampaignsController.php and add on LINE: 711

PHP:
// since 2.0.29
$allowedStatuses = [Campaign::STATUS_PENDING_SENDING, Campaign::STATUS_DRAFT, Campaign::STATUS_PAUSED];
if (isset($attributes['status']) && in_array($attributes['status'], $allowedStatuses)) {
    $campaign->status = $attributes['status'];
}

Screenshot 2021-09-29 at 12.55.45.png
 
Top