I'm using Gibbon, version 2.2.1 for Mailchimp, and I'd like to be able to create an interest inside an interest group. For instance, I have users who are subscribed to a class. My interest group is "Lessons", and an interest inside that interest group would be "Foo Lesson".
I'd like to be able to add the ability to add a new class in my site's CMS, which would make an API request on after_create
.
class Lesson < ActiveRecord::Base
after_create :create_class_on_mailchimp
def create_class_on_mailchimp
require 'mailchimp_service'
mailchimp = MailchimpService.new(self)
response = mailchimp.create_class
self.interest_id = response.id
self.save
end
end
class MailchimpService
def initialize(lesson)
@lesson = lesson
@list_id = ENV['MAILCHIMP_LIST_ID']
end
def create_class
GB.lists(@list_id).interest_categories(ENV['MAILCHIMP_CLASSES_CATEGORY_ID']).interests.create(
body: {
name: 'foobar'
}
)
end
end
I keep getting this error:
Gibbon::MailChimpError:the server responded with status 404 @title="Resource Not Found",
@detail="The requested resource could not be found.",
@body={
"type" =>"http://developer.mailchimp.com/documentation/mailchimp/guides/error-glossary/",
"title" =>"Resource Not Found",
"status" =>404,
"detail" =>"The requested resource could not be found.",
"instance" =>""
},
@raw_body="{
\"type\": \"http://developer.mailchimp.com/documentation/mailchimp/guides/error-glossary/\",
\"title\":\"Resource Not Found\",
\"status\":404,
\"detail\":\"The requested resource could not be found.\",
\"instance\":\"\"
}",
@status_code=404
What this tells me is that I'm not using the correct resource name? There doesn't seem to be any documentation for this kind of request in Gibbon's limited docs, nor does it seem to be something that Mailchimp goes over. Here is a link to Mailchimp's docs that goes over the requests for interests inside interest-groupings, however, there doesn't seem to be a create option... Just read, edit, and delete. This seems silly to me, as I can imagine people would want to create interests from somewhere other than Mailchimp's dashboard.
I've tried using name
, title
, and interest_name
for the resource name, but none work. I've also tried using REST API calls, but I receive the same response.
Am I doing something wrong, or is this really something that Mailchimp doesn't offer? It'd be a huge bummer if so, since I'll be creating many classes that I want people to be able to subscribe to, and it would be a major pain to have to do this all manually.
I'm pretty sure POST works to create interests, although it does appear to be missing from the documentation. What is probably happening is that either your list ID or interest category ID is incorrect. You might want to try using the API Playground to track down the exact IDs for both of those entities.