As I cannot make the creation of subscribers work in node (Only POST requests allowed for this endpoint), I would like to try it in PHP.
I installed the SDK by following this doc and composer require ems-api/php-client
, then modified vendor/ems-api/php-client/example/setup.php
as follows.
<code><?php
// exit('COMMENT ME TO TEST THE EXAMPLES!');
// require_once __DIR__ . '/../vendor/autoload.php';
require 'vendor/autoload.php';
// configuration object
$config = new EmsApiConfig([
'apiUrl' => 'http://mail.mycompay.com/api',
'apiKey' => 'kpi',
// components
'components' => [
'cache' => [
'class' => EmsApiCacheFile::class,
'filesPath' => __DIR__ . '/data/cache', // make sure it is writable by webserver
]
],
]);
// now inject the configuration and we are ready to make api calls
EmsApiBase::setConfig($config);
// start UTC
date_default_timezone_set('UTC');
// CREATE THE ENDPOINT
$endpoint = new EmsApiEndpointListSubscribers();
// ADD SUBSCRIBER
$response = $endpoint->create('tb104q03l4224', [
'EMAIL' => '[email protected]', // 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' => '[email protected]'
]);
// DISPLAY RESPONSE
echo '<hr /><pre>';
print_r($response->body);
echo '</pre>';
</code>
<code><?php
// exit('COMMENT ME TO TEST THE EXAMPLES!');
// require_once __DIR__ . '/../vendor/autoload.php';
require 'vendor/autoload.php';
// configuration object
$config = new EmsApiConfig([
'apiUrl' => 'http://mail.mycompay.com/api',
'apiKey' => 'kpi',
// components
'components' => [
'cache' => [
'class' => EmsApiCacheFile::class,
'filesPath' => __DIR__ . '/data/cache', // make sure it is writable by webserver
]
],
]);
// now inject the configuration and we are ready to make api calls
EmsApiBase::setConfig($config);
// start UTC
date_default_timezone_set('UTC');
// CREATE THE ENDPOINT
$endpoint = new EmsApiEndpointListSubscribers();
// ADD SUBSCRIBER
$response = $endpoint->create('tb104q03l4224', [
'EMAIL' => '[email protected]', // 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' => '[email protected]'
]);
// DISPLAY RESPONSE
echo '<hr /><pre>';
print_r($response->body);
echo '</pre>';
</code>
<?php
// exit('COMMENT ME TO TEST THE EXAMPLES!');
// require_once __DIR__ . '/../vendor/autoload.php';
require 'vendor/autoload.php';
// configuration object
$config = new EmsApiConfig([
'apiUrl' => 'http://mail.mycompay.com/api',
'apiKey' => 'kpi',
// components
'components' => [
'cache' => [
'class' => EmsApiCacheFile::class,
'filesPath' => __DIR__ . '/data/cache', // make sure it is writable by webserver
]
],
]);
// now inject the configuration and we are ready to make api calls
EmsApiBase::setConfig($config);
// start UTC
date_default_timezone_set('UTC');
// CREATE THE ENDPOINT
$endpoint = new EmsApiEndpointListSubscribers();
// ADD SUBSCRIBER
$response = $endpoint->create('tb104q03l4224', [
'EMAIL' => '[email protected]', // 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' => '[email protected]'
]);
// DISPLAY RESPONSE
echo '<hr /><pre>';
print_r($response->body);
echo '</pre>';
php vendor/ems-api/php-client/example/setup.php
returned the follows. [email protected]
is the only one existing subscriber in the list. So, it means [email protected]
was not added. Does anyone know what can be the cause?
<code><hr /><pre>EmsApiParams Object
(
[_data:EmsApiParams:private] => 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] => [email protected]
[FNAME] =>
[LNAME] =>
[status] => confirmed
[source] => web
[ip_address] => 103.47.100.216
[date_added] => 2024-01-31 13:31:03
)
)
)
)
[_readOnly:EmsApiParams:private] =>
)
</pre><hr /><pre>EmsApiParams Object
(
[_data:EmsApiParams:private] => 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] => [email protected]
[FNAME] =>
[LNAME] =>
[status] => confirmed
[source] => web
[ip_address] => 103.47.100.216
[date_added] => 2024-01-31 13:31:03
)
)
)
)
[_readOnly:EmsApiParams:private] =>
)
</pre>%
</code>
<code><hr /><pre>EmsApiParams Object
(
[_data:EmsApiParams:private] => 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] => [email protected]
[FNAME] =>
[LNAME] =>
[status] => confirmed
[source] => web
[ip_address] => 103.47.100.216
[date_added] => 2024-01-31 13:31:03
)
)
)
)
[_readOnly:EmsApiParams:private] =>
)
</pre><hr /><pre>EmsApiParams Object
(
[_data:EmsApiParams:private] => 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] => [email protected]
[FNAME] =>
[LNAME] =>
[status] => confirmed
[source] => web
[ip_address] => 103.47.100.216
[date_added] => 2024-01-31 13:31:03
)
)
)
)
[_readOnly:EmsApiParams:private] =>
)
</pre>%
</code>
<hr /><pre>EmsApiParams Object
(
[_data:EmsApiParams:private] => 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] => [email protected]
[FNAME] =>
[LNAME] =>
[status] => confirmed
[source] => web
[ip_address] => 103.47.100.216
[date_added] => 2024-01-31 13:31:03
)
)
)
)
[_readOnly:EmsApiParams:private] =>
)
</pre><hr /><pre>EmsApiParams Object
(
[_data:EmsApiParams:private] => 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] => [email protected]
[FNAME] =>
[LNAME] =>
[status] => confirmed
[source] => web
[ip_address] => 103.47.100.216
[date_added] => 2024-01-31 13:31:03
)
)
)
)
[_readOnly:EmsApiParams:private] =>
)
</pre>%