Create Campaign via API

Ronnie

New Member
Hi, I am integrating Mailwizz with our Python/Django based backend. I have a simple/basic python library to do API calls on Mailwizz. Currently I can get lists and add a subscriber via the mailwizz api however I'm stuck on implementing the create campaign via the api.

My api call will be as follows, an HTTP POST with the post body:
See: https://api-docs.mailwizz.com/#campaigns

POST https://www.example.com/api/index.php/campaigns
{
"name": "Test Campaign",
"from_name": "Test",
"from_email": "test@example.com",
"subject": "Test",
"reply_to": "test@example.com",
"list_uid": "list-id",
"send_at": "2019-03-22T07:54:42.325383+00:00",
"template": {
"template_id": "template-id"
}
}
And here is the response:
Status code: 422
{'status': 'error', 'error': {'name': 'Campaign name cannot be blank.', 'from_name': 'From name cannot be blank.', 'from_email': 'From email cannot be blank.', 'subject': 'Subject cannot be blank.', 'reply_to': 'Reply to cannot be blank.'}}


But It seems like Mailwizz campaign api cant read the post body. My HTTP headers I believe is correct since I can successfully call get lists and add subscriber api endpoint. I assume that the post data above are not correct? Any advice.
 
Hi, I just did and sent it with form encoded data with Content-Type header: 'application/x-www-form-urlencoded' but still I get the same error HTTP 422. Any more advice?
 
I even used Postman to do the api call with same set of headers and form data, still it returned same error.
 
So I have figured out the issue, it was bcoz of our HTTP Library not supporting properly the nested POST data required for creating campaigns.

Another question: Looking at the docs to create campaign https://api-docs.mailwizz.com/#campaigns
Is it possible to enable Randomize Subscribers via the api when creating a campaign? There was no reference of it in the examples.
 
Is it possible to enable Randomize Subscribers via the api when creating a campaign? There was no reference of it in the examples.
You can try, in the options area, to send like:
PHP:
...
'options' => array(
   ...
   'max_send_count' => 1000,
   'max_send_count_random' => 'yes'
   ...
),
...
 
@tier1 - Please see this article: https://api-docs.mailwizz.com/#campaigns , like bellow example from docs if these lines are commented in your file then only normal regular campaign will be created. 'cronjob_enabled' => 1 means advance recurring is set to yes and cronjob' => '0 0 * * *', this is frequency for advanced recurring in this example once a day.
PHP:
...
'options' => array(
    ...
    // - if this campaign is advanced recurring, you can set a cron job style frequency.
    // - please note that this applies only for regular campaigns.
    //'cronjob'         => '0 0 * * *', // once a day
    //'cronjob_enabled' => 1, // 1 or 0
    ...
),
..
 
Back
Top