Let the platform do the work

Web Logic Hooks

Overview

Web logic hooks let administrators post record and event information to a specified URL when certain sugar events take place.

The administration panel for web logic hooks can be found by navigating to Admin > Web Logic Hooks in the Sugar application. When a web logic hook is triggered, Sugar creates a record in the job queue.

Note: You must have the cron set up and running in order to process the job queue for web logic hooks. The POST of the information to the external URL will happen when the cron runs and not when the actual event occurs.

Arguments

Name Description
URL The URL to post JSON-encoded information
Module Name The name of the module to which the web logic hook will apply
Trigger Event The event that will trigger the web logic hook

The following events are applicable to a web logic hook:
Request Method

The request method to use when sending the information

The following methods may be used:

  • POST
  • GET
  • PUT
  • DELETE

Example

The following example shows how to receive the information posted to the web logic hook URL parameter.

http://{url}/receive.php

  <?php

//get the posted JSON data
$data = file_get_contents('php://input');
//decode the data
$decoded_data = json_decode(trim($data));

//use the data
$file = 'receivedData-'.time().'.txt';
file_put_contents($file, print_r($decoded_data, true));

?>

Result

receivedData-1380158171.txt

  stdClass Object
(
    [isUpdate] => 1
    [dataChanges] => Array
    (
    )

    [bean] => Account
    [data] => stdClass Object
    (
        [id] => e0623cdb-ac4b-e7ff-f681-5242e9116892
        [name] => Super Star Holdings Inc
        [date_modified] => 2013-09-25T21:16:06-04:00
        [modified_user_id] => 1
        [modified_by_name] => admin
        [created_by] => 1
        [created_by_name] => Administrator
        [description] =>
        [deleted] =>
        [assigned_user_id] => seed_will_id
        [assigned_user_name] => Will Westin
        [team_count] =>
        [team_name] => Array
        (
            [0] => stdClass Object
                (
                    [id] => East
                    [name] => East
                    [name_2] =>
                    [primary] => 1
                )

            [1] => stdClass Object
                (
                    [id] => West
                    [name] => West
                    [name_2] =>
                    [primary] =>
                )

        )
        [linkedin] =>
        [facebook] =>
        [twitter] =>
        [googleplus] =>
        [account_type] => Customer
        [industry] => Energy
        [annual_revenue] =>
        [phone_fax] =>
        [billing_address_street] => 111 Silicon Valley Road
        [billing_address_city] => Los Angeles
        [billing_address_state] => NY
        [billing_address_postalcode] => 84028
        [billing_address_country] => USA
        [rating] =>
        [phone_office] => (374) 791-2199
        [phone_alternate] =>
        [website] =>
        [ownership] =>
        [employees] =>
        [ticker_symbol] =>
        [shipping_address_street] => 111 Silicon Valley Road
        [shipping_address_city] => Los Angeles
        [shipping_address_state] => NY
        [shipping_address_postalcode] => 84028
        [shipping_address_country] => USA
        [email] => Array
        (
            [0] => stdClass Object
                (
                    [email_address] => example@example.tw
                    [invalid_email] =>
                    [opt_out] =>
                    [primary_address] => 1
                    [reply_to_address] =>
                )

            [1] => stdClass Object
                (
                    [email_address] => the.example@example.name
                    [invalid_email] =>
                    [opt_out] =>
                    [primary_address] =>
                    [reply_to_address] =>
                )

        )
        [email1] => example@example.tw
        [parent_id] =>
        [sic_code] =>
        [parent_name] =>
        [email_opt_out] =>
        [invalid_email] =>
        [campaign_id] =>
        [campaign_name] =>
    )
    [event] => after_save
)