SpliFF
SpliFF

Reputation: 39014

Zoho CRM Python SDK 2.1 won't update record owner

When I try to change the owner on a Zoho record I get a success message but the Lead Owner field doesn't change. The record is in the "Potentials" module (I think it's a custom module)

lead: Record = self.get_lead(int(lead_id))
user: ZCRMUser = self.get_user_by_email(owner_email)

# Perform the update
lead.add_key_value("Owner", user)
request = BodyWrapper()
request.set_data([new_record])
request.set_trigger(["approval", "workflow", "blueprint"])
response = self.record_operators.update_record(zoho_id, "Potentials", request)

The update is performed and reports no errors but it doesn't change the "Owner" field:

INFO Status: success
INFO Code: SUCCESS
INFO Details
INFO Modified_Time : 2024-05-13 11:23:12+10:00
INFO Modified_By : <zcrmsdk.src.com.zoho.crm.api.users.user.User object at 0x115384c10>
INFO Created_Time : 2024-05-02 14:03:19+10:00
INFO id : 68968000000476063
INFO Created_By : <zcrmsdk.src.com.zoho.crm.api.users.user.User object at 0x115347d10>
INFO Message: record updated

If I inspect the lead itself the field exists:

Owner = <zcrmsdk.src.com.zoho.crm.api.users.user.User object at 0x1153ae7d0>

Also the user object is a valid User object. The API token I'm using seems to have all permissions granted. It seems like Zoho just quietly drops the field. I don't know if this is a permissions thing, an API limitation or something else.

UPDATE: I've noticed the code I'm working on has pinned zohocrmsdk2_1 = "^1.0.0" so might be an old issue. Will retest with latest 3.0.0 and see if it helps. UPDATE 2: Didn't help. Same issue with versions 1.1.0 and 3.0.0 of zohocrmsdk2-1

Upvotes: 0

Views: 48

Answers (1)

SpliFF
SpliFF

Reputation: 39014

No thanks to Zoho themselves whose support and documentation are completely worthless but I was able to solve this by tracing API code.

It turns out the API will only update json keys and sub-keys that it thinks have changed. Because the User object already existed it doesn't see User.email as a NEW value so it uploads an empty User key with no email field.

Trick is to force Zoho to see the email field by pretending it changed (this will internallt set _email_modified = True or something like that on the User object and cause it to be correctly serialised to JSON. ie:

user.set_email(owner_email)

You should do this even if the user object was retrieved. If you just want to set the owner of a record you can use a new/partial User object like:

lead = Record()
lead.set_id(int(lead_id))
user = User()
user.set_email(owner_email)
lead.add_field_value(Field.Deals.owner(), user)
request = BodyWrapper()
request.set_data([new_record])
response = RecordOperations.update_record(lead_id, 'Lead', request)

Upvotes: 0

Related Questions