Page 1 of 1

subscribe users who register in another application

PostPosted: 1:44am, Fri 07 Mar, 2014
by jimlongo
I have a couple of systems and I'm trying to think of a way to tie them together a bit.

I have an online store that uses osCommerce.
Users who open an account there get email confirmations and such from the osCommerce installation. It's confusing to many of them that they don't also get broadcast emails from phpList. No matter how many places and times I instruct them to also register for the mailing list, it will get missed.

What I wish is that there was a way that new accounts opened on the osCommerce app would automatically subscribe to phpList. I would still require them to confirm the phpList subscription, so they wouldn't be subscribed without consent.

Anyone have any ideas on how I could accomplish this?

Thanks.

Re: subscribe users who register in another application

PostPosted: 10:34pm, Sat 08 Mar, 2014
by jimlongo
I'm looking into the restapi and it might work for me, except for the fact you need to be logged in to run anything.

I think i'm going to try this approach.
When the user submits their registration data to osCommerce, I will take the email and

->directly query the phpList db to
check if the email already exists
find the last id
add the user email
add the list(s)
mark confirmed.

Feel free to comment if you have a better idea.

Re: subscribe users who register in another application

PostPosted: 10:52pm, Sat 08 Mar, 2014
by jimlongo
Just came across this . . . viewtopic.php?f=7&t=5009&hilit=adding+user+to+database+confirmation and although it's fairly old it might offer some ideas.

Re: subscribe users who register in another application

PostPosted: 10:23am, Sun 09 Mar, 2014
by duncanc
I would still require them to confirm the phpList subscription, so they wouldn't be subscribed without consent.

Your approach isn't going to make phplist send the confirmation email. If you really want to do that then you will need to mimic submitting a subscribe page, using curl, so that phplist treats it as a real subscription.
I'm looking into the restapi and it might work for me, except for the fact you need to be logged in to run anything.

You might be misunderstanding how the restapi works. In your OS commerce code you would make calls to the API. The first API method that you need to call is to 'login' to phplist with an admin/password. After that you make calls to add a user, etc.

Re: subscribe users who register in another application

PostPosted: 10:36pm, Sun 09 Mar, 2014
by jimlongo
duncanc wrote:
I'm looking into the restapi and it might work for me, except for the fact you need to be logged in to run anything.

You might be misunderstanding how the restapi works. In your OS commerce code you would make calls to the API. The first API method that you need to call is to 'login' to phplist with an admin/password. After that you make calls to add a user, etc.


It sounds promising if only I could login, to get started.
Here's my rest_test.php file, all it has is the method to login and getLists, when I run this I get nothing . . .
Code: Select all
<?php
/**
 * Class to communicate with phpList via API REST
 *
 **/
class phpList_RESTAPI_Test {

    private $session = null;
    private $url = 'http://mydomain.com/list/plugins/restapi/restapi.php';

    function __construct($url) {
        $this->url = $url;
    }

    private function setSessionID($sid){
        $this->session = $sid;
    }

    public function getSessionID(){
        return $this->session;
    }

    /************************************************************
     * Administrators Operation
     ************************************************************/

    /**
     * @param $loginname
     * @param $password
     * @return mixed
     */
    public function login( $login, $password ) {

        //Post Data
        $post_params = array(
            'login' => $login,
            'password' => $password
        );

        $result = $this->callAPI( 'login', $post_params);

        if ( $result->status == 'success' ) {
            $this->setSessionID( $result->data );
            return $result;
        }

        return $result;
    }

    /************************************************************
     * Lists
     ************************************************************/
    public function listsGet( ) {

        //Post Data
        $post_params = array(
        );

        $result = $this->callAPI( 'listsGet', $post_params);

        return $result;
    }



    /************************************************************
     * Remote Requests via cUrl or other
     ************************************************************/

    private function callAPI($command, $post_params, $no_decode=false ) {

        $post_params['cmd'] = $command;

        $post_params = http_build_query($post_params);

        $c = curl_init();
        curl_setopt($c, CURLOPT_URL,            $this->url );
        curl_setopt($c, CURLOPT_HEADER,         0);
        curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($c, CURLOPT_POST,           1);
        curl_setopt($c, CURLOPT_POSTFIELDS,     $post_params);
        curl_setopt($c, CURLOPT_COOKIEFILE,     $GLOBALS['tmpdir'].'/phpList_RESTAPI_Helper_cookiejar.txt');
        curl_setopt($c, CURLOPT_COOKIEJAR,      $GLOBALS['tmpdir'].'/phpList_RESTAPI_Helper_cookiejar.txt');
        curl_setopt($c, CURLOPT_HTTPHEADER,     array( 'Connection: Keep-Alive', 'Keep-Alive: 60' ));

        $result = curl_exec($c);

        if ( !$no_decode ) $result = json_decode($result);

        return $result;
    }
}