Giter Site home page Giter Site logo

mailchimp / apiv3-examples Goto Github PK

View Code? Open in Web Editor NEW
85.0 85.0 34.0 12 KB

Straight-forward examples of working with v3 the MailChimp API without any wrapper libraries

Home Page: https://mailchimp.com/developer/

License: BSD 3-Clause "New" or "Revised" License

Python 58.67% Ruby 41.33%

apiv3-examples's People

Contributors

bryceroney avatar mc-hannah-morrison avatar toomuchpete avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

apiv3-examples's Issues

Every operation in batch errored "resource not found" but list exists

Note: posting without batch to the same resource (list) succeeds!

With batch:
O:8:"stdClass":1:{s:10:"operations";a:1061:{i:0;O:8:"stdClass":3:{s:6:"method";s:4:"POST";s:4:"path";s:25:"/lists/5720994ca9/members";s:4:"body";s:66:"{"email_address":"[email protected]","status":"subscribed"}";}i:1;O:8:"stdClass":3:{s:6:"method";s:4:"POST";s:4:"path";s:25:"/lists/5720994ca9/members";s:4:"body";s:67:"{"email_address":"[email protected]","status":"subscribed"}";}i:2;O:8:"stdClass":3:{s:6:"method";s:4:"POST";s:4:"path";s:25:"/lists/5720994ca9/members";s:4:"body";s:66:"{"email_address":"[email protected]","status":"subscribed"}";}...

Response:
O:8:"stdClass":9:{s:2:"id";s:10:"734a070347";s:6:"status";s:7:"pending";s:16:"total_operations";i:0;s:19:"finished_operations";i:0;s:18:"errored_operations";i:0;s:12:"submitted_at";s:25:"2016-03-30T14:33:36+00:00";s:12:"completed_at";s:0:"";s:17:"response_body_url";s:0:"";s:6:"_links";a:2:{i:0;O:8:"stdClass":5:{s:3:"rel";s:6:"parent";s:4:"href";s:42:"https://us12.api.mailchimp.com/3.0/batches";s:6:"method";s:3:"GET";s:12:"targetSchema";s:65:"https://us12.api.mailchimp.com/schema/3.0/Batches/Collection.json";s:6:"schema";s:70:"https://us12.api.mailchimp.com/schema/3.0/CollectionLinks/Batches.json";}i:1;O:8:"stdClass":4:{s:3:"rel";s:4:"self";s:4:"href";s:53:"https://us12.api.mailchimp.com/3.0/batches/734a070347";s:6:"method";s:3:"GET";s:12:"targetSchema";s:63:"https://us12.api.mailchimp.com/schema/3.0/Batches/Instance.json";}}}
Batch status:
{"id":"734a070347","status":"finished","total_operations":1061,"finished_operations":1061,"errored_operations":1061,"submitted_at":"2016-03-30T14:33:36+00:00","completed_at":"2016-03-30T14:33:51+00:00","response_body_url":"https://mailchimp-api-batch.s3.amazonaws.com/734a070347-response.tar.gz?AWSAccessKeyId=AKIAJWOH5BECJQZIEWNQ&Expires=1459349066&Signature=cDyRNiQirQ2kdDAnZBa20%2Fuyou8%3D","_links":[{"rel":"parent","href":"https://us12.api.mailchimp.com/3.0/batches","method":"GET","targetSchema":"https://us12.api.mailchimp.com/schema/3.0/Batches/Collection.json","schema":"https://us12.api.mailchimp.com/schema/3.0/CollectionLinks/Batches.json"},{"rel":"self","href":"https://us12.api.mailchimp.com/3.0/batches/734a070347","method":"GET","targetSchema":"https://us12.api.mailchimp.com/schema/3.0/Batches/Instance.json"}]}

In response_body_url files all:
[{
"status_code":400,
"operation_id":null,
"response":"{
"type":"http://developer.mailchimp.com/documentation/mailchimp/guides/error-glossary/",
"title":"Invalid Resource",
"status":400,
"detail":"The resource submitted could not be validated. For field-specific details, see the 'errors' array.",
"instance":"",
"errors":[{
"field":"",
"message":"Schema describes object, NULL found instead"
}]
}"
},
...
]

Email Update - PATCH

Having trouble trying to update the email. Is there something special I should be putting into the body? 2.0 api was way easier updating the email field.

Using Node JS. I can update the status field but not email_address for some odd reason.

Code:

var options = {
baseUrl: 'https://us9.api.mailchimp.com',
uri: '/3.0/lists/listid/members/insertmemberid',
method: 'PATCH',
headers: {
'Content-Type': 'application/json',
'Authorization': 'apikey insertapikey'
},
body: {
'email_address': '[email protected]',
'status': 'subscribed'
},
json: true
};

API v3 Python Client?

We've been comfortably using API v2 via an official Python client (https://pypi.python.org/pypi/mailchimp) for the past year or so.

However, I haven't yet to found any equivalent API v3 python client library or seeing any signs of the official python client lib adopting the support for API v3. And in this repo's API v3 Python code examples, there's quite a bit of boilerplate code to deal with API v3's REST API via Requests and JSON.

Is mailchimp working on either to improve upon the existing Python client lib for v2 or building a new python client for v3 or Python client is simply not coming back after you sunset API v2?

Would love to hear the roadmap for that, thanks!

Add subscriber to list without sending confirmation

I try to subscribe an address as document description here http://developer.mailchimp.com/documentation/mailchimp/guides/manage-subscribers-with-the-mailchimp-api/ but mailchimp still send subscriber confirmation email

POST /3.0/lists/2cd35fd050/members/ HTTP/1.1
Host: us12.api.mailchimp.com
Authorization: Basic xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Cache-Control: no-cache
Postman-Token: 94f32fa3-935b-1e28-1049-b5f99499b5e2

{
    "email_address": "[email protected]",
    "status": "subscribed",
    "merge_fields": {
        "FNAME": "Test",
        "LNAME": "Account"
    }
}

Response data

{
  "id": "de25a78407a2152fba1a8f2b6e4b0b2e",
  "email_address": "[email protected]",
  "unique_email_id": "4af9adf7ff",
  "email_type": "html",
  "status": "pending",
  "merge_fields": {
    "FNAME": "Test",
    "LNAME": "Account"
  },
  "stats": {
    "avg_open_rate": 0,
    "avg_click_rate": 0
  },
  "ip_signup": "",
  "timestamp_signup": "",
  "ip_opt": "123.24.170.224",
  "timestamp_opt": "2016-04-02T13:41:24+00:00",
  "member_rating": 2,
  "last_changed": "2016-04-02T13:41:24+00:00",
  "language": "",
  "vip": false,
  "email_client": "",
  "location": {
    "latitude": 0,
    "longitude": 0,
    "gmtoff": 0,
    "dstoff": 0,
    "country_code": "",
    "timezone": ""
  },
  "list_id": "2cd35fd050",
  "_links": [
    {
      "rel": "self",
      "href": "https://us12.api.mailchimp.com/3.0/lists/2cd35fd050/members/de25a78407a2152fba1a8f2b6e4b0b2e",
      "method": "GET",
      "targetSchema": "https://us12.api.mailchimp.com/schema/3.0/Lists/Members/Instance.json"
    },
    {
      "rel": "parent",
      "href": "https://us12.api.mailchimp.com/3.0/lists/2cd35fd050/members",
      "method": "GET",
      "targetSchema": "https://us12.api.mailchimp.com/schema/3.0/Lists/Members/Collection.json",
      "schema": "https://us12.api.mailchimp.com/schema/3.0/CollectionLinks/Lists/Members.json"
    },
    {
      "rel": "update",
      "href": "https://us12.api.mailchimp.com/3.0/lists/2cd35fd050/members/de25a78407a2152fba1a8f2b6e4b0b2e",
      "method": "PATCH",
      "schema": "https://us12.api.mailchimp.com/schema/3.0/Lists/Members/Instance.json"
    },
    {
      "rel": "upsert",
      "href": "https://us12.api.mailchimp.com/3.0/lists/2cd35fd050/members/de25a78407a2152fba1a8f2b6e4b0b2e",
      "method": "PUT",
      "schema": "https://us12.api.mailchimp.com/schema/3.0/Lists/Members/Instance.json"
    },
    {
      "rel": "delete",
      "href": "https://us12.api.mailchimp.com/3.0/lists/2cd35fd050/members/de25a78407a2152fba1a8f2b6e4b0b2e",
      "method": "DELETE"
    },
    {
      "rel": "activity",
      "href": "https://us12.api.mailchimp.com/3.0/lists/2cd35fd050/members/de25a78407a2152fba1a8f2b6e4b0b2e/activity",
      "method": "GET",
      "targetSchema": "https://us12.api.mailchimp.com/schema/3.0/Lists/Members/Activity/Collection.json"
    },
    {
      "rel": "goals",
      "href": "https://us12.api.mailchimp.com/3.0/lists/2cd35fd050/members/de25a78407a2152fba1a8f2b6e4b0b2e/goals",
      "method": "GET",
      "targetSchema": "https://us12.api.mailchimp.com/schema/3.0/Lists/Members/Goals/Collection.json"
    },
    {
      "rel": "notes",
      "href": "https://us12.api.mailchimp.com/3.0/lists/2cd35fd050/members/de25a78407a2152fba1a8f2b6e4b0b2e/notes",
      "method": "GET",
      "targetSchema": "https://us12.api.mailchimp.com/schema/3.0/Lists/Members/Notes/Collection.json"
    }
  ]
}

400 Bad Request deleting Cart lines

I've got a Rails integration for tracking abandoned cart activity in Spree, but lately, it seems carts are failing to update -- specifically when an item is removed from the user's cart.

We've noticed that every DELETE request sent to /ecommerce/stores/{store_id}/carts/{cart_id}/lines/{line_id} returns a 400 error with In order to delete this line item, delete the parent resource.

The implication here is that if a customer deletes an item from their cart, in order to track that in MailChimp, we need to delete their entire cart and start over, which seems problematic.

Is there a different process we should be using to sync line item deletes?

Create list doesn't work

Hi !
Thanks in advance for your answer and the job you did so far ;)

