Question

How can I access 37 signals Highrise's API with Python? Found wrappers for PHP/Ruby, but not Python. I'm writing my own now, anyone have advice on getting over the first hurdle of authentication with Python?

Was it helpful?

Solution

I wrote (am writing, really) a Highrise API wrapper for Python. It uses Python objects for each of the Highrise classes and work a lot like the Django ORM:

>>> from pyrise import *
>>> Highrise.server('my-server')
>>> Highrise.auth('api-key-goes-here')
>>> p = Person()
>>> p.first_name = 'Joe'
>>> p.last_name = 'Schmoe'
>>> p.save()

You can get the source from GitHub: https://github.com/feedmagnet/pyrise

Or install it from PyPI:

$ sudo pip install pyrise

OTHER TIPS

I was just tackling this problem when I stumbled onto your question. Here is what I have hacked together so far. Its not pretty (yet) but it works. I don't know Pycurl and after looking at it for a while I went back to urllib2. Highrise uses Basic Authentication so you don't have to use CURL you can use urllib2. You just have to go through all the Pword Manager steps. The output is a long XML file of either all the companies or the people depending on which URL you insert. If you wanted just one person you could do something like 'http....../people/123.xml' or 'http....../people/123-fname-lname.xml' (like you see in the url when you actually go to a contact in highrise with the .xml added).

import ullib2    

PEOPLEurl = 'http://yourcompany.highrisehq.com/people.xml' #get all the people
# or 
COMPANYurl = 'http://yourcompany.highrisehq.com/company.xml' #get all companies

token = '12345abcd' #your token
password = 'X'

passmanager = urllib2.HTTPPasswordMgrWithDefaultRealm()
passmanager.add_password(None, PEOPLEurl, token, password)
authhandler = urllib2.HTTPBasicAuthHandler(passmanager)
opener = urllib2.build_opener(authhandler)
urllib2.install_opener(opener)
page = urllib2.urlopen(PEOPLEurl).read()

print page #this will dump out all the people contacts in highrise

Any feedback or suggestions on this code would be helpful!

See here on how to do basic authentication. Also IIRC urllib supports http://user:password@example.com URLs.

i was just looking to the php code of one of the php API wrappers and i see that they use curl ; so have you looked to pycurl ??

about the authentication here is an example that you can start with (it's not tested)...

  import pycurl

  def on_receive(data):
      # process your data here
      pass

  def connetion(url, token)

      conn = pycurl.Curl()

      # Set Token.  
      conn.setopt(pycurl.USERPWD, "%s:x" % (token,)) 
      # the format TOKEN:x i get it from the PHP wrapper because usually the 
      # format should be USER:PASSWD so here i think they just use a token as
      # a USERname and they set the password to 'x'.

      conn.setopt(pycurl.URL, url)

      # Set the XML data to POST data.
      conn.setopt(pycurl.POSTFIELDS, XML_DATA)  

      # Add SSL.
      conn.setopt(pycurl.SSL_VERIFYPEER, 0)
      conn.setopt(pycurl.SSL_VERIFYHOST, 0)

      # Set function that will be called as soon as the data is received.
      conn.setopt(pycurl.WRITEFUNCTION, on_receive)

      # Perform the data transfer. 
      conn.perform() 

  if __name__ == '__main__':
      connection("http://yourcompany.highrisehq.com", your_token)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top