amalc / rubyzoho

Abstracting Zoho’s API into a set of Ruby classes, with reflection of Zoho’s fields using a more familiar ActiveRecord lifecycle, but without ActiveRecord. Works with Rails and Devise.
MIT License
62 stars 57 forks source link

Adding notes to Contacts? #17

Closed yesezra closed 9 years ago

yesezra commented 10 years ago

Hi! Great library.

I'm interested in programmatically adding notes to entities like Contacts, Leads, and Accounts. The API docs claim that this is possible, but I haven't been able to figure out how to do this in rubyzoho.

If this functionality doesn't exist, I'm happy to work on a patch if it would be helpful.

amalc commented 10 years ago

Have you tried using the name of the notes field and assigning a note to it? I'm pretty sure we use that in our system. I don't have a test for it. If you want to add that, will gladly put it in.

Attaching a document is something that I was trying as well without much success. But that's not what you want to do, right?

Update: Nope, I just checked our app. We don't use notes. Please feel free to add the functionality.

yesezra commented 10 years ago

Thanks for your response! There doesn't currently seem to be a notes field on a Contact:

c = RubyZoho::Crm::Contact.new
=> #<RubyZoho::Crm::Contact:0x007ff505b3eca8
c.notes = "hello"
NoMethodError: undefined method `notes=' for #<RubyZoho::Crm::Contact:0x007ff505b3eca8>
from /Users/ezra/.rbenv/versions/2.1.0/gemsets/omc-shim/gems/rubyzoho-0.1.11/lib/crm.rb:38:in `method_missing'

There's a 1-to-N relationship between Contacts (and Leads, Accounts, etc.) and notes, but notes aren't a module/class level entity (though they do have two attributes – title and content).There does seem to be an API endpoint for notes.

Not sure what the best approach is. What I'm going for is to be able to add data to entities in Zoho CRM when actions happen in other web services (i.e. an order is placed, a tech support ticket is created).

amalc commented 10 years ago

You're right. I just looked through the code. Looks like I got the retrieval of notes under way. But didn't allow for the inserts. Let me take a look through the API and see what they're doing and we can sort out an implementation. There is always a bit of archeology involved when dealing with their API! Another dev is working on relating records and he was having an adventure as well!

yesezra commented 10 years ago

Sounds great. Let me know if there's any way I can help!

amalc commented 10 years ago

Well, looks like Notes is an entity in its own right. So, I suspect the best thing to so would be to add a separate Notes entity... which is unfortunate. But I suppose at some level it makes sense to them, because it can be added to any module.

Let me think about this overnight and revert.

amalc commented 10 years ago

@ahhrrr I'll add the Notes functionality. Will you be able to test it?

yesezra commented 10 years ago

Yes, I'd be happy to test it! Looking forward to it.

pjsim commented 10 years ago

Hi, will documents be added to the gem api as well as notes?

amalc commented 10 years ago

That works now. Should be in the docs. We use it to add PDF materials sent to the prospect or client so the salesperson can see what they got.

pjsim commented 10 years ago

Ah beautiful I see it now thanks!

pjsim commented 10 years ago

Hi, another quick question regarding documents. I'm confused with how Zoho works but basically what I need for each lead/contact is the ability to upload a pdf and have it sorted in a folder attached to that user with the ability to have revisions. It seems like Zoho does have folders and revisions in the documents module but these aren't for specific leads or contacts?

Is it possible in Zoho? and if so, can it be done with the API? and also if so can it be done with this gem? :)

amalc commented 10 years ago

Yes, this is a bit of a rub. The docs “module” is part of ZohoDocs and we did take a look at it for the very use case you describe. 

As it happens, the CRM only allows , as best as I can tell, the attachment of individual documents to a CRM module record. And it does this well. ZohoDocs, with a separate API allows typical document management functionality. In the CRM a user can attach a document from ZohoDocs to a record in the CRM but it isn’t clear to me that the CRM API allows that. 

At any rate, we couldn’t find away to manage folders at the CRM level. We’ve got a link to Alfresco which manages folders and the the rest of DM for us. 