I try, from your 'lists.py' to make a "createList.py' (code bellow) but I always receive the same 400 bad request from mailchimp api. Would you take a look on my code please ?


Code:

from config import MailChimpConfig
import requests, json

config = MailChimpConfig()

endpoint = config.api_root + "/lists"
headers = {'Authorization': 'apikey ' + config.apikey}

params = {
'name': 'List API python',
'permission_reminder': 'This is an API test',
'email_type_option': False,
'contact': {
'company': 'My Company',
'address1': '',
'city': 'Paris',
'state': '',
'zip': '75000',
'country': '54'
},
'campaign_defaults': {
'from_name': 'Shetza',
'from_email': '[email protected]',
'subject': 'Test from API',
'language': 'fr'
}
}

response = requests.post(endpoint, headers=headers, params=params)
body = response.json()

if (response.status_code != 200):
print "Error: {} {}".format(str(response.status_code), response.reason)
print json.dumps(body, indent=4)
else:
print 'ok'


Response:

Error: 400 Bad Request
{
"status": 400,
"errors": [
{
"field": "",
"message": "Schema describes object, NULL found instead"
}
],
"title": "Invalid Resource",
"detail": "The resource submitted could not be validated. For field-specific details, see the 'errors' array.",
"instance": "74583a62-11e0-403e-9c4a-d53a61439933",
"type": "http://kb.mailchimp.com/api/error-docs/400-invalid-resource"
}

