Adding a Contact to Infusionsoft in a Ruby on Rails App ( or: Why I’ll Never do Business with “Confusionsoft” Again)

Infusionsoft is a popular CRM and that is unfortunate.

I had a specification that required new user’s emails to get sent to an Infusionsoft list.

This appears to be a relatively easy task, right? They even have a Ruby gem, which I added to my Gemfile:

gem 'infusionsoft'

Then I performed the required config:

# Added to your config\initializers file
Infusionsoft.configure do |config|
  config.api_url = ENV['INFUSIONSOFT_URL'] # example infused.infusionsoft.com
  config.api_key = ENV['INFUSIONSOFT_API_KEY']
  config.api_logger = Logger.new("#{Rails.root}/log/infusionsoft_api.log") # optional logger file
end

And to test, I ran the recommended scripts in my rails console:

# Add a new Contact
Infusionsoft.contact_add({:FirstName => 'first_name', :LastName => 'last_name', :Email => 'test@test.com'})

No dice. I get this error:

SocketError: getaddrinfo: nodename nor servname provided, or not known
from /Users/Justus/.rbenv/versions/2.1.2/lib/ruby/2.1.0/net/http.rb:879:in `initialize'

Hmm. I wonder why? I do a bit of research. Let’s check the API docs for infusionsoft:

Infusionsoft API Getting Started Documentation

 

Hmm. The ruby gem’s documentation make’s no mention of client_id or redirect_uri. Maybe they mean API key?

I continue digging and find that Infusionsoft has a “developer portal” that requires a separate registration. Maybe I’ll get what I need from there…

Nope. I register my application and receive an “application key” and a “secret”.

What is a secret? Nobody’s mentioned a secret. Why do I need a separate account to use the API? Will be able to access my original account’s campaign and how?

I have a lot of questions, so I call Infusionsoft’s technical support:

“Hi Infusionsoft, I’d like to speak with someone about integrating your API with an existing Rails App.”

“Please hold.”*

*intolerably long hold*

“I’m sorry sir, we don’t have technical support services, please checkout our community forum for assistance with the API.”

Oh, ok then.

Let’s talk about their community forums.

I register for an account. I confirm my email…

I should be able to create a thread, no?

No.

I have to wait for a moderator to confirm my registration.

Fast-forward 24 hours.

I have a deadline and need to get this card completed. My forum registration is still restricted. StackOverflow and GitHub issues have yielded no useful responses.

I make a simple email form in the infusionsoft campaign builder and examine the HTML it provides:

Webform” />

Email *

Time for a hack.

Let’s dissect this HTML. We have form data being passed via POST request. Here are the pertinent key- value pairs:

inf_form_xid : SUPER_SECRET_NUMBER

inf_form_name : ‘Webform’

infusionsoft_version : ‘1.34.0.35’

inf_field_Email : “#{user.email}”

Ah now we’re getting somewhere. I test the POST request in Postman and receive HTML responses. If the email is invalid or a duplicate, the response is a form with error alerts. I already validate those in the rails app so I shouldn’t have to worry.

I use HTTParty to facilitate the request in a Rails service object called AddContactToInfusionsoft.rb

class AddContactToInfusionsoft
 def self.call(user)
   HTTParty.post("https://ns166.infusionsoft.com/app/form/process/961b755cc1de68e2d549824cf11890d5",
     query: 
     {
       inf_form_xid: '961b755cc1de68e2d549824cf11890d5',
       inf_form_name: 'Webform in Content App',
       infusionsoft_version: '1.34.0.35',
       inf_field_Email: '#{user.email}'
     }
   )
 end
end

I test the code in my rails console and it works fine. Push it and you should be all set.

*Paraphrasing obviously.

Leave a Reply

Your email address will not be published. Required fields are marked *