pacely / mailchimp-api-v3 Goto Github PK
View Code? Open in Web Editor NEWAPI client for Mailchimp API v3
License: MIT License
API client for Mailchimp API v3
License: MIT License
This examples are misleading, i'm trying to use it as you explain:
public function suscribe(Request $request) {
$result = $MC::request('lists', [
'fields' => 'lists.id,lists.name,lists.stats.member_count',
'offset' => 10,
'count' => 10
]);
}
Also tried with $mc->request() with no success. How it is supossed to be used?, and please don't tell me to go to the documentation, i'm coming from there.
It seems that your wrapper somewhere converts arrays to objects which cause trouble in my case. Mailchimp api needs for some reason an array and I am not able to pass it via your Wrapper.
Do you have any recommendations?
The following code in makeRequest will discard the error information in a call
private function makeRequest($resource, $arguments, $method)
{
try {
$options = $this->getOptions($method, $arguments);
$response = $this->client->{$method}($this->endpoint . $resource, $options);
$collection = new Collection(
json_decode($response->getBody())
);
if ($collection->count() == 1) {
return $collection->collapse();
}
return $collection;
} catch (ClientException $e) {
throw new Exception($e->getResponse()->getBody());
} catch (RequestException $e) {
$response = $e->getResponse();
if ($response instanceof ResponseInterface) {
throw new Exception($e->getResponse()->getBody());
}
throw new Exception($e->getMessage());
}
}
Since you discard the info that ClientException contains we cannot see what kind of Error mailchimp throws. For instance we need to create a customer if it does not exist, which we need to check if the response status is 404.
The PUT method is not enough here since it will throw if the email has changed.
Is it possible to expose the raw ClientException here instead of discarding it (i.e. throw $e) or what is the reasoning about doing this?
Hi
I'm having trouble initiating this package correctly in laravel 5.1. Probably a PICNIC error but need some help!
I've installed the package, added the service provider and facade per the docs. I've published the config file and added my apikey.
However trying the sample code for a simple request of lists I'm coming up with this error:
Call to undefined method Mailchimp\MailchimpFacade::request()
Here's my code:
$mc = new MC;
$result = $mc->request( 'lists' , [
'fields' => 'lists.id,lists.name,lists.stats.member_count' ,
'offset' => 0 ,
'count' => 10
] );
ddd($result);
If I try and initiate mailchimp direct I am able to get the list as expected but that appears to be bypassing the package and I'd rather use the facade and not have to worry about pulling the apikey etc.
This works:
$mc = new \Mailchimp\Mailchimp('xxxxx xxxxx');
$result = $mc->request( 'lists' , [
'fields' => 'lists.id,lists.name,lists.stats.member_count' ,
'offset' => 0 ,
'count' => 10
] );
What am I doing wrong? How can I use the facade correctly?
Thanks
Hi Chris,
I have added
"require": {
"pacely/mailchimp-apiv3": "dev-master"
}
to composer.json as
{
"name": "pacely/mailchimp-apiv3",
"description": "Simple API wrapper for Mailchimp API V3",
"version": "0.1",
"type": "library",
"keywords": ["mailchimp", "api", "php", "v3"],
"license": "MIT",
"authors": [
{
"name": "Chris Magnussen",
"email": "[email protected]"
}
],
"autoload": {
"psr-4": {
"Mailchimp": "src/"
}
},
"require": {
"php": ">=5.4.0",
"guzzlehttp/guzzle": "~5.0",
"illuminate/support": "~5.0"
},
"require-dev": {
"phpspec/phpspec": "~2.2"
},
"minimum-stability": "dev",
"require": {
"pacely/mailchimp-apiv3": "dev-master"
}
}
When I try to do
php composer.phar update, it shows an error saying 'The requested package pacely/mailchimp-apiv3 0.1 could not be found.'
There is a bug in the MailchimpFacade.php - needs to return "Mailchimp\Mailchimp" rathern than just "Mailchimp"
Hi,
I was just looking for examples to do filtering in lists and I spotted this repo in GitHub, thanks for the contribution.
I'm not using this code, but something else, however this example doesn't seem correct:
$result = $mc->post('lists', [
'name' => 'New list',
'permission_reminder' => 'You signed up for updates on Greeks economy.',
'email_type_option' => false,
'contact' => [
'company' => 'Doe Ltd.',
'address1' => 'DoeStreet 1',
'address2' => '',
'city' => 'Doesy',
'state' => 'Doedoe',
'zip' => '1672-12',
'country' => 'US',
'phone' => '55533344412'
],
'campaign_defaults' => [
'from_name' => 'John Doe',
'from_email' => '[email protected]',
'subject' => 'My new campaign!',
'language' => 'US'
]
]);
From what I understand you also need to set visibility 'prv' or 'pub'
and set use_archive_bar true or false
.
Hi,
The last changes (e.g. setting Guzzle options + fixing multiple calls in a row reusing the object) are not in a release yet, so I need to require dev-master (which I don't like for consecutive updates). Could you file a new release consisting of these helpful functions?
Thanks!
Hello,
When calling the /lists/{list_id} resource using the GET method, I'm getting this error :
array_merge(): Argument #2 is not an array
Line 79, the collapse() method is throwing that error :
return $method == 'get' ? $collection->collapse() : $collection;
When I'm just returning $collection, it's working. I'm not sure how to fix that?
Thanks for making that library, very helpful! :)
Unless there's something that I've overlooked, the requirements for mailchimp-api-v3 are listed as follows:
"require": {
"php": ">=5.5.0",
"guzzlehttp/guzzle": "~5.0|~6.0",
"illuminate/support": "~5.0"
},
While the requirements for "illuminate/support" are as follows:
"require": {
"php": ">=5.6.4",
"ext-mbstring": "",
"doctrine/inflector": "~1.1",
"illuminate/contracts": "5.4.",
"paragonie/random_compat": "~1.4|~2.0"
},
So clearly php >= 5.6.4 is required. I changed the "illuminate/support" version to "5.2.x-dev" for it to work in PHP 5.5.9.
Hi,
I'm starting to use your package, and the first thing I noticed was that Campaigns (I've yet to try with lists) don't care if I use pagination.
My call looks like this:
$res = $mc->get('/campaigns/',array(
'fields' => 'campaigns.id,campaigns.name',
'offset' => 10,
'count' => 20
));
But it always return the firts 10 elements.
Am I doing something wrong?
The same operations work perfectly with subscribers management.
TIA,
Riccardo
I try to get response through your package, but I can't get response status, detail when data errors. Can you advice me?
Hi guys, I'm trying to get this wrapper running on my local dev box but when trying your example code from the readme I'm seeing the following error:
Exception in Mailchimp.php line 170:
cURL error 60: SSL certificate problem: unable to get local issuer certificate (see http://curl.haxx.se/libcurl/c/libcurl-errors.html)
Is there any way I can enforce non-ssl or is this a requirement from Mailchimp? Thanks
Guzzle is actually sending async requests by default, it would be great if you can support async flow. Thanks!
Hello!
I'm not sure if I'm just being an idiot, but I can't get batches to work. Any idea why this code would always return an error 400, 'Schema describes object, array found instead'?
public function update(Request $request) {
$orders = $request->orders;
$list = $request->list;
$operations = [];
foreach($orders as $order) {
$data = [
'email_address' => $order['email'],
'status' => 'Subscribed'
];
$operations[] = [
'method' => 'POST',
'path' => 'lists/' . $list . '/members',
'body' => json_encode($data)
];
}
$response = $this->mc->request('batches', [
$operations
], 'post');
return Response::json([
'message' => $response
], 200);
}
What PHP version is required for this class?
Hi, is this package still maintained?
I'll gladly submit a PR with some exception handling if it is.
(that is, throwing more exception types instead of PHP's base \Exception
, or at least assigning the Exception
with the response data as an array instead of a JSON encoded string).
Hi @ChrisRM,
Thanks for putting this together - very handy.
I'm trying to run a POST request, but seems I cannot get my arguments right. The GET request works fine:
$lists = $mc->request('lists/{list_id}/members', [
'fields' => 'members.email_address,members.status',
'count' => 30
]);
How would it look at as a POST request. I want to subscribe an email programmatically. Thanks very much!
This works:
$this->mc = new \Mailchimp\Mailchimp($this->apiKey);
$lists = $this->mc->request('lists',array(
'count' => 100,
'fields'=>'lists.id,lists.name'
),'GET');
var_dump($lists);
$this->mc = new \Mailchimp\Mailchimp($this->apiKey);
$lists2 = $this->mc->request('lists',array(
'count' => 100,
'fields'=>'lists.id,lists.name'
),'GET');
var_dump($lists2);
Re-initializing the Mailchimp object for each call doesn't seem like it should be necessary, though? This fails:
$lists = $this->mc->request('lists',array(
'count' => 100,
'fields'=>'lists.id,lists.name'
),'GET');
var_dump($lists);
$lists2 = $this->mc->request('lists',array(
'count' => 100,
'fields'=>'lists.id,lists.name'
),'GET');
var_dump($lists2);
Here's the exception thrown:
Fatal error: Uncaught exception 'Exception' with message '<HTML><HEAD>
<TITLE>Bad Request</TITLE>
</HEAD><BODY>
<H1>Bad Request</H1>
Your browser sent a request that this server could not understand.<P>
Reference #7.116c1160.1436314067.0
</BODY>
</HTML>
First off, fantastic work! Thanks for writing this much needed wrapper. A+
I'm trying to use this wrapper to get a list of interest categories so then I can set them on the user update, but it looks like the wrapper retains the fields param for the second call and throws an error.
Is there a reset method or a recommended way to handle this without a second instantiation of the wrapper?
$service = new Mailchimp\Mailchimp($api_key);
$all_interests = $service->get("lists/$list_id/interest-categories/$interest_category_id/interests", array(
'fields' => 'interests.id,interests.name'
));
//some logic to figure out what interests for user
$updated_user = $service->patch("lists/$list_id/members/$user_id", array(
'merge_fields' => array(
'FNAME' => $first_name,
'LNAME' => $last_name
),
'interests' = $user_interests
));
throws error
Error on line 162
Message: {"type":"http://developer.mailchimp.com/documentation/mailchimp/guides/error-glossary/","title":"Requested Fields Invalid","status":422,"detail":"Some of the fields requested were invalid: interests.id,interests.name","instance":""}
File: /vagrant/intranet/application/vendor/pacely/mailchimp-apiv3/src/Mailchimp.php
I need to know how I can make a request to the APi to meet the last subscribers. This request will be made every hour if is possible
Does this package only work on Laravel version 5.x? Wasn't quite sure from the documentation.
Thanks
Hi
Could you please force update version at packagist https://packagist.org/packages/pacely/mailchimp-apiv3 ?
Composer doesn't see version 1.0.0.
Thanks
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.