PHP/WP Example for post to /lists/[id]/members/

Seems like mailchimp ignores sent ip_signup and timestamp_signup

For basic PHP i would suggest using file_get_contents with stream_context_create, and for Wordpress I would suggest using wp_remote_post.

VERY Basic (working, except for ip_signup and timestamp_signup) WP Code example:

$apiKey = trim(get_option('mailchimp_api_key'));
$listID = trim($_POST['id']);
$email = trim($_POST['email']);

$data = array(
    'email_address' => $email,
    'status' => 'subscribed',
    'ip_signup' => $_SERVER['REMOTE_ADDR'],
    'timestamp_signup' => $_SERVER['REQUEST_TIME'],
);

$body = json_encode($data);

$opts = array(
    'headers' => array(
        'Content-Type' => 'application/json',
        'Authorization' => 'apikey ' . $apiKey
    ),
    'body' => $body
);

$apiKeyParts = explode('-', $apiKey);
$shard = $apiKeyParts[1];

$url = 'https://' . $shard . '.api.mailchimp.com/3.0/lists/' . $listID . '/members/';

$response = wp_remote_post( $url, $opts );

if ( is_wp_error( $response ) ) {
    $result = $response->get_error_message();
} else {
    // DEBUG
    $result = print_r($response, true);
}

