lightspeedwp / cf-zoho

Zoho CRM Addon for Caldera Forms
https://lsdev.biz/lsx/extensions/lsx-caldera-forms-zoho-crm-integration/
GNU General Public License v3.0
2 stars 0 forks source link

In api requests api_name should be used instead of field_label #25

Closed brona-ruzicka closed 3 years ago

brona-ruzicka commented 4 years ago

Hello,

I’ve recently installed the addon onto my website and it doesn’t work properly. My use for it was just to insert new contacts. But i believe this bug affects all the types of processors.

To the problem. When the addon make a API call to Zoho the json looks something like this:

`{
    "data":[
        {
            "Full_Name": "Mr. My Name",
            ...
        }
    ],
    "trigger":[ ]
}`

The the problem is with the “Full_Name” json key. It’s generated from the fieldlabel json key which is seen as the label in the processor settings. (“Full Name” we replace ” ” with “” and we have “Full_Name”). But that’s not the right way. The addon gets the field_label from another API request to zohoapis.com/crm/v2/settings/fields?module=… In the same request. In the same object as field_label is also another json key api_name. And that’s the right string to use.

Why is this a problem? When a user changes name of some field on Zoho (as I did). It will logically affect the key generated by addon. For example: If I were to change “Full Name” to just “Name” the json sent by addon would change like this:

{
    "data":[
        {
            "Name": "Mr. My Name",
            ...
        }
    ],
    "trigger":[ ]
}

But Zoho API sets the expected api_name when you create the field and then it stays the same. So basically the json key is wrong, there’s no field by that api_name and therefore it just ignores it. The result is that, some part of your form gets imported and some (the fields you’ve changed the name of) parts don’t.

I’ve gone though the code and I belive to fix this you just need to change code in this file ( /includes/class-cf-processor.php ) at line 483. Instead of this:

$label = str_replace( ' ', '_', $field['field_label'] );

/**
* TODO: Change this to a preg_match
*/
if ( 'Lead_Owner' === $label || 'Task_Owner' === $label || 'Contact_Owner' === $label ) {
    $label = 'Owner';
}

$label = str_replace( '.', '', $label );
$object[ $label ] = $this->get_form_value( $field );

I believe there just needs to be this:

$object[ $field['api_name'] ] = $this->get_form_value( $field );

I have tested it on my website and it seems to work.

Thank you Brona Ruzicka

brona-ruzicka commented 4 years ago

26 I've made a pull request for this bug

ashleyshaw commented 4 years ago

Thanks for submitting this, apologies for the slow reply.

github-actions[bot] commented 3 years ago

Stale issue message

brona-ruzicka commented 3 years ago

Hello,

this issue is not fixed yet but it has been marked as closed (primarily due to inactivity). And I'm not sure what exactly is the state of it, if it's been closed just due to inactivity and should be reopened or if a fix is not planned at all.

Thanks for your reply