Skip to navigation

Sending a campaign via the API

If your layout comes from another system, such as a CMS that already generates the newsletter, you can create, populate and send the campaign entirely via the API. There is no need to open the editor.

1

Create the campaign

The sender address must be approved within Laposta, otherwise you will receive an error message. Under list_ids, specify the lists and any segments that should receive the campaign.

curl
curl https://api.laposta.nl/v2/campaign \
-u YOUR_API_KEY: \
-d type=regular \
-d 'name=March newsletter' \
-d 'subject=The March newsletter' \
-d 'from[name]=Example Ltd' \
-d from[email]=newsletter@example.net \
-d reply_to=info@example.net \
-d list_ids[]=BaImMu3JZA
PHP
$laposta = new Laposta('YOUR_API_KEY');
$campaign = $laposta->campaignApi()->create([
'type' => 'regular',
'name' => 'March newsletter',
'subject' => 'The March newsletter',
'from' => ['name' => 'Example Ltd', 'email' => 'newsletter@example.net'],
'reply_to' => 'info@example.net',
'list_ids' => ['BaImMu3JZA'],
]);
2

Populate the campaign with HTML

Include the HTML in the request, or provide a URL where Laposta can fetch the code. Choose one of the two. If you provide both, Laposta will use the HTML included in the request.

curl
curl https://api.laposta.nl/v2/campaign/njhgaf61ye/content \
-u YOUR_API_KEY: \
-d import_url=https://example.net/newsletter.html \
-d inline_css=true
PHP
$laposta->campaignApi()->updateContent('njhgaf61ye', [
'import_url' => 'https://example.net/newsletter.html',
'inline_css' => true,
]);

The response includes a report with details: a missing unsubscribe link, JavaScript that has been stripped out, or an image that could not be loaded. You can still send the campaign with these comments, but be sure to check them first.

3

Send a test email

This is only possible for a campaign that already has content and has not yet been sent.

curl
curl https://api.laposta.nl/v2/campaign/njhgaf61ye/action/testmail \
-u YOUR_API_KEY: \
-d email=you@example.net
PHP
$laposta->campaignApi()->sendTestMail('njhgaf61ye', 'you@example.net');
4

Send or schedule the campaign

Sending takes place in the background: you receive an immediate response while the delivery is still in progress. To schedule a campaign, specify a time in the future.

curl
curl https://api.laposta.nl/v2/campaign/njhgaf61ye/action/schedule \
-u YOUR_API_KEY: \
-d 'delivery_requested=2026-05-18 09:00:00'
PHP
$laposta->campaignApi()->schedule('njhgaf61ye', '2026-05-18 09:00:00');

Sending cannot be undone. A second call is not blocked and will trigger the delivery again. Make sure your own code prevents this: record that you have already sent a campaign, and do not allow the same action to be triggered twice by a repeated call or a double click. You can cancel a scheduled campaign by deleting it.

A campaign created in the drag & drop editor cannot be populated or read via the API. Doing so will return the message “Wrong campaign type”. Managing content via the API only works for campaigns that you have created or imported yourself.

Retrieving results after sending

You can request the results immediately after sending. The figures will continue to rise as more recipients open the email and click on links.

WhatWhere
Numbers and ratios per campaignResults of a campaign
All campaigns in the accountRetrieving all results
Individual events, such as opens and clicksRetrieving campaign history