return $result;

.NET

I am trying to work with MailChimp v3 API without using any wrappers (although, only v2 wrappers exist for .NET).

Is this something you could build as an example?

Thank you in advance...

Automated- Cart abandoned emails in queue but not sending?

I see users in queue for these automation, but the emails aren't actually sending.
Is there a log somewhere or anything else perhaps to assist with troubleshooting?

Here's the data i'm sending using PHP/Curl:
$data = [ 'id' => $email, 'customer' => array( 'id' => $email, 'email_address' => $email, 'opt_in_status' => true, ), 'currency_code' => 'USD', 'order_total' => 80, 'lines' => array( array( 'id' => 'cleaning', 'product_id' => 'cleaning', 'product_variant_id' => 'cleaning', 'quantity' => 1, 'price' => 80, ) ), ];

$email is set and valid, and the items inside my lines array are valid as well, and stored within my connected store - Is there missing data required?

Making a GET to my /store/carts returns the appropriate carts, but the emails wont send for whatever reason... any insights?

Please merge the PHP example code

Hey Chimps, the old API goes away at the end of the year - we really ought to have some PHP examples that are actually merged in to this repo. Starting with one of the two PRs that have been outstanding since January seems like not a bad way to go - what say you?

Issue in search campaign api

HI,
The issue was that I don't get any responses while i just sending first letter of the campaign name in the query attribute of the search campaign api. it sends me responses only when i types more than half of the name of the campaign.
the same issue is find with search contact api . please, give me any idea to fix the issue

InsecureRequestWarning and placing the api key

Hi. Thanks for this one.

I wonder about the InsecureRequestWarning due to HTTPS. Is it ok to suppress that?

And i wonder if I could add the api key directly response = requests.get(endpoint, auth=('apikey', config.apikey), verify=False) in a function? (security)

I am using Django and are rendering the respons in a template.

How to get interest id used in conditions for creating segments?

Hello,

this is not really an issue, I just need to create segment related to a group (interest), and I don't know where the interest id comes from, since it's not the hex id I'm used to, but rather a 5-digit-integer. Are they even related? Help me out here?

Python lacks POST request example

e.g. Maybe one for adding members:

mailchimp_api_root = "https://" + shard + ".api.mailchimp.com/3.0/"
endpoint = mailchimp_api_root + "lists/" + mailchimp_list_id + "/members/"
response = requests.post(endpoint, auth=('apikey', mailchimp_api_key), json=payload, verify=False)

NodeJS examples

Hi,

