jessica dussault

Patching the Facebook Business SDK

Date
10 June, 2026
Category
code
Tags
bugfix

A few months ago, I was working on a project that needed to access the Facebook marketing API. It became clear very quickly that Facebook does not care about the developer experience. Every step felt like pulling teeth. It was marginally worse for Ruby developers, because the business SDK is auto-generated, un-monitored, and it turns out NOT FUNCTIONAL.

The README says that this is how you update an object (and in case you're wondering, they're the ones with a mix of single and double quotes, not me):

ad_account = FacebookAds::AdAccount.get('act_1234', 'name')
ad_account.name = "New Ad Account"
ad_account.save

Sounds easy enough, very rails-esque, but when you try to use the object again you get this:

FacebookAds::ClientError Syntax error "Field status specified more than once."

Cool, uh, why?

Fortunately, somebody had already tracked this down in an open issue. The problem is that some of the fields are stored as string attributes and others are stored as symbols and you can end up with both "name" and :name.

The (gross) solution

Now, would I rather that facebook fix their SDK so that it was actually usable? Sure I would! But it didn't look like that was going to happen anytime soon, and I closed my PR when I realized that I would have to sign a bunch of paperwork to contribute. So what I ended up doing instead was putting in a patch.

In config/initializers/facebook_ads.rb :

FacebookAds::Fields::ClassMethods.module_eval do
  def define_writer(name)
    define_method("#{name}=") do |val|
      changes[name] = val
      @__all_fields.add(name.to_sym)
    end
  end
end

I ended up just mapping all the fields to a symbol so that the new incoming ad_account.name type symbols would overwrite them. I don't know if it's a very good solution but it got us unstuck, so I'll take the win.