Using Sugar web logic hooks with ngrok and Flask

I am trying to retrieve data from a Sugar web logic hook using ngrok for a public url and Flask as my web server. (I‘m using the method shown in this video: https://www.youtube.com/watch?v=YMBzb_RBDAA&t=664s )

I know the ngrok url and Flask application I am using work because I can receive a payload from  Zoho Forms. Also, I am able to receive a payload from Sugar in pipedream (requestbin).

When  I take that json formatted payload from pipedream and send it to my Flask application using Postman, I am able to access the data.

However, when I trigger the webhook by changing a record in Sugar I get no response. I don’t even get an error code.

I do get a message from the ngrok inspect page: “The connection was closed before this request could be fully read; 219 bytes were captured. It cannot be replayed. The error encountered while reading the request body was "unexpected EOF".”

Any suggestions on how to troubleshoot this?

I’m open to other ways to create a webhook listener, but I’m new to this and am already somewhat familiar with Python.

Parents
  • Hi   / ,

    I had a similar issue and when I debugged the issue further, I noticed that the web logic hooks timeout in 1 second. - which is why the connection will be closed by Sugar even before transmitting the whole data.

    Because of a known issue,  the web logic hook dumps the entire content of the case and other unnecessary details, which makes the payload huge - in the order of 8-10 MB. This is the bug report - portal.sugarondemand.com/

    But even with that fix, Sugar will still terminate the web hook after 1 second, so we should ensure we get the data from sugar before that one second. It is not configurable right now, but you can request Sugar to do so.

    But - there are code alternatives to fix this issue, by extending the WebLogicHook bean and customizing the timeout ourselves.

    Eg: Use this method to customize WebLogicHook bean: https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_10.0/Data_Framework/Models/SugarBean/Customizing_Core_SugarBeans/

    We have to modify the run function, with increased timeout:

    public function run($data)
    {
    $data = unserialize($data);
    $payload = json_encode($data['payload']);

    $curlHandler = curl_init();

    $options = array(
    CURLOPT_HTTPHEADER => false,
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_CONNECTTIMEOUT => 5,
    CURLOPT_TIMEOUT => 5, // NOTE - This is the customization, increase timeout from 1s to 5s
    CURLOPT_MAXREDIRS => 1,
    CURLOPT_USERAGENT => 'SugarCrm',
    CURLOPT_VERBOSE => false,
    CURLOPT_URL => $data['url'],
    CURLOPT_HTTPHEADER => array(
    'Content-Type: application/json',
    'Content-Length: ' . strlen($payload)
    ),
    CURLOPT_POSTFIELDS => $payload,
    CURLOPT_CUSTOMREQUEST => $data['request_method'],
    );

    curl_setopt_array($curlHandler, $options);

    if (false === curl_exec($curlHandler)) {
    $GLOBALS['log']->error('WebLogicHook failed: ' . curl_error($curlHandler));
    }

    curl_close($curlHandler);
    $this->job->succeedJob();
    return true;
    }
Reply
  • Hi   / ,

    I had a similar issue and when I debugged the issue further, I noticed that the web logic hooks timeout in 1 second. - which is why the connection will be closed by Sugar even before transmitting the whole data.

    Because of a known issue,  the web logic hook dumps the entire content of the case and other unnecessary details, which makes the payload huge - in the order of 8-10 MB. This is the bug report - portal.sugarondemand.com/

    But even with that fix, Sugar will still terminate the web hook after 1 second, so we should ensure we get the data from sugar before that one second. It is not configurable right now, but you can request Sugar to do so.

    But - there are code alternatives to fix this issue, by extending the WebLogicHook bean and customizing the timeout ourselves.

    Eg: Use this method to customize WebLogicHook bean: https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_10.0/Data_Framework/Models/SugarBean/Customizing_Core_SugarBeans/

    We have to modify the run function, with increased timeout:

    public function run($data)
    {
    $data = unserialize($data);
    $payload = json_encode($data['payload']);

    $curlHandler = curl_init();

    $options = array(
    CURLOPT_HTTPHEADER => false,
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_CONNECTTIMEOUT => 5,
    CURLOPT_TIMEOUT => 5, // NOTE - This is the customization, increase timeout from 1s to 5s
    CURLOPT_MAXREDIRS => 1,
    CURLOPT_USERAGENT => 'SugarCrm',
    CURLOPT_VERBOSE => false,
    CURLOPT_URL => $data['url'],
    CURLOPT_HTTPHEADER => array(
    'Content-Type: application/json',
    'Content-Length: ' . strlen($payload)
    ),
    CURLOPT_POSTFIELDS => $payload,
    CURLOPT_CUSTOMREQUEST => $data['request_method'],
    );

    curl_setopt_array($curlHandler, $options);

    if (false === curl_exec($curlHandler)) {
    $GLOBALS['log']->error('WebLogicHook failed: ' . curl_error($curlHandler));
    }

    curl_close($curlHandler);
    $this->job->succeedJob();
    return true;
    }
Children
No Data