rikas / zoho_hub

Zoho CRM API V2 Wrapper
MIT License
25 stars 30 forks source link

How to retrieve Contacts (and other sub-modules) attached to an Account? #26

Closed waynerobinson closed 2 years ago

waynerobinson commented 5 years ago

Hi

Thanks for this library, it's been quite helpful so far for us to get started using the Zoho CRM API.

I've run into a bit of a stumbling block though. How do we go about retrieving sub-module records associated with others?

For example, to get an Account record we can do something like Account.find(account_id) that does a GET from /crm/v2/Accounts/#{account_id}, but how do we get the associated contacts?

The raw request would normally look something like /crm/v2/Accounts/#{account_id}/Contacts but I can't work out how to massage BaseRecord into being configured to return records like that?

Any help would be appreciated.

Cheers

artsyca commented 5 years ago

I'd venture this can be accomplished via ZohoHub.connection.get(...) although I'm not sure if there's an idiomatic way to do this in ZohoHub just yet -- I'd equally like to see it for Attachment records too

For reference, the related modules API docs are here: https://www.zoho.com/crm/developer/docs/api/get-related-records.html

artsyca commented 5 years ago

Attachments behave in a similar fashion to these as well -- so far I've been able to add a method to the parent record to retrieve the related records, but I'd like to understand what would be the idiomatic way to do this?

artsyca commented 4 years ago

This is far from being a relationship type of implementation, but I have implemented a quick n' dirty fetch method thus (which I memoize using the tycoon/memery gem):

  def contact_record
    Zoho::Contact.find_by(id: @contact_lookup[:id])
  end

where @contact_lookup is a Zoho lookup field which looks like

  "contact_lookup": {
    "name": "Alexandros K",
    "id": "3xxxxxxxxxxxxxxxxx2"
  }