Skip to navigation

Making your first API call

The quickest way to check whether everything works is to retrieve your lists. This call does not change anything in your account and gives an immediate response. You can make this call right here on the site or from your own computer.

Making a call via this site

1

Create an API key

Create a key in your account under ‘Connect’. A new key is only visible once, so save it straight away. See: Create an API key.

2

Open the endpoint

Go to Retrieve all lists.

3

Enter your key and send

Click ‘Try it’ on the right of the code example and enter your key under ‘api_key’. Then click send. You can read more about this field and button at Trying out the API with Try it.

4

Read the response

You will receive a 200 response containing all your lists in data. You will need the list_id shown there for almost every other call.

This makes a real API call. To find out how to test safely, see Trying out the API with Try it.

Making a call from your own system

You can read how to send your key along at Authentication with your API key.

curl
curl https://api.laposta.nl/v2/list \
-u YOUR_API_KEY:

With the PHP library, this is:

PHP
$laposta = new Laposta('YOUR_API_KEY');
$lists = $laposta->listApi()->all();

A response looks like this, shortened to one list:

{
"data": [
{
"list": {
"list_id": "BaImMu3JZA",
"name": "Newsletter",
"state": "active",
"members": { "active": 1232, "unsubscribed": 113, "cleaned": 14 }
}
}
]
}

Adding a subscriber

The next call you will probably need is adding a subscriber. In addition to the email address, the IP address is required, as this records where the registration came from.

curl
curl https://api.laposta.nl/v2/member \
-u YOUR_API_KEY: \
-d list_id=BaImMu3JZA \
-d ip=198.51.100.10 \
-d email=new.subscriber@example.net \
-d custom_fields[firstname]=Sarah
PHP
$laposta->memberApi()->create('BaImMu3JZA', [
'ip' => '198.51.100.10',
'email' => 'new.subscriber@example.net',
'custom_fields' => ['firstname' => 'Sarah'],
]);

The keys within custom_fields are the custom_name of your own fields. You can retrieve these once with Retrieve all fields and store them in your own code.