Community Forums
Connect with us on LinkedIn
+ Reply to Thread
Results 1 to 5 of 5
  1. #1
    Member
    Join Date
    Jun 2008
    Posts
    7

    Default Custom API2 Functions

    I am trying to create my own API2 function and cannot get it to work.

    I followed the guidelines in WritingCpanelModules < DeveloperResources/ApiBasics < TWiki but to no avail.

    I get the following error:
    Could not find function 'getcsr' in module 'myModule'
    The issue I beleive is that the module is not located/loaded. I have no idea where exactly to save my module and the name to save my file as.

    For example I have saved my file in:
    /usr/local/cpanel/Cpanel/
    which is what the wiki says to do. Full path is:
    /usr/local/cpanel/Cpanel/myModule.pm
    Really not too sure where to go from here.

  2. #2
    cPanel Staff cPanelMatt's Avatar
    Join Date
    Apr 2005
    Location
    Houston, TX
    Posts
    409

    Default

    What this error message means is that cpanel was unable to retrieve an API2 function called "getcsr" from the api2() function within myModule.pm

    Could I see what the api2 method looks like the myModule.pm module?
    Matt Dees
    Integration Developer
    cPanel, Inc.
    cPanel Integration Blog

  3. #3
    Member
    Join Date
    May 2008
    Posts
    30

    Default

    I'm pretty sure this is the issue we saw where the Package declaration had not been made:

    package Cpanel::myModule;

    api2 modules are standard perl modules, with a few necessary components in addition.

  4. #4
    Member
    Join Date
    Sep 2010
    Posts
    6

    Default

    Hi Guys,

    I think I have exact same problem as willsmelser.
    I've followed documentation (only thing missing there for me is working api2 test module), and still I'm not able to find answer.

    My test module code:
    Code:
    package Cpanel::testModule;
    use strict;
    use YAML::Syck;
    
    sub testModule_init { }
    
    sub api2_lista {   
        Cpanel::CPERROR{'testmodule'} = "Some test error";
        return;
    }
    
    sub api2 {
        
        my $func = shift;
        my %API;
    
        my %API = (
            'lista' => {
                'func'    => 'api2_lista',
                'engine'  => 'hasharray',
            }
    
        );
    
        return \%{ $API{$func} };
    }
    
    1;
    .. placed under /usr/local/cpanel/Cpanel .
    I have no idea why I'm getting error:
    Code:
    Could not find function 'lista' in module 'testModule'
    when trying to access in FastMode.

    Any ideas?

  5. #5
    cPanel Staff cPanelMatt's Avatar
    Join Date
    Apr 2005
    Location
    Houston, TX
    Posts
    409

    Default

    Ok, so.. the code actually does work correctly, however there appears to be some weirdness when copy and pasting the code off of there due to the way that twiki formats it. Could you please try actually typing out the example?

    I was encountering an issue where the quotes (both single and double) where being sent as a UTF8 character rather than the ASCII quote strings causing perl to have some issues.

    After making making this change (from the quotes in there to ASCII quotes) the code worked properly.
    Matt Dees
    Integration Developer
    cPanel, Inc.
    cPanel Integration Blog

Similar Threads & Tags
Similar threads

  1. Planned for 11.34 XML API2 functions - Batch support [Case 43047]
    By rusev in forum Feature Requests for cPanel/WHM
    Replies: 4
    Last Post: 02-21-2011, 10:35 AM
  2. Custom API2 Functions
    By willsmelser in forum cPanel and WHM Discussions
    Replies: 0
    Last Post: 07-25-2010, 09:25 AM
  3. Calling API1 functions from a custom Cpanel module
    By RSimoes in forum cPanel Developers
    Replies: 1
    Last Post: 01-27-2010, 06:44 PM
Tags for this Thread
Linkedin       Facebook       Twitter       RSS       Flickr       YouTube