solspace / craft-freeform

Freeform for Craft: The most reliable form builder that's ready for wherever your project takes you.
https://docs.solspace.com/craft/freeform/v5/
Other
47 stars 59 forks source link

Zoho CRM integration/oauth token issues #1412

Closed petehjfd closed 2 months ago

petehjfd commented 3 months ago

What happened?

We have successfully integrated with Zoho and tested form submissions. Everything worked as expected.

However, shortly after, we began seeing errors in the Freeform error log about an INVALID TOKEN:

Screenshot 2024-07-08 at 10 38 49

I just tested one of the forms and, while the form's notification email was sent and the data appeared in the submissions, I received an exception due to an 'invalid oauth token':

freeform-zoho-error

The issue seems to be resolved by going to the Zoho integration settings in Freeform (admin/freeform/settings/integrations/crm/2) but then it starts occuring again sometime after.

I'm not sure if this is related to issue #1372 but we have updated the latest version of Freeform and the issue is still occurring.

Thanks

Errors and Stack Trace (if available)

No response

How can we reproduce this?

  1. Integrate with Zoho
  2. Wait a few days

Freeform Edition

Pro

Freeform Version

5.3.4

Craft Version

4.8.9

When did this issue start?

Fresh install of Freeform

Previous Freeform Version

No response

gustavs-gutmanis commented 3 months ago

Hi @petehjfd,

Thanks for reporting this. As you mentioned - the latest version should have fixed this and the other issue you linked, but apparently it does not.
I will have a look at it again and try to reproduce it and fix it as fast as possible

petehjfd commented 3 months ago

Thanks @gustavs-gutmanis, much appreciated!

gustavs-gutmanis commented 3 months ago

Hi @petehjfd,

Unfortunately I am unable to reproduce this issue. I attempted to log in with intervals where the access token would have failed, as well as submitted linked data that goes to Zoho before and after the interval is for sure dead and gone.

Could you try re-authorizing the integration? You can do so by going to Freeform > Settings > CRM > Your Zoho integration and clicking Save.

The error you're receiving happens when the token becomes invalid. It might also happen that your refresh token becomes invalid (is invalidated or expires). There is no way for us to refresh a refresh token, and there doesn't seem to be a place where you can invalidate tokens in Zoho, so the only hope I have is that re-authorizing it would work for you. If not, then we will have to contact their support and look into it.

petehjfd commented 3 months ago

Thanks @gustavs-gutmanis. I have just re-authorized the integration. I will keep an eye on the error log over the next few days and let you know if the problem reoccurs.

Thanks

petehjfd commented 2 months ago

Hi @gustavs-gutmanis I've just checked the Freeform error logs again after re-authorizing the integration yesterday. I'm afraid we are still having the same issue. This is the error from a couple of hours ago:

Zoho: {"code":"INVALID_TOKEN","details":{},"message":"invalid oauth token","status":"error"} {"integration":{"id":2,"handle":"zoho"}} [] 
gustavs-gutmanis commented 2 months ago

That is very unfortunate. We will get in contact with Zoho support and see how we could resolve this issue. Thanks for the patience.

petehjfd commented 2 months ago

Hi @gustavs-gutmanis have you managed to get a response from Zoho yet? Thanks

gustavs-gutmanis commented 2 months ago

Hi @petehjfd, I am very sorry, it has not been done yet, because of the amount of work we have been dealing with. But I will get to it right now, thank you for the reminder.

gustavs-gutmanis commented 2 months ago

I will actually try to build a process which tries to refresh the token once if the access token used throws an error.

But out of curiosity, could you send me what the metadata column value is for your Zoho integration in the freeform_integrations database table? Plese redact out the clientId, clientSecret, refreshToken and accessToken values (even though they're encrypted and would be useless outside of your environment, but still)

petehjfd commented 2 months ago

Great, thanks. Here is the value of the metadata column:

{"sandboxMode":false,"developerMode":false,"clientId":"*************","clientSecret":"*************","accountsServer":"https:\/\/accounts.zoho.com","location":"us","apiDomain":"https:\/\/www.zohoapis.com","refreshToken":"*************","issuedAt":1721652369,"expiresIn":3600,"accessToken":"*************"}

Thanks again for your help.

gustavs-gutmanis commented 2 months ago

Hi @petehjfd,

I have added a refresh token flow whenever an access token throws an unauthorized response.
This took a bit of a while, because it gave me the option to refactor error logging for integrations as well.

Would it be possible for you to install it by specifying this branch in your composer.json?

{
    // ...
    "require": {
        // ...
        "solspace/craft-freeform": "dev-fix/SFT-1310-integrations"
    },
    // ...
}
petehjfd commented 2 months ago

Hi @gustavs-gutmanis

Thanks for working on this so quickly. I've installed that update. I'll monitor the error log for the next day or two and see if that has resolved the issue.

Will we need to switch back to the main branch once you have merged this one into it?

Thanks

petehjfd commented 2 months ago

Hi @gustavs-gutmanis

We have seen no more errors since making this update, so it looks like it's done the trick, thanks.

Will we need to switch back to the main branch once you have merged this one into it?

Thanks

gustavs-gutmanis commented 2 months ago

Glad to hear it! Yes, @kjmartens will let you know once it's released.

petehjfd commented 2 months ago

Perfect, thanks!

kjmartens commented 2 months ago

This should be resolved now in Freeform 5.5.5. 🙂