Any chance that you could provide examples in NodeJS?

Thanks,
/t

404 ?

Using this with correct campaign_id and url

$result = $MailChimp->put("campaigns/$campaign_id/content", [
'url' => $url
]);

results always in:
"Resource Not Found,404,The requested resource could not be found."
?

ASP.NET PATCH

I am trying to get http 'PATCH' working on mailchimp API 3 using ASP.NET. I have no problem with 'GET' and 'POST'.

I can get a 'PATCH' call to be accepted by the API but the data does change. The same call using the API playground does change the data.

I see from a previous issue that mailchimp do not have any .net developers, so to help in this issue I would like mailchimp to add some test calls to the api to allow developers to get their interface working. For instance, the test 'PATCH' call would send some fixed json to the mailchimp server and if the data is correct the server returns a 200 status code with a suitable json message. If the data is incorrect the server should return a suitable error message.

Note: to use 'PATCH' in asp.net you require .net 4.5+. Also using the restSharp dll allows you do the 'PATCH' call in a few lines of code.

Thanks.

Your Campaign is not ready to send

Hello,

I am new to Mailchimp
I have created a new MailChimp account and trying to send a test campaign using PHP.
I am getting following errors in response

stdClass Object ( [type] => http://developer.mailchimp.com/documentation/mailchimp/guides/error-glossary/ [title] => Bad Request [status] => 400 [detail] => Your Campaign is not ready to send. [instance] => 2f516d17-5ace-4628-b2b4-e71878088bb2 )

My domain is already verified to send emails..
image

i am trying to authenticate domain using Cname and txt records but it is not working due to any reasons.

add tags to list member

What's the "right" way to add/remove tags to list members.
I tried almost all of the possibilities.

  1. using tags as array in Member instance and URL lists/{0}/members/{1} using PUT/PATCH/POST : no luck
  2. using the url lists/{0}/members/{1}/tags and using POST with tag array in body of request: no luck

Not a clear answer ...

A foreign character é causes statusCode 400

I sent POST http request with this body to "/lists/{list_id} | Batch sub/unsub list members":

{
"members":
  [{"email_address":"[email protected]",
  "status":"subscribed",
  "merge_fields":{"FNAME":"César Octavio"}
  }],
"update_existing":true
}

and got

{
  "type":"http://developer.mailchimp.com/documentation/mailchimp/guides/error-glossary/",
  "title":"Invalid Resource",
  "status":400,
  "detail":"The resource submitted could not be validated. For field-specific details, see the 'errors' array.",
  "instance":"bae54115-1fd9-4d46-b203-775f0fdb063e",
  "errors":[{"field":"","message":"Schema describes object, NULL found instead"}]
}

I think it is this Spanish character é in "César Octavio" causes the issue. Because when I move it out, it works properly.

How can I fix it ? I worked a whole day trying to get it done but failed.

HTTP Code 409 for existing email, not 400

Hello

I don't know if this is the right place to submit this, but...

When subscribing an email to a list via the API which is already present, the server returns 400. 400 is not appropriate for a request that was correctly formed. It should respond with 409 Conflict instead. This would also make it easier for APIs to distinguish between a duplicate and an actual request error.

Just my 2 cents.

Subscribes to MailChimp API v3 fail with 500 error in specific cases (malformatted email, blacklisted domain,...)

We see an issue with the PUT method on the /members endpoint that generates 500 errors: This was already supported to the API support team, but I'm going to document it here, as well, as other developers are likely to run into the same situation.

When using the PUT method to add or update a member, the following cases will lead to a 500 error from the MailChimp API:

  • the email address contains a comma
  • the email contains a "." at the end
  • the email address is on a domain that has been blacklisted by MailChimp (e.g. googlegroups.com)

The error response is in all cases:
{
"type": "about:blank",
"title": "Internal Server Error",
"status": 500,
"detail": "A deep, internal error has occurred during the processing of your request. Please contact support.",
"exception": "EXCEPTIONID",
"instance": "INSTANCEID"
}

We assume that MailChimp is putting all emails through a validation check, but the result of the validation check is not properly supported in the API v3, so we get a 500 back. This is really bad, as we can of course check for commas and "."s in malformatted emails, but the blacklisted domains are not public and we can't check. A 500 response is the wrong answer to it and we need a proper error code to do the appropriate error handling on our side.

How can the error be reproduced? here are the example payloads of these cases:

Example payload ("," in email address)
{
"email_address": "firstname.lastname@maildomain,com",
"status_if_new": "subscribed",
"merge_fields": {
"FNAME": "Bjoern",
"LNAME": "Sjut"
}
}

Example payload ("." in email address)
{
"email_address": "[email protected].",
"status_if_new": "subscribed",
"merge_fields": {
"FNAME": "Bjoern",
"LNAME": "Sjut"
}
}

Example payload (blacklisted domain)
{
"email_address": "[email protected]",
"status_if_new": "subscribed",
"merge_fields": {
"FNAME": "Bjoern",
"LNAME": "Sjut"
}
}

Is there a way to remove a Tag from mailchimp

Hi,

This might not be the right place to ask but let me know where we can get some help about this issue...

I'm trying to provide some tags to my contacts using mailchimp API.

I can add them fine by making a call to "add_list_members" and providing the "tags" field for each user.

But this field always adds more tags, it doesn't remove the previously added tags.

So if I call "add_list_members" and add user [email protected] to the following tags: "Tag one" "Tag two"

And then make a new call to "add_list_members" for the same user only providing "Tag one", the other tag ("Tag two") will still be there.

Sure I can run a call for each member to remove its tags, but this doesn't seem reasonable.

Is there a way to remove a particular Tag using the API, so that specific Tag is no longer assigned to any user? That way I can run it before "add_list_members" and everything should work fine.

automations unexcepted respond

Hi,

I was trying to play with the ApiV3 of mailchimp.
I didn't wanted to recode everything, rewrappe everything, so i did a little tricks,

class Automations(object):
  def __init__(self, master):
    self.master = master

  def automations(self):
    """
    :return:
    """
    root = "%s%s" % (self.master.root_api3, 'automations')
    return self.master.call_api3(root, None)

  def automation(self, id="d3f0ffe2f2"):
    root = "%s%s" % (self.master.root_api3, 'automations/%s' % id)
    return self.master.call_api3(root, None)

  def pause_all_emails(self, id="d3f0ffe2f2", order='actions/pause-all-emails'):
    return self.start_all_emails(id=id, order=order)

  def start_all_emails(self, id="d3f0ffe2f2", order='actions/start-all-emails'):
    root = "%s%s" % (self.master.root_api3, 'automations/%s/%s' % (id, order))
    try:
      print "Essaye1:\n",self.master.call_api3(root, None, call_attr="post")
    except Exception, e:
      print "Exception1:\n", e
    try:
      print "Essaye2:\n", self.master.call_api3(root, None, call_attr="post")
    except Exception, b:
      print "Exception2:\n", b
    return ""

class Api3Mailchimp(Mailchimp):
  def __init__(self,  apikey=None, debug=False):
    super(Api3Mailchimp, self).__init__(apikey=apikey, debug=debug)
    self.root_api3 = 'https://us3.api.mailchimp.com/3.0/'
    self.automations = Automations(self)

  def call_api3(self, url, params=None, call_attr="get"):
        '''Actually make the API call with the given params - this should only be called by the namespace methods - use the helpers in regular usage like m.helper.ping()'''
        if params is None: params = {}
        #params['apikey'] = self.apikey
        params = json.dumps(params)
        self.log('%s to %s: %s' % (call_attr, url, params))
        start = time.time()
        r = getattr(self.session, call_attr)(url, auth=('apikey', self.apikey), data=params, headers={'content-type': 'application/json', 'user-agent': 'MailChimp-Python/3.0'})
        try:
            remote_addr = r.raw._original_response.fp._sock.getpeername() # grab the remote_addr before grabbing the text since the socket will go away
        except:
            remote_addr = (None, None) #we use two private fields when getting the remote_addr, so be a little robust against errors

        response_body = r.text
        complete_time = time.time() - start
        self.log('Received %s in %.2fms: %s' % (r.status_code, complete_time * 1000, r.text))
        self.last_request = {'url': url, 'request_body': params, 'response_body': r.text, 'remote_addr': remote_addr, 'response': r, 'time': complete_time}

        result = json.loads(response_body)

        if r.status_code != requests.codes.ok:
            raise self.cast_error(result)
        return result

if __name__ == '__main__':
  chimp = Api3Mailchimp(key, debug=True)
  print chimp.automations.automation()
  print chimp.automations.pause_all_emails()
  print chimp.automations.start_all_emails()

I have the pip mailchimp 2.0.9 package installed.
My code is working for simple request like chimp.automations.automations(), it work also with automations.automation(id='XXXXX')
but when i want to start_all_emails or pause_all_email i have to make twice the request to get different unexcepted response.

Exception1:
No JSON object could be decoded
(debug output from mailchimp Content:)
Received 400 in 17.83ms: <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&#32;&#35;7&#46;780fdd58&#46;1433168958&#46;0
</BODY>
</HTML>

Response 2:
We received an unexpected error: {u'status': 400, u'instance': u'1045824c-7dea-463a-a33c-217239580010', u'type': u'http://kb.mailchimp.com/api/error-docs/400-bad-request', u'detail': u'This automation is already paused or in a draft state.', u'title': u'Bad Request'}

And it does the same think with start, this automations is already started.
My point is firt always receive an unexcepted error Your browser sent a request that this server could not understand.<P>

based on: http://kb.mailchimp.com/api/resources/automations/automations-instance
Do i have big trouble to use mailchimp and in this case, what am i doing wrong, or the lastest API3 is not so stable ?

Post requests "gets Required fields were not provided"

I'm using postman to send post request to mailchimp. My call look like this:

{
  "operations": [
  {
   "method": "POST",
    "path": "lists/ff80d78e68/members",
    "operation_id": "my-op-id", 
    "params": {}, 
    "body": "{\"email_address\": \"[email protected]\",
    	\"status\": \"subscribed\",
    \"merge_fields\": {
        \"IMIS_ID\": \"12\",
        \"FNAME\": \"test1\",
        \"LNAME\": \"test1last\"
}
    }"
  },
    {
	
    "operation_id": "my-op-id", 
    "method": "POST",
    "path": "lists/ff80d78e68/members",
    "body": "{
    	\"email_address\": \"[email protected]\",
    	\"status\": \"subscribed\",
    \"merge_fields\": {
        \"IMIS_ID\": \"13\",
        \"FNAME\": \"test2\",
        \"LNAME\": \"test2last\"
}
    }"
  }

 ]
}