And as far the user experience is concerned, any documents sent to a prospect, client etc become this list of “versioned” documents. We tack on a revision number. The “links” section of the CRM interface allows a one click move to Alfresco or I suppose could be Zoho Docs. Sorry this doesn’t help you, I know. But if you find something that’s perhaps new, happy to add to the gem.

Also, the API documentation tends to lag whatever is going on in Zoho engineering, so posting into the ZohoCRM forum or I had to resort to calling the help desk, does get you to one of their engineers via email who can tell you about some undocumented feature. We had a few of those to get the gem running. Perhaps they have a new API call which allows hooking a ZohoDocs folder, or at minimum, a document to a module record.

LMK what you find. We’d find it useful as well.

On February 13, 2014 at 8:33:46 PM, Phillip Simmonds (notifications@github.com) wrote:

Hi, another quick question regarding documents. I'm confused with how Zoho works but basically what I need for each lead/contact is the ability to upload a pdf and have it sorted in a folder attached to that user with the ability to have revisions. It seems like Zoho does have folders and revisions in the documents module but these aren't for specific leads or contacts?

Is it possible in Zoho? and if so, can it be done with the API? and also if so can it be done with this gem? :)

— Reply to this email directly or view it on GitHub.

pjsim commented 10 years ago

Thanks for the reply! We are thinking maybe if we can just upload and download attachments with the API we can do all the folder organisation on our own site and then just store the documents as attachments to that user on Zoho. Is there a download method for attachments as well as an upload one for this gem?

amalc commented 10 years ago

Looks like the API supports both a delete and a download. Want to take a crack at it and send in a PR? Should be fairly straightforward unless they've got some idiosyncratic behavior which does happen.

amalc commented 10 years ago

Looks like it could go into crud_methods.rb and the associated spec. Not clear to me, though, how to manage file names or identify the correct attachment.

amalc commented 10 years ago

Yes, it got a little more hair on it. A related records call needs to be made to get the list of attachments with attributes, then a call needs to be made to download the attachment. And as is typical with Zoho there is a governor of 15 downloads every 5 minutes.

https://www.zoho.com/crm/help/api/getrelatedrecords.html#To_view_files_attached_to_a_record

pjsim commented 10 years ago

For some reason using that method said a lead (which had two documents attached to it) had no documents attached to it.. I'll give it another go at work tomorrow.

And yes the 15 downloads every 5 minutes is very annoying of Zoho and will very likely be an issue for us.

amalc commented 10 years ago

What is your use case for folders? We use folders for standard marketing collateral. Debate over if we should store link to the versioned document in Alfresco or simply tack on the pdf to a record. If its client specific, its always attached.

AlbaHoo commented 6 years ago

Sorry, is Notes added or not, lost in the conversation!

amalc commented 6 years ago

Apologies. Didn’t see this. No, never did get it working.

AlbaHoo commented 6 years ago

I have went through your code and ZOHO API DOC, and get it work in this way: But this is for Deal module, should be the same to Contact, replace deal_id with contact_id

    def add_note(deal_id, content, title = '')
      x = REXML::Document.new
      element = x.add_element 'Notes'
      row = element.add_element 'row', 'no' => '1'
      # deal_id is the id of the zoho record, association key.
      row.add_element('FL', 'val' => 'entityId').add_text(deal_id)
      row.add_element('FL', 'val' => 'Note Title').add_text(title)
      row.add_element('FL', 'val' => 'Note Content').add_text(content)
      r = ZohoApi::Crm.post('http://crm.zoho.com:443/crm/private/xml/Notes/insertRecords',
                            query: { newFormat: 1, authtoken: RubyZoho.configuration.api_key,
                                     scope: 'crmapi', xmlData: x, wfTrigger: 'true' },
                            headers: { 'Content-length' => '0' })
      raise "Add Note failed.#{r.body}" unless r.code == 200
    end

In case someone has the same problem. @amalc maybe Note doesn't have to be a separate module, I don't know. Rubyzoho is awesome, just want to thank you for your great work.

amalc commented 6 years ago

Wow. Can you send a pull request? It’s time for a new release!

AlbaHoo commented 6 years ago

Haha, it's mostly your code, I just put them together with the note api endpoint, but yeah, I would love to do that next week, cheers.