The Community Forums

Interact with an entire community of cPanel & WHM users!
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Custom API2 Functions

Discussion in 'cPanel Developers' started by willsmelser, Jul 25, 2010.

  1. willsmelser

    willsmelser Member

    Joined:
    Jun 11, 2008
    Messages:
    7
    Likes Received:
    0
    Trophy Points:
    1
    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:
    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:
    which is what the wiki says to do. Full path is:
    Really not too sure where to go from here.
     
  2. MattDees

    MattDees cPanel Product Owner
    Staff Member

    Joined:
    Apr 29, 2005
    Messages:
    417
    Likes Received:
    1
    Trophy Points:
    18
    Location:
    Houston, TX
    cPanel Access Level:
    Root Administrator
    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?
     
  3. leefrom

    leefrom Active Member

    Joined:
    May 27, 2008
    Messages:
    30
    Likes Received:
    0
    Trophy Points:
    6
    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. kris.x15

    kris.x15 Member

    Joined:
    Sep 20, 2010
    Messages:
    6
    Likes Received:
    0
    Trophy Points:
    1
    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. MattDees

    MattDees cPanel Product Owner
    Staff Member

    Joined:
    Apr 29, 2005
    Messages:
    417
    Likes Received:
    1
    Trophy Points:
    18
    Location:
    Houston, TX
    cPanel Access Level:
    Root Administrator
    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.
     
Loading...

Share This Page