Create logs on API calls for specific customers license keys

Share on FacebookShare on Google+Tweet about this on TwitterShare on LinkedInPrint this page

By woocommerce-sl, posted on May 23, 2022

The WP Software License API is the core module of the plugin. It allows easy interaction of customer applications with the licensing system. The implementation is straightforward and consists of GET / POST calls to the domain, as shown in the Software API Integration code example. Also, detailed code examples can be provided upon request.

Debugging API interaction is simple, calling the arguments using raw URL, returns the actual API response that the customer application receives. When this is not possible, a log can be created on the API machine, which will record all calls and responses for a specific license key ( customer ) or a list of keys. To achieve this feature a simple code can be used. This should be placed within /wp-content/mu-plugins/woosl-custom.php The name should be preserved as woosl-custom.php to ensure the system loads the code when using API Cache.

    add_filter( 'WOOSL/API_call/response', '__woosl_api_call_response__log', 10, 2 );
    function __woosl_api_call_response__log ( $response, $args )
        {
            
            $log_keys   =   array (
                                    '57285638-4a95bb52-187l7ddf'  
                                    );
               
            if ( ! isset ( $_REQUEST['licence_key'] )     ||    ! in_array ( $_REQUEST['licence_key'], $log_keys ) )
                return $response;
                
            
            $log    =    "--------------------------\n";
            $log    .=   "A new call at ". date("Y-m-d H:i:s") ."\n";
            $log    .=   "Call GET request " . print_r( $_GET, TRUE ) ."\n";
            $log    .=   "Call POST request " . print_r( $_POST, TRUE ) ."\n";
            $log    .=   "Response is " . print_r( $response, TRUE ) ."\n";
            
            //creates the log on WordPress root
            $Logfile = fopen("WooSL_log.txt", "a");
            fwrite( $Logfile, $log );
            fclose( $Logfile );

            return $response;    
        }

Category:
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments