Base CRM API Client
BaseCRM Official API V2 library client for ruby
Make sure you have rubygems installed.
The gem is available via Rubygems. To install, use the following command:
gem install basecrm
If you use Bundler, put the line below in your Gemfile:
gem 'basecrm'
To get the latest version, put this in your Gemfile:
gem 'basecrm', :git => 'git://github.com/zendesk/basecrm-ruby.git'
require "basecrm"
# Then we instantiate a client (as shown below)
Using this api without authentication gives an error
client = BaseCRM::Client.new(access_token: "<YOUR_PERSONAL_ACCESS_TOKEN>")
The following options are available while instantiating a client:
The library follows few architectural principles you should understand before digging deeper.
For example, to interact with deals API you will use DealsService
, which you can get if you call:
client = BaseCRM::Client.new(access_token: "<YOUR_PERSONAL_ACCESS_TOKEN>")
client.deals # => BaseCRM::DealsService
When you want to fetch all resources you will use #all
method which returns paginated resource (which implements Enumerable):
client = BaseCRM::Client.new(access_token: "<YOUR_PERSONAL_ACCESS_TOKEN>")
client.deals.all.map { |deal| deal.name } # => Array<String>
To retrieve list of resources and use filtering you will call #where
method:
client = BaseCRM::Client.new(access_token: "<YOUR_PERSONAL_ACCESS_TOKEN>")
client.deals.where(organization_id: google.id, hot: true) # => Array<BaseCRM::Deal>
To find a resource by it’s unique identifier use #find
method:
client = BaseCRM::Client.new(access_token: "<YOUR_PERSONAL_ACCESS_TOKEN>")
client.deals.find(id) # => BaseCRM::Deal
When you’d like to create a resource, or update it’s attributes you want to use either #create
or #update
methods. Both of them can take either Hash or a model class e.g. Deal instance. For example if you want to create a new deal you will call:
client = BaseCRM::Client.new(access_token: "<YOUR_PERSONAL_ACCESS_TOKEN>")
coffeeshop = client.contacts.where(name: "Coffee Shop")
deal = client.deals.create(name: "Website redesign", contact_id: coffeeshop.id)
deal.value = BigDecimal("1000.99")
deal.currency = "USD"
client.deals.update(deal) # => BaseCRM::Deal
To destroy a resource use #destroy
method:
client = BaseCRM::Client.new(access_token: "<YOUR_PERSONAL_ACCESS_TOKEN>")
client.deals.destroy(id) # => true
There other non-CRUD operations supported as well. Please contact corresponding service files for in-depth documentation.
Create a new organization and after that change it’s attributes (website).
client = BaseCRM::Client.new(access_token: "<YOUR_PERSONAL_ACCESS_TOKEN>")
lead = client.leads.create(organization_name: "Design service company")
lead.website = "http://www.designservices.com"
client.leads.update(lead)
The following sample code shows how to perform a full synchronization flow using high-level wrapper.
First of all you need an instance of BaseCRM::Client
. High-level BaseCRM::Sync
wrapper is using BaseCRM::SyncService
to interact with the Sync API.
In addition to the client instance, you must provide a device’s UUID within device_uuid
parameter. The device’s UUID must not change between synchronization sessions, otherwise the sync service will not recognize the device and will send all the data again.
client = BaseCRM::Client.new(access_token: "<YOUR_PERSONAL_ACCESS_TOKEN>")
sync = BaseCRM::Sync.new(client: client, device_uuid: "<YOUR_DEVICES_UUID>")
Now all you have to do is to call #fetch
method and pass a block that you might use to store fetched data to a database.
sync.fetch do |meta, resource|
options = {
table: meta.type,
statement: meta.sync.event_type,
properties: resource
}
DB.execute(options) ? meta.sync.ack : meta.sync.nack
end
Notice that you must call either #ack
or #nack
method on an instance of BaseCRM::SyncMeta
.
Documentation for every action can be found in corresponding service files under lib/basecrm/services
directory.
client = BaseCRM::Client.new(access_token: "<YOUR_PERSONAL_ACCESS_TOKEN>")
client.accounts # => BaseCRM::AccountsService
Actions:
client.accounts.self
client = BaseCRM::Client.new(access_token: "<YOUR_PERSONAL_ACCESS_TOKEN>")
client.associated_contacts # => BaseCRM::AssociatedContactsService
Actions:
client.associated_contacts.all
client.associated_contacts.create
client.associated_contacts.destroy
client = BaseCRM::Client.new(access_token: "<YOUR_PERSONAL_ACCESS_TOKEN>")
client.calls # => BaseCRM::CallsService
Actions:
client.calls.all
client.calls.create
client.calls.find
client.calls.update
client.calls.destroy
client = BaseCRM::Client.new(access_token: "<YOUR_PERSONAL_ACCESS_TOKEN>")
client.call_outcomes # => BaseCRM::CallOutcomesService
Actions:
client.call_outcomes.all
client = BaseCRM::Client.new(access_token: "<YOUR_PERSONAL_ACCESS_TOKEN>")
client.contacts # => BaseCRM::ContactsService
Actions:
client.contacts.all
client.contacts.create
client.contacts.find
client.contacts.update
client.contacts.destroy
client = BaseCRM::Client.new(access_token: "<YOUR_PERSONAL_ACCESS_TOKEN>")
client.deals # => BaseCRM::DealsService
Actions:
client.deals.all
client.deals.create
client.deals.find
client.deals.update
client.deals.destroy
A note about deal value
It is prefered to use a BigDecimal when creating or modyfing a deal value. This guarantees correct precision
deal.value = BigDecimal("1000.98")
You should not be using floats as it may result in precision loss.
deal.value = 1000.98
client = BaseCRM::Client.new(access_token: "<YOUR_PERSONAL_ACCESS_TOKEN>")
client.deal_sources # => BaseCRM::DealSourcesService
Actions:
client.deal_sources.all
client.deal_sources.create
client.deal_sources.find
client.deal_sources.update
client.deal_sources.destroy
client = BaseCRM::Client.new(access_token: "<YOUR_PERSONAL_ACCESS_TOKEN>")
client.deal_unqualified_reasons # => BaseCRM::DealUnqualifiedReasonsService
Actions:
client.deal_unqualified_reasons.all
client.deal_unqualified_reasons.create
client.deal_unqualified_reasons.find
client.deal_unqualified_reasons.update
client.deal_unqualified_reasons.destroy
client = BaseCRM::Client.new(access_token: "<YOUR_PERSONAL_ACCESS_TOKEN>")
client.leads # => BaseCRM::LeadsService
Actions:
client.leads.all
client.leads.create
client.leads.find
client.leads.update
client.leads.destroy
client = BaseCRM::Client.new(access_token: "<YOUR_PERSONAL_ACCESS_TOKEN>")
client.lead_sources # => BaseCRM::LeadSourcesService
Actions:
client.lead_sources.all
client.lead_sources.create
client.lead_sources.find
client.lead_sources.update
client.lead_sources.destroy
client = BaseCRM::Client.new(access_token: "<YOUR_PERSONAL_ACCESS_TOKEN>")
client.lead_unqualified_reasons # => BaseCRM::LeadUnqualifiedReasonsService
Actions:
client.lead_unqualified_reasons.all
client = BaseCRM::Client.new(access_token: "<YOUR_PERSONAL_ACCESS_TOKEN>")
client.line_items # => BaseCRM::LineItemsService
Actions:
client.line_items.all
client.line_items.create
client.line_items.find
client.line_items.destroy
client = BaseCRM::Client.new(access_token: "<YOUR_PERSONAL_ACCESS_TOKEN>")
client.loss_reasons # => BaseCRM::LossReasonsService
Actions:
client.loss_reasons.all
client.loss_reasons.create
client.loss_reasons.find
client.loss_reasons.update
client.loss_reasons.destroy
client = BaseCRM::Client.new(access_token: "<YOUR_PERSONAL_ACCESS_TOKEN>")
client.notes # => BaseCRM::NotesService
Actions:
client.notes.all
client.notes.create
client.notes.find
client.notes.update
client.notes.destroy
client = BaseCRM::Client.new(access_token: "<YOUR_PERSONAL_ACCESS_TOKEN>")
client.orders # => BaseCRM::OrdersService
Actions:
client.orders.all
client.orders.create
client.orders.find
client.orders.update
client.orders.destroy
client = BaseCRM::Client.new(access_token: "<YOUR_PERSONAL_ACCESS_TOKEN>")
client.pipelines # => BaseCRM::PipelinesService
Actions:
client.pipelines.all
client = BaseCRM::Client.new(access_token: "<YOUR_PERSONAL_ACCESS_TOKEN>")
client.products # => BaseCRM::ProductsService
Actions:
client.products.all
client.products.create
client.products.find
client.products.update
client.products.destroy
client = BaseCRM::Client.new(access_token: "<YOUR_PERSONAL_ACCESS_TOKEN>")
client.sources # => BaseCRM::SourcesService
Actions:
client.sources.all
client.sources.create
client.sources.find
client.sources.update
client.sources.destroy
client = BaseCRM::Client.new(access_token: "<YOUR_PERSONAL_ACCESS_TOKEN>")
client.stages # => BaseCRM::StagesService
Actions:
client.stages.all
client = BaseCRM::Client.new(access_token: "<YOUR_PERSONAL_ACCESS_TOKEN>")
client.tags # => BaseCRM::TagsService
Actions:
client.tags.all
client.tags.create
client.tags.find
client.tags.update
client.tags.destroy
client = BaseCRM::Client.new(access_token: "<YOUR_PERSONAL_ACCESS_TOKEN>")
client.tasks # => BaseCRM::TasksService
Actions:
client.tasks.all
client.tasks.create
client.tasks.find
client.tasks.update
client.tasks.destroy
client = BaseCRM::Client.new(access_token: "<YOUR_PERSONAL_ACCESS_TOKEN>")
client.text_messages # => BaseCRM::TextMessagesService
Actions:
client.text_messages.all
client.text_messages.find
client = BaseCRM::Client.new(access_token: "<YOUR_PERSONAL_ACCESS_TOKEN>")
client.users # => BaseCRM::UsersService
Actions:
client.users.all
client.users.find
client.users.self
client = BaseCRM::Client.new(access_token: "<YOUR_PERSONAL_ACCESS_TOKEN>")
client.visits # => BaseCRM::VisitsService
Actions:
client.visits.all
client = BaseCRM::Client.new(access_token: "<YOUR_PERSONAL_ACCESS_TOKEN>")
client.visit_outcomes # => BaseCRM::VisitOutcomesService
Actions:
client.visit_outcomes.all
Report here.
master
v
and the version, for example v1.0.0
Copyright 2013 Zendesk
Licensed under the Apache License, Version 2.0