mailerlite / mailerlite-php Goto Github PK
View Code? Open in Web Editor NEWPHP SDK for MailerLite
License: MIT License
PHP SDK for MailerLite
License: MIT License
When i set the plain_text Field on the emails array on create campaign the API returns a error and it returns a wrong one.
It says «The emails.0 field must be an array» alltough everything is set as in the API docs.
Both examples should work fine or return a correct error.
The API returns following error: «The emails.0 field must be an array»
<?php
use MailerLite\MailerLite;
require_once "vendor/autoload.php";
$mailerLite = new MailerLite([
"api_key" => "",
]);
// This request works as expected:
$response = $mailerLite->campaigns->create([
"type" => "regular",
"name" => "My new campaign",
"language_id" => 10,
"emails" => [
[
"subject" => "My new email",
"from_name" => "My Customer",
"from" => "[email protected]",
"content" => "Hello World!",
],
],
"filter" => [],
]);
// This request throws the error that emails.0 is not set, alltough the problem is with plain_text:
$response = $mailerLite->campaigns->create([
"type" => "regular",
"name" => "My new campaign",
"language_id" => 10,
"emails" => [
[
"subject" => "My new email",
"from_name" => "My Customer",
"from" => "[email protected]",
"content" => "Hello World!",
"plain_text" => "Hello World!",
],
],
"filter" => [],
]);
// PHP Fatal error: Uncaught MailerLite\Exceptions\MailerLiteValidationException: The emails.0 field must be an array
When creating a new campaign using the MailerLite PHP SDK, MailerLite is automatically adding code to the bottom of the HTML content even when the Unsubscribe tag is present in the 'content' parameter being passed to MailerLite API and the "Automatically generate a footer from the company details." is unchecked in the Account Settings. If you edit the HTML content in the MailerLite UX, the code disappears.
A campaign would be created containing only my HTML code that was in the 'content' parameter. In the below example, it is <p>Thanks for the email. <a href="{$unsubscribe}">Unsubscribe</a></p>
.
The following code is inserted below the HTML code in the 'content' parameter.
<style type="text/css">
.mlFooter p{margin:0}@media only screen and (max-width:640px){.mlContentTable{width:100%!important;min-width:10%!important;margin:0!important;float:none!important}.mlContentOuter{padding-bottom:0!important;padding-left:15px!important;padding-right:15px!important;padding-top:0!important}}
</style>
<table align="center" border="0" cellpadding="0" cellspacing="0" width="680" style="width: 680px; min-width: 680px;" class="mlMainContent" dir="ltr">
<tbody>
<tr>
<td class="mlTemplateContainer" style="padding: 20px 20px 0px 20px;">
<table border="0" cellpadding="0" width="100%" class="mlMainContent" style="border-top: 1px solid #d1d3d3;">
<tbody>
<tr>
<td></td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
<table role="article" aria-roledescription="email" align="center" border="0" cellpadding="0" cellspacing="0" width="680" style="width: 680px; min-width: 680px;" class="mlMainContent" dir="ltr">
<tbody>
<tr>
<td class="mlTemplateContainer" style="padding: 20px 20px 0px 20px;">
<table border="0" cellpadding="0" cellspacing="0" width="100%" class="mlMainContent">
<tbody>
<tr>
<td style="font-family: Arial, Helvetica, sans-serif; font-size: 12px; line-height: 125%; color: #000000; padding-top: 15px;" class="ml-rte-footer" align="left">
</td>
</tr>
<tr>
<td id="mlRTEfooterUnsubscribe" style="line-height: 125%;" align="left">
</td>
</tr>
<tr>
<td height="20"></td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
<p>Thanks for the email. <a href="{$unsubscribe}">Unsubscribe</a></p>
For the above steps to reproduce, here's the entirety of my PHP file:
require 'vendor/autoload.php';
use MailerLite\MailerLite;
$mailerLite = new MailerLite(['api_key' => '{my API key went here}']);
$data = [
'type' => 'regular',
'name' => '{my campaign name went here}',
'language_id' => 4,
'emails' => [
[
'subject' => '{my subject went here}',
'from_name' => '{my name went here}',
'from' => '{my verified email address went here}',
'content' => '<p>Thanks for the email. <a href="{$unsubscribe}">Unsubscribe</a></p>',
]
],
'filter' => [],
];
$response = $mailerLite->campaigns->create($data);
When using this SDK, I get the following error:
Fatal error: Composer detected issues in your platform: Your Composer dependencies require a PHP version ">= 8.1.0". You are running 8.0.22
Requiring 8.1 is not yet feasible in my attempts to use this in a WordPress plugin which only has PHP 7.4 as its minimum requirement.
I should be able to use this on PHP 7.4 and greater according to the documentation
You need PHP 8.1. The error does go away when I use at minimum 8.1.
Make any request and this is the result I get.
According to the MailerLite documentation, a call to get all subscribers returns group information for each subscriber:
https://developers.mailerlite.com/docs/subscribers.html#list-all-subscribers
When I call the following:
$response = $mailerLite->subscribers->get();
it does not return group information for each subscriber. There is no groups array included in the response.
Do we need to include something in the call to ask the api to include group info?
$response = $mailerLite->subscribers->get(['someparm' => 'someval' ]); // ??
Thanks.
Original conversation: https://themailergroup.slack.com/archives/C03GPTBQKUK/p1691663547247109
Currently, our getSubscribers
method doesn’t have any page or cursor information, it's missing second parameter $params, where ‘cursor’ could be passed
mailerlite-php/src/Endpoints/Group.php
Line 70 in 1b86b05
If you want to construct your own "HttpLayer" (i.e. to re-use existing HTTP Client etc), you need to explicitly pass in the options array including the API key. This is undocumented. In fact, the main client interface "MailerLite" checks the options array given to the constructor for the api key, and throws an exception if it's not present, and then never uses it internally, assuming that the HttpLayer
will be constructed internally and not passed as a constructor argument. It would make more sense to check for the presence of the api key inside the 'HttpLayer' and throw an exception there.
Adding an array shape to the constructors of both would be helpful, for example:
/** @param array{api_key: non-empty-string} $options */
public function __construct(array $options, ...) {}
Not providing a valid API Key to HttpLayer::__construct()
should throw an exception
PHP Notice: undefined index 'api_key'
The SDK for subscribers doesn't seem to support forget
, although this exists in the REST API.
$mailerLite->subscribers->forget($id)
I currently have to not use the SDK and instead make HTTP requests directly.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.