1

Topic: Use of API in php...

Hello.

I need to use iRedMail API in a php script, but I've just little experience in curl and, after several unsuccessfull tries, I get confused...

Does exist any sample php code which shows how to call iRedMail API ?!?!

Thank you...

----

Spider Email Archiver: On-Premises, lightweight email archiving software developed by iRedMail team. Supports Amazon S3 compatible storage and custom branding.

2

Re: Use of API in php...

Any errors?

(incomplete) PHP code looks like below:

        USERNAME = "admin@mydomain.com";
        PASSWORD = "mypassword";
        
        //login
        $curl = curl_init();

        $data = array('username'=>USERNAME, 'password'=>PASSWORD);
        $post = http_build_query($data);
        
        curl_setopt_array($curl, array(
          CURLOPT_URL => "https://domain.com/iredadmin/api/login",
          CURLOPT_CUSTOMREQUEST => "POST",
          CURLOPT_POSTFIELDS => $post,
          CURLOPT_SSL_VERIFYHOST=>false,
          CURLOPT_SSL_VERIFYPEER=>false,
          CURLOPT_COOKIEJAR=>dirname(__FILE__) . "/cookies.txt",
        ));

        $response = curl_exec($curl);
        $err = curl_error($curl);

        curl_close($curl);
        
        //add user
        $email = "test1@mydomain.com";

        $curl = curl_init();
        
        $data = array(
            'name'=>"Test", 
            'password'=>"my-complex-password-@*/)",
            'language'=>'en_US'
            );
        $post = http_build_query($data);
        
        curl_setopt_array($curl, array(
          CURLOPT_URL => "https://domain.com/iredadmin/api/user/".$email,
          CURLOPT_CUSTOMREQUEST => "POST",
          CURLOPT_POSTFIELDS => $post,
          CURLOPT_SSL_VERIFYHOST=>false,
          CURLOPT_SSL_VERIFYPEER=>false,
          CURLOPT_COOKIEFILE=>dirname(__FILE__) . "/cookies.txt",
        ));

        $response = curl_exec($curl);
        $err = curl_error($curl);

        curl_close($curl);
        
        if ($err) {
          echo "cURL Error #:" . $err;
        } else {
            echo '<pre>';
            print_r( $response);
            echo '</pre>';
        }

3

Re: Use of API in php...

My friend wrote a complete PHP class for iRedAdmin-Pro-API with documentation and examples. It is and will be up to date with the latest iRedAdmin. Hope it helps somebody.

https://github.com/Bezlaj/PHPiRedAdminProAPI

Greetings