And that's what I get:

"errors": [
        {
            "field": "",
            "message": "Required fields were not provided: email_address"
        }

Anybody can tell me what I do wrong?

API Key Missing Error

I am testing out the new API for subscribing new list member.

My request:

curl -H "Content-Type: application/json" -d '{"apikey": "myUniqueAPIKeyHere", 
"email": {"email": "[email protected]"} }' 
https://us9.api.mailchimp.com/3.0/lists/uniquelistid1234/members

Response:

{"type":"http://kb.mailchimp.com/api/error-docs/401-api-key-missing",
"title":"API Key Missing","status":401,"detail":"Your request did not include an API key.",
"instance":"uniqueinstance1234"}

Can you please advise? This will help sort out what needs to happen in language-specific apps. Many thanks.

HttpCode 400 when upserting a member

Hello, I'm trying to update (both resubscribe and change some merge fields) a couple members.
Sending a PUT request to
https://<br>.api.mailchimp.com/3.0/lists/{listId}/members/{hashedEmail}
with a payload of:

{
   "email_address":"[email protected]",
   "merge_fields":{
      "LATITUDE":"17,4",
      "LONGITUDE":"12",
      "BIRTHDATE":"02\/14\/1988",
      "CREDLIM":"200,00",
      "EXRATE":"1",
      "FIRSTNAME":"Test1a",
      "NAMETITLE":"Test1 Contact1 works as Poskok",
      "GENDER":"Male",
      "LASTNAME":"Contact1a",
      "MOBILE":"+31685646587a",
      "NUMCHILD":0,
      "ACCNAME":"Test Account 1",
      "ACCNAMELK":"Test Account 1",
      "WEBURL":"https:\/\/www.test.cz",
      "ADDRESS":{
         "addr1":"somewhere",
         "addr2":"16",
         "city":"somewhere",
         "country":"NL",
         "state":"",
         "zip":"21658"
      }
   },
   "status":"subscribed",
   "status_if_new":"subscribed"
}

