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.

Find API codes

Discussion in 'cPanel Developers' started by cetterra, Jun 8, 2009.

  1. cetterra

    cetterra Member

    Joined:
    Jan 5, 2009
    Messages:
    19
    Likes Received:
    0
    Trophy Points:
    1
    Where can I find API codes?

    I am trying to make a script to change the contact's e-mail of a user, but this do not exist in XML API.

    I am trying to find where in cpanel installation are the codes that use the APIs.
     
  2. jhyland87

    jhyland87 Well-Known Member

    Joined:
    Dec 8, 2008
    Messages:
    153
    Likes Received:
    0
    Trophy Points:
    16
  3. cPanelDavidG

    cPanelDavidG Technical Product Specialist

    Joined:
    Nov 29, 2006
    Messages:
    11,279
    Likes Received:
    8
    Trophy Points:
    38
    Location:
    Houston, TX
    cPanel Access Level:
    Root Administrator
    Are you still looking for information on how to change the contact info via our APIs? If so, just let me know and I'll get you that information.
     
  4. cetterra

    cetterra Member

    Joined:
    Jan 5, 2009
    Messages:
    19
    Likes Received:
    0
    Trophy Points:
    1
    Thanks for the answer.
    I am already using the xmlapi-php class. But there isn't any method to change contact mail there.

    I will look at frontends, but I think it is only for cpanel's functions, not WHM.

    For example, I didn't find in /usr/local/base/cpanel/frontend anything about changing a website's ip address. I will take a look better to be certain of that.
     
  5. cetterra

    cetterra Member

    Joined:
    Jan 5, 2009
    Messages:
    19
    Likes Received:
    0
    Trophy Points:
    1
    I didn' find the answer, yet. If you have the answer, please tell me.

    I will look at the frontend's folder later to find more useful functions.
     
  6. cPanelDavidG

    cPanelDavidG Technical Product Specialist

    Joined:
    Nov 29, 2006
    Messages:
    11,279
    Likes Received:
    8
    Trophy Points:
    38
    Location:
    Houston, TX
    cPanel Access Level:
    Root Administrator
    The raw API call for this in the X3 theme is:

    HTML:
    <?cp CustInfo::savecontactinfo(
            [tr]
                [td]%[/td]
                [td]%[/td]
            [/tr],name,display_value) email=$FORM{'email'},second_email=$FORM{'second_email'},notify_disk_limit=$FORM{'notify_disk_limit'},notify_bandwidth_limit=$FORM{'notify_bandwidth_limit'},notify_email_quota_limit=$FORM{'notify_email_quota_limit'}  ?>
    
    To break this down, this is an API2 function:

    module: CustInfo
    function: savecontactinfo
    named parameter: email <- primary contact email
    named parameter: second_email <- secondary contact email
    named parameter: notify_disk_limit <- 1 to enable, 0 to disable
    named parameter: notify_bandwidth_limit <- 1 to enable, 0 to disable
    named parameter: notify_email_quota_limit <- 1 to enable, 0 to disable

    If you are coding your script in PHP 5, you may want to use Matt's PHP Class posted at: http://forums.cpanel.net/f42/xmlapi-php-class-111897.html

    Otherwise, documentation for manual implementation is posted at XmlApi < AllDocumentation/AutomationIntegration < TWiki
     
  7. cetterra

    cetterra Member

    Joined:
    Jan 5, 2009
    Messages:
    19
    Likes Received:
    0
    Trophy Points:
    1
    I am already using the XML API PHP Class.

    I have found the following code:
    Code:
    [% IF acl.edit_account %]
        <td>[% acct.user %]&nbsp;<a href="/scripts/edituser?domain=[% acct.domain %]&user=[% acct.user %]" class="dlink"><img src="[% MagicRevision.calculate_mag
    ic_url('/change.gif') %]" border="0"></a><div class="fillerdiv">&nbsp;</div></td>
    [% ELSE %]
        <td>&nbsp;[% acct.user %]&nbsp;</td>
    [% END %]
    
    
        <td>&nbsp;<a href="mailto:[% acct.email %]">[% acct.email %]</a>&nbsp;[B][COLOR="Red"]<a href="/scripts2/changeemail?domain=[% acct.domain %]&user=[% acct.user %]"[/COLOR][/B] class
    ="dlink"><img src="[% MagicRevision.calculate_magic_url('/change.gif') %]" border="0"></a><div class="fillerdiv">&nbsp;</div>&nbsp;</td>
    
        <td align="center">&nbsp;[% acct.html_startdate %]&nbsp;</td>
    
    [% IF acl.all %]
        <td>[% acct.partition %]&nbsp;<a href="/scripts/rearrangeacct?domain=[% acct.user %]&user=[% acct.user %]" class="dlink"><img src="[% MagicRevision.calcu
    late_magic_url('/change.gif') %]" border="0"></a><div class="fillerdiv">&nbsp;</div></td>
    [% ELSE %]
        <td>&nbsp;[% acct.partition %]&nbsp;</td>
    [% END %]
    
    This code is in this file: /usr/local/cpanel/whostmgr/docroot/themes/x/templates/listaccts.tmpl

    This code is exactly what I want, but doing remotely. The '/scripts2/changeemail' is readable? What would be the API Code referent to this?

    The code you sent to me forces to change some other parameters, and didn't work in my script.

    Here is the example:
    Code:
    $dados['email'] = mymail@mail.com';
    $result = $xmlapi->api1_query('username','CustInfo','savecontactinfo',$dados);
    
    The return:

    Code:
    <?xml version="1.0" ?>
    <cpanelresult>
       <module>CustInfo</module>
       <func>savecontactinfo</func>
       <type>event</type>
       <source>internal</source>
       <apiversion>1</apiversion>
       <data>
           <result></result>
       </data>
    </cpanelresult>
     
    #7 cetterra, Jun 10, 2009
    Last edited: Jun 10, 2009
  8. cPanelDavidG

    cPanelDavidG Technical Product Specialist

    Joined:
    Nov 29, 2006
    Messages:
    11,279
    Likes Received:
    8
    Trophy Points:
    38
    Location:
    Houston, TX
    cPanel Access Level:
    Root Administrator
    Unlike the cPanel interface, code from the WHM interface does not always have a XML API counterpart. WHM is not based on either API1 nor API2.

    Use of /scripts2, /scripts3 ... /scripts6, /scripts (not to be confused with the /scripts directory on the file system) etc. directly is not encouraged as these can change at any time without notice. Also, these scripts don't necessarily have API counterparts at this time.
     
  9. cPanelDavidG

    cPanelDavidG Technical Product Specialist

    Joined:
    Nov 29, 2006
    Messages:
    11,279
    Likes Received:
    8
    Trophy Points:
    38
    Location:
    Houston, TX
    cPanel Access Level:
    Root Administrator
    In previous testing I've done on this function, I've noticed that all parameters for this function must be passed, not just the first parameter for this function.
     
  10. cetterra

    cetterra Member

    Joined:
    Jan 5, 2009
    Messages:
    19
    Likes Received:
    0
    Trophy Points:
    1

    I've tryed with all parameters, but it didn't work too.

    Code:
    $dados['email'] = 'email@mail.com';
    $dados['secondary_email'] = '';
    $dados['notify_disk_limit'] = 1;
    $dados['notify_bandwidth_limit'] = 1;
    $dados['notify_email_quota_limit'] = 1;
    print_r($dados);
    $result = $xmlapi->api1_query('user','CustInfo','savecontactinfo',$dados);
     
  11. cPanelDavidG

    cPanelDavidG Technical Product Specialist

    Joined:
    Nov 29, 2006
    Messages:
    11,279
    Likes Received:
    8
    Trophy Points:
    38
    Location:
    Houston, TX
    cPanel Access Level:
    Root Administrator
    You have double-checked the cPanel interface to ensure this API1 call failed?

    API1 isn't as good with providing success/failure messages as XML API functions are.
     
  12. cetterra

    cetterra Member

    Joined:
    Jan 5, 2009
    Messages:
    19
    Likes Received:
    0
    Trophy Points:
    1
    Yeah... I have checked... the contact email didn't change.
     
  13. cPanelDavidG

    cPanelDavidG Technical Product Specialist

    Joined:
    Nov 29, 2006
    Messages:
    11,279
    Likes Received:
    8
    Trophy Points:
    38
    Location:
    Houston, TX
    cPanel Access Level:
    Root Administrator
    This is an API2 function, that's why the API1 function call is failing. You are calling a function that doesn't exist in API1. Call this as an API2 function instead.

    Note, in API2, the arguments are named - unlike API1 where they are just passed sequentially.
     
  14. cetterra

    cetterra Member

    Joined:
    Jan 5, 2009
    Messages:
    19
    Likes Received:
    0
    Trophy Points:
    1
    Uhmm.... details!!! Always the details... Now it worked!

    Thanks!
     
Loading...

Share This Page