Reading list Switch to dark mode

    OpenERP 7.0 connection with PHP using XML-RPC

    Updated 26 March 2015

    OpenERP xmlrpc

    In order to connect with openerp first of all we need XML-RPC for PHP, download the latest stable release from http://phpxmlrpc.sourceforge.net/.

    Now extract it and get the file i.e inside lib folder named as xmlrpc.inc.

    Include this file in your own php file, so that we can use it’s property.

     1) Before doing coding we need openERP base URL and it’s credentials(database_name, user_name, password)

    Start your headless eCommerce
    now.
    Find out More

    2) Now we will start with the coding

    include('xmlrpc.inc');
    
    $dbname = 'dbname';
    $user = 'admin';
    $pwd = 'pwd';
    $url = 'http://demo.openerp.com:8069'; // it's demo server url
    $sock = new xmlrpc_client("http://demo.openerp.com:8069/xmlrpc/common");
    
    $sock_msg = new xmlrpcmsg('login');
    $sock_msg->addParam(new xmlrpcval($dbname, "string"));
    $sock_msg->addParam(new xmlrpcval($user, "string"));
    $sock_msg->addParam(new xmlrpcval($pwd, "string"));
    $sock_resp = $sock->send($sock_msg);
    
    if ($sock_resp->errno != 0){
    echo  'error';
    }else{
    
    $sock_val = $sock_resp->value();
    
    $user_id = $sock_val->scalarval();
    
    }

    Note:-  when $sock_resp->errno value is equals to 0 then it’s connected with openERP otherwise something wrong in configuration.

    3) now you are successfully connected with openERP, now we will use  $user_id for further operation.

    4) here is the simple code to create a customer…

    $customer_array = array(
    'name'=>new xmlrpcval('Demo Customer', "string")
    );
    $client = new xmlrpc_client("http://demo.openerp.com:8069/xmlrpc/object");
    
    $msg = new xmlrpcmsg('execute');
    $msg->addParam(new xmlrpcval("dbname", "string"));
    $msg->addParam(new xmlrpcval($user_id, "int"));
    $msg->addParam(new xmlrpcval("demo", "string"));
    $msg->addParam(new xmlrpcval("res.partner", "string"));
    $msg->addParam(new xmlrpcval("create", "string"));
    $msg->addParam(new xmlrpcval($customer_array, "struct"));
    $resp = $client->send($msg);
    $customer_id = $resp->value()->scalarval();

    now the next operations like write, read, search etc.. will discussed in my next post.

    . . .

    Leave a Comment

    Your email address will not be published. Required fields are marked*


    Be the first to comment.

    Back to Top

    Message Sent!

    If you have more details or questions, you can reply to the received confirmation email.

    Back to Home