I'll get an error

{
   "type":"http://developer.mailchimp.com/documentation/mailchimp/guides/error-glossary/",
   "title":"Member Exists",
   "status":400,
   "detail":"[email protected] is already a list member. Use PUT to insert or update list members.",
   "instance":"85c2fcb7-c094-4d00-85d8-3db71bff8622"
}

which doesn't really make any sense - I'm already using a PUT request.
I'm sending the request like this, don't really see anything wrong:

Member member = ToMember(mappedEntity, false);
string payload = _serializer.SerializeObject(member);

using (MD5 md5 = MD5.Create())
{
    byte[] hashedMailByteArray = md5.ComputeHash(Encoding.UTF8.GetBytes(mappedEntity.Email.ToLower()));
    string hashedEmail = HttpServerUtility.UrlTokenEncode(hashedMailByteArray);
    HttpResponseMessage response = await _httpClient.PutAsync($"lists/{listId}/members/{hashedEmail}",
        new StringContent(payload, Encoding.UTF8, "application/json"));

    string responseBody = await response.Content.ReadAsStringAsync();
}

Anybody knows what I'm doing wrong? :)

.NET Updating Member

Good day,

I am trying to update a member in a list using RestSharp.

I have the following code:

var client = new RestClient("https://us4.api.mailchimp.com/3.0")
{
Authenticator = new HttpBasicAuthenticator("Basic", "MyAPIKey")
 };

var request = new RestRequest("lists/MyListID/members/EmailIDToEdit", RestSharp.Method.PATCH);              
request.AddJsonBody("{\"email_address\":\n[email protected]\"}");
request.RequestFormat = DataFormat.Json;
var queryResult = client.Execute(request);

This returns status: "StatusCode: OK, Content-Type: application/json; charset=utf-8, Content-Length: -1)"

But the data was not updated.

What could the problem be?

Am I doing something wrong?

Thanks

PHP

I'd love to see examples for PHP as well. All the PHP wrappers I've found are for v2.

Error 401 (Unauthorized) when sending a request for adding a new list member

Here is how I'm trying to send a request:

fetch('https://us17.api.mailchimp.com/3.0/lists/185415c92c/members', {
      method: 'POST',
      headers: {
        'Content-Type': 'application/json',
        'Authorization': 'anystring:8ec49e64f2041073d3fe56e0abc5fe5f-us17',
      },
      body: JSON.stringify({
        email_address: '[email protected]',
        status: 'subscribed',
      }),
      mode: 'no-cors',
    })

And I get such error:
POST https://us17.api.mailchimp.com/3.0/lists/185415c92c/members 401 (Unauthorized)

What am I doing wrong?

Node.JS wrapper update

Just wondering if there are plans or not to update the mailchimp-api module for v3 of the API.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.