Home > Ruby > Programatically adding tags to contacts in Highrise

Programatically adding tags to contacts in Highrise

April 3rd, 2009

I have been playing with adding tags to contacts in Highrise programatically. Unfortunately, 37Signals has not added this functionality to the API for Highrise so you have to hack it in. Based on a post on adding contacts, the following code will add a single tag to a contact.

require 'rubygems'
require 'net/http'

contact_id = 12345
connection = Net::HTTP.new("your_account.highrisehq.com")
req = Net::HTTP::Post.new("/parties/#{contact_id}/tags")
req["content-type"] = "application/xml"
req.basic_auth("your_api_token", 'X')
req.set_form_data({"name" => "new_or_existing_tag"}, ";")
response = connection.request(req)
puts response

This will return a bunch of JavaScript that you can ignore.

For comparison, here is the same code using HTTParty. A very nice, easy to use library for interacting with ReST services.

require 'rubygems'
require 'httparty'

class Tag
  include HTTParty
  base_uri "your_site.highrisehq.com"
  basic_auth 'your_api_token', 'X'

  def add_tag_to_contact(tag, contact_id)
    self.class.post("/parties/#{contact_id}/tags", :query => { :name => tag })
  end
end

puts Tag.new.add_tag_to_contact("tag_as_string", "1")

The goal of all this is to create a Highrise API wrapper that includes the ability to manipulate tags. Highrise is great, but the lack of Tags in the API really reduces what you can do with the tool since there is no facility for creating or manipulating lists.

Categories: Ruby Tags:
  1. Pete
    April 16th, 2009 at 07:04 | #1

    Interesting post. I’ve been finding holes in the Highrise API to – for example, have you managed to remove an email address or phone number from a person? Reading the API documentation, you would assume you’d just omit the details you want to remove from an update post but that doesn’t seem to work.

    I’m stumped

    Cheers,
    Pete

  2. April 16th, 2009 at 10:46 | #2

    I have not gotten that far. I have been side tracked a little lately working on a Rails site. Anyway, I will give it a shot in the next little while and see if I can figure it out.

Comments are closed.