PHP API to create a subscriber

SoftTimur

Member
As I cannot make the creation of subscribers work in node (https://forum.mailwizz.com/threads/...post-requests-allowed-for-this-endpoint.9135/), I would like to try it in PHP.

In the terminal of my local Mac, I installed the SDK by `composer require ems-api/php-client`, then modified `vendor/ems-api/php-client/example/setup.php` as follows.

PHP:
<?php
// exit('COMMENT ME TO TEST THE EXAMPLES!');
// require_once __DIR__ . '/../vendor/autoload.php';
require 'vendor/autoload.php';
// configuration object
$config = new \EmsApi\Config([
    'apiUrl'    => 'http://mail.mycompany.com/api',
    'apiKey'    => 'key',
    // components
    'components' => [
        'cache' => [
            'class'     => \EmsApi\Cache\File::class,
            'filesPath' => __DIR__ . '/data/cache', // make sure it is writable by webserver
        ]
    ],
]);
// now inject the configuration and we are ready to make api calls
\EmsApi\Base::setConfig($config);
// start UTC
date_default_timezone_set('UTC');
// CREATE THE ENDPOINT
$endpoint = new EmsApi\Endpoint\ListSubscribers();
// ADD SUBSCRIBER
$response = $endpoint->create('tb104q03l4224', [
    'EMAIL'    => 'softtimur@gmail.com', // the confirmation email will be sent!!! Use valid email address
]);
// DISPLAY RESPONSE
echo '<hr /><pre>';
print_r($response->body);
echo '</pre>';
// CREATE / UPDATE EXISTING SUBSCRIBER
$response = $endpoint->createUpdate('tb104q03l4224', [
    'EMAIL'    => 'softtimur@gmail.com'
]);
// DISPLAY RESPONSE
echo '<hr /><pre>';
print_r($response->body);
echo '</pre>';

In the terminal, `php vendor/ems-api/php-client/example/setup.php` returned the follows. `test-ulm9bj7dh@srv1.mail-tester.com` is the only one existing subscriber in the list. So, it means `softtimur@gmail.com` was not added. I don't see `softtimur@gmail.com` in the list on the website of MailWizz either. Does anyone know what can be the cause?

Code:
<hr /><pre>EmsApi\Params Object
(
    [_data:EmsApi\Paramsrivate] => Array
        (
            [status] => success
            [data] => Array
                (
                    [count] => 1
                    [total_pages] => 1
                    [current_page] => 1
                    [next_page] =>
                    [prev_page] =>
                    [records] => Array
                        (
                            [0] => Array
                                (
                                    [subscriber_uid] => sg0748rt2l465
                                     => test-ulm9bj7dh@srv1.mail-tester.com
                                    [FNAME] =>
                                    [LNAME] =>
                                    [status] => confirmed
                                    [source] => web
                                    [ip_address] => 103.47.100.216
                                    [date_added] => 2024-01-31 13:31:03
                                )
                        )
                )
        )
    [_readOnly:EmsApi\Paramsrivate] =>
)
</pre><hr /><pre>EmsApi\Params Object
(
    [_data:EmsApi\Paramsrivate] => Array
        (
            [status] => success
            [data] => Array
                (
                    [count] => 1
                    [total_pages] => 1
                    [current_page] => 1
                    [next_page] =>
                    [prev_page] =>
                    [records] => Array
                        (
                            [0] => Array
                                (
                                    [subscriber_uid] => sg0748rt2l465
                                    [EMAIL] => test-ulm9bj7dh@srv1.mail-tester.com
                                    [FNAME] =>
                                    [LNAME] =>
                                    [status] => confirmed
                                    [source] => web
                                    [ip_address] => 103.47.100.216
                                    [date_added] => 2024-01-31 13:31:03
                                )
                        )
                )
        )
    [_readOnly:EmsApi\Paramsrivate] =>
)
</pre>%
 
Last edited:
If you see the email in the web interface, it means you'll have to confirm it before it shows up in the api results.
 
If you see the email in the web interface, it means you'll have to confirm it before it shows up in the api results.

Are you referring to the web interface of MailWizz? I don't see messages regarding subscriber creation there.

If you are referring to the mail box of softtimur@gmail.com, it did not receive any emails for the confirmation.

As you can see, creating subscribers via the API in either Node or PHP is puzzling us a lot. Missing this single part will prevent us from automating our entire email process, including sending regular newsletters. Your help would be greatly appreciated. Thank you.
 
Last edited:
That response you are showing is not the response you got when you are creating a subscriber. Anyway, you should look in the web interface in that list subscriber section to see if that email was added. It should have the status unconfirmed.
 
That response you are showing is not the response you got when you are creating a subscriber. Anyway, you should look in the web interface in that list subscriber section to see if that email was added. It should have the status unconfirmed.
The email was not added to the list on the website of MailWizz.

I added some details in the OP. For instance, I run the script in the terminal of my Mac, is it a problem?

Does the script look good to you?

Is there any place we could check what happened behind the scenes?
 
Please open a support ticket and share there backend access to your application.
 
Back
Top