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.

php example uapi?

Discussion in 'cPanel Developers' started by jeffschips, Jun 12, 2016.

Tags:
  1. jeffschips

    jeffschips Member

    Joined:
    Jun 5, 2016
    Messages:
    12
    Likes Received:
    0
    Trophy Points:
    1
    Location:
    new york
    cPanel Access Level:
    Root Administrator
    Hello.

    I am new and trying to use the uapi php functionality to create email filters. The examples given in the documentation at this link, do not run when I use my code, below. I wish to execute this from the command line.

    when running the file as: php test.livephp no errors come back but no filters are created either.

    What am I doing wrong?


    Code:
    <?php
    
    include("/usr/local/cpanel/php/cpanel.php");
    
    $cpanel = &new CPANEL();
    
    $new_filter = $cpanel->uapi(
        'Email', 'store_filter',
        array(
            'filtername'      => 'coffee',
            'account'         => 'name@thedomain.com',
            'action1'         => 'deliver',
            'dest1'           => 'anothername@thedomain.com',
            'part1'           => '$header_subject:',
            'match1'          => 'contains',
            'val1'            => 'curds',
            'opt1'            => 'or',
            'part2'           => '$message_body',
            'match2'          => 'is',
            'val2'            => 'whey',
             )
    );
    
    ?>
    
     
    #1 jeffschips, Jun 12, 2016
    Last edited by a moderator: Jun 13, 2016
  2. sparek-3

    sparek-3 Well-Known Member

    Joined:
    Aug 10, 2002
    Messages:
    1,383
    Likes Received:
    23
    Trophy Points:
    38
    cPanel Access Level:
    Root Administrator
    If you are going to be doing this from the command-line, why not just use the /usr/local/cpanel/bin/uapi binary?
     
  3. jeffschips

    jeffschips Member

    Joined:
    Jun 5, 2016
    Messages:
    12
    Likes Received:
    0
    Trophy Points:
    1
    Location:
    new york
    cPanel Access Level:
    Root Administrator
    You raise an option which I have tried and the binary on the command line works, but I need to pass variables set by administrator to the binary, so I figured a php script will do that.

    Also, I've tried calling the binary from a bash script and can't get that to work either.

    Any options viable for passing variables I'll consider.

    Thank you!
     
  4. cPanelMichael

    cPanelMichael Forums Analyst
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    30,834
    Likes Received:
    672
    Trophy Points:
    113
    cPanel Access Level:
    Root Administrator
    Hello,

    Could you let us know the specific command you used? Did you utilize URI-encode values?

    Thank you.
     
Loading...

Share This Page