Comments (15)
Just realised you ARE using guzzle - i'll keep you posted with how i go getting mocks in there
from mailjet-apiv3-php.
Hey @bretto36 ! Amazing! We are definitely going to feature your work in our documentation!
I don't really get what you are looking for here. You want the client to prevent the Http call right ?
you just need to pass a third parameter to the constructor. https://github.com/mailjet/mailjet-apiv3-php/blob/master/src/Mailjet/Client.php#L41 . false
will return a response without actual data/status
Please let me know if you need any help on implementing this !
from mailjet-apiv3-php.
I can prevent the actual call (using the flag), but what i'm hoping to achieve is to simulate a response. EG I have an app where i want to test that the mail is sent and handles valid responses. I want to be able to see what it will do if i provide it with an error response and with a success response so i can ensure it fails gracefully and provides a meaningful error
from mailjet-apiv3-php.
@bretto36
We are about to release new version of our Send API v3.1. In there, we will have new mode called Sandbox mode. When set to true, the Send API processes the message as usual, validating the input payload but does not actually drop the message in the sending queue. When everything’s OK, it returns a 200 OK, using the success payload with fake IDs in it.
I believe this is similar to what you would like to achieve. The release of the new SendAPI is coming soon, stay tuned!
from mailjet-apiv3-php.
@Zhivko-Mailjet really great to hear that as this is exactly the feature I need right now ;), can you provide an approximate release date? (maybe an exact one... ;))
from mailjet-apiv3-php.
Hi @wysow , I can not give you exact date yet but the release of the new Send API is scheduled for January. Initially, it will start as private beta.
from mailjet-apiv3-php.
@Zhivko-Mailjet thanks for the feedback, really would like to be part of this beta if possible, what's the process to be in?
from mailjet-apiv3-php.
Hi @wysow,
I'm happy to hear you are interested in testing our new API. Please contact our support, selecting the API category, for details.
from mailjet-apiv3-php.
Done @Zhivko-Mailjet thanks.
from mailjet-apiv3-php.
@wysow @Zhivko-Mailjet is 3.1 out now ? Can't find anywhere in the doc for a sanbox flag (or the 3.1 changelog)
edit : ok looks like it's still in beta... guess we'll have to wait
from mailjet-apiv3-php.
@wysow @tentacode @bretto36
The new SendAPI beta is live. It has the Sandbox mode, which allows you to simulate the sending, verifyting the payload. See more details here:
https://dev.mailjet.com/beta/#sandbox-mode
from mailjet-apiv3-php.
Hi @Zhivko-Mailjet,
I've just tried this feature but even if I set the SandBoxMode
flag, the mail is sent. The code I wrote:
public function send(int $templateId, array $toUsers, array $vars = []): bool
{
$recipients = [];
foreach ($toUsers as $user) {
$recipients[] = [
'Email' => $user->getEmail(),
'Name' => \sprintf('%s %s', $user->getFirstname(), $user->getLastname()),
'Vars' => $vars,
];
}
$body = [
'FromEmail' => $this->fromEmail,
'MJ-TemplateID' => $templateId,
'MJ-TemplateLanguage' => true,
'Recipients' => $recipients,
];
if ($this->sandbox) {
$body['SandboxMode'] = true;
}
$response = $this->mailjet->post(Resources::$Email, ['body' => $body]);
if ($response->success()) {
return true;
}
$this->logger->critical('Mailjet error: {error}', ['error' => $response->getReasonPhrase()]);
return false;
}
Am I doing something wrong?
from mailjet-apiv3-php.
Hi @dunglas
The Sandbox mode is new functionality, which works in our new SendAPI v3.1. In order to take advantage of it, you have to switch the API versions and adapt your code as per the new requirements. See sample code below:
use \Mailjet\Resources;
$mj = new \Mailjet\Client(getenv('MJ_APIKEY_PUBLIC'), getenv('MJ_APIKEY_PRIVATE'),true,['version' => 'v3.1']);
$body = [
'Messages' => [
[
'From' => [
'Email' => "[email protected]",
'Name' => "Mailjet Pilot"
],
'To' => [
[
'Email' => "[email protected]",
'Name' => "passenger 1"
]
],
'Subject' => "Your email flight plan!",
'TextPart' => "Dear passenger 1, welcome to Mailjet! May the delivery force be with you!",
'HTMLPart' => "<h3>Dear passenger 1, welcome to Mailjet!</h3><br />May the delivery force be with you!"
]
],
'SandboxMode' => true
];
$response = $mj->post(Resources::$Email, ['body' => $body]);
$response->success() && var_dump($response->getData());
Additional information you can find in our guides:
https://dev.mailjet.com/beta/?php#send-api-v3-to-v3-1
from mailjet-apiv3-php.
Thanks, it works now. However there is an issue in the example in https://dev.mailjet.com/beta/?php#using-a-template:
\Mailjet\Client(getenv('MJ_APIKEY_PUBLIC'), getenv('MJ_APIKEY_PRIVATE'),['version' => 'v3.1']);
the 3rd parameter (true
) is missing.
from mailjet-apiv3-php.
Thanks for reporting that. We have also spotted the error. It is now fixed.
from mailjet-apiv3-php.
Related Issues (20)
- How to debug ? HOT 5
- Version overrided when not duplicated in $options HOT 2
- Blocks & Hard/Soft Bounces Statistics HOT 1
- Issue with getting error log after uploadind CSV file HOT 2
- A template language occurred when sending a message (var parsing error) HOT 2
- Problems with mailjet api & php wrapper HOT 2
- Template Section IDs / Names HOT 27
- Emails not being received HOT 1
- 404 Readme.md link to api keys HOT 1
- vendor/autoload.php is missing
- API TIME OUT HOT 3
- How to set the interface used for requests (CURLOPT_INTERFACE) ? HOT 1
- Incompatibility with PHP 8.1 [http_build_query(): Passing null to parameter #2 ($numeric_prefix) of type string is deprecated] HOT 1
- Send API fails from time to time with error HTTP/2 stream 0 was not closed cleanly: CANCEL (err 8) HOT 3
- cURL error 35 when trying to use API in production env
- SSL_ERROR_SYSCALL in connection to api.mailjet.com:443 connecting from Google App Engine HOT 2
- Codacy link in readme is broken HOT 1
- Compatibility HOT 2
- Resource Contacts missing HOT 2
- v1.6.2 breaks Symfony 6.4 projects HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from mailjet-apiv3-php.