Using the OnePageCRM API with Ruby

14 Mar 2014

I have created a short ruby script to help getting started with the OnePageCRM API. The script is available on the OnePageCRM Github profile. It contains a small subsection of calls and functions available using the API.

Getting started

  • Clone the repository and change to the directory
  • Start irb and require the lib/onpageapi file
require './lib/onepageapi'
api_login = 'you@example.com'
api_pass = 'youronpagepassword'
samples = OnePageAPISamples.new(api_login, api_pass)
samples.login

# Try a few api calls
samples.bootstrap
samples.get_contacts

Creating a contact

new_contact_details = ({
      'first_name' => 'Johnny',
      'last_name' => 'Deer',
      'company_name' => 'ACMEinc',
      'starred' => true,
      'tags' => %w[api_test1 api_test2],
      'emails' => [{
          'type' => 'work',
          'value' => 'johnny@exammmple.com' }]
    })

samples.create_contact(new_contact_details)

Making other API calls

You can also use this client to manually make API calls that aren’t fully covered in this client. For example, to get a list of custom fields

samples.get('custom_fields.json')

will return:

{"status"=>0, "message"=>"OK", "timestamp"=>1394799434, "data"=>
  {"custom_fields"=>
    [{"custom_field"=>
        {"id"=>"52d6edc1eb89973879000003", "name"=>"Customer Ref", "type"=>"number"}
      }, 
      {"custom_field"=>
        {"id"=>"52cf182beb8997213a000001", "name"=>"Next Training Date", "type"=>"date"}
      }, 
      {"custom_field"=>
      {"id"=>"52cd3922eb89976e7d000034", "name"=>"Birthday", "type"=>"date"}
      }
    ],
  "total_count"=>3, "page"=>1, "max_page"=>1, "per_page"=>10}
}

I hope that this short code sample will get you started using the OnePageCRM API v3.

Please let us know if there are other languages you would like to see examples for.

author image

Peter Armstrong

Peter is a software engineer at OnePageCRM. http://peterarmstrong.ie