500 Error Using Messages Template with Json

323 views
Skip to first unread message

Rich

unread,
Jul 7, 2012, 12:40:09 AM7/7/12
to mandrill-a...@googlegroups.com
Could someone look at my code and tell me what I'm doing wrong?  The API call is made fine but comes back with a server error.  I couldn't find examples of working code to check this against, but I think the server must be rejecting it due to my syntax, even though the json is valid.
Also, I did create template and it is copied from MailChimp to Mandrill.

NSDictionary *toDict = [NSDictionary dictionaryWithObjectsAndKeys:
                                     
@"jsmith@yahoo.com", @"email",
                                     
@"Richie Rich", @"name",
                                       
nil];
       
NSMutableArray *toArray = [NSMutableArray arrayWithObject:toDict];
       
NSDictionary *messageDict = [NSDictionary dictionaryWithObjectsAndKeys:
                                       
@"Your co-worker invited you to a meeting on Zute", @"subject",
                                       
@"custome...@mydomain.com", @"from_email",
                                       
@"Zute", @"from_name",
                                        toArray
, @"to",
                                       
@"true", @"track_opens",
                                       
@"true", @"track_clicks",
                                       
@"true", @"auto_text",
                                       
@"true", @"url_strip_qs",
                                 
                                         
nil];
       
       
NSDictionary *templateDict = [NSDictionary dictionaryWithObjectsAndKeys:
                                     
@"example name", @"name",
                                     
@"example content", @"content",
                                     
nil];
       
NSMutableArray *templateArray = [NSMutableArray arrayWithObject:templateDict];

       
NSString *mailchimpAPI = @"a8sdf68a7sdfTHIS-IS-NOT-MY-REAL-API-KEY";
       
NSDictionary *masterDictionary = [NSDictionary dictionaryWithObjectsAndKeys:
                                          mailchimpAPI
, @"key",
                                         
@"Zute Meeting Invitation", @"template_name",
                                          templateArray
, @"template_content",
                                          messageDict
, @"message",
                                         
nil];

       
        chimpmailClient
= [RKClient clientWithBaseURL:[RKURL URLWithBaseURLString:@"https://mandrillapp.com"]];
       
NSLog(@"I am your RKClient for MailChimp : %@", [RKClient sharedClient]);
        client
.requestQueue.showsNetworkActivityIndicatorWhenBusy = YES;
       
[client setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];

       
NSError *error2;
       
NSData *chimpmailData = [NSJSONSerialization dataWithJSONObject:masterDictionary options:0 error:&error2];
       
NSString *chimpmailString = [[NSString alloc] initWithData:chimpmailData encoding:NSUTF8StringEncoding];
       
RKParams *params3 = [RKRequestSerialization serializationWithData:[chimpmailString dataUsingEncoding:NSUTF8StringEncoding]MIMEType:RKMIMETypeJSON];
       
[chimpmailClient post:@"/api/1.0/messages/send-template.json" params:params3 delegate:self];




Rich

unread,
Jul 7, 2012, 8:01:26 AM7/7/12
to mandrill-a...@googlegroups.com
Here is the JSON:
{"template_name":"Zute Meeting Invitation","key":"as8df8as7dfTHIS-IS-NOT-MY-REAL-API-KEY","template_content":[{"content":"example content","name":"example name"}],"message":{"subject":"Your co-worker invited you to a meeting on Zute","from_email":"custome...@mydomain.com","track_opens":"true","auto_text":"true","from_name":"Zute","to":[{"name":"Richie Rich","email":"jsm...@yahoo.com"}],"url_strip_qs":"true","track_clicks":"true"}}

Rich

unread,
Jul 7, 2012, 8:32:03 AM7/7/12
to mandrill-a...@googlegroups.com
I solved it!   I was using my MailChimp API key, didn't realize there was a separate key for Mandrill in my account.  Put the right one in a voila, worked like a charm.
Reply all
Reply to author
Forward
This conversation is locked
You cannot reply and perform actions on locked conversations.
0 new messages