Results 1 to 2 of 2

Thread: How to add users using the SOAP service?

  1. #1
    magick93 Guest

    Default How to add users using the SOAP service?

    Hi

    I'm trying to integrate Sugar into our java app.

    I am looking at the wsdl, and cannot see any obvious method for adding users.

    Can someone enlighten me?

  2. #2
    dkallish@sugarcrm.com Guest

    Default Re: How to add users using the SOAP service?

    Hello,

    I was able to modify the following Developer Guide example - Creating or Updating a Record - REST and PHP - SugarCRM Support Site

    This example is using the REST web service. I would recommend switching to REST, for performance and longevity purposes. Here is the script I used:

    <?php

    $url = "http://{Site URL}/service/v4/rest.php";
    $username = "Username";
    $password = "Password";

    //function to make cURL request
    function call($method, $parameters, $url)
    {
    ob_start();
    $curl_request = curl_init();

    curl_setopt($curl_request, CURLOPT_URL, $url);
    curl_setopt($curl_request, CURLOPT_POST, 1);
    curl_setopt($curl_request, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
    curl_setopt($curl_request, CURLOPT_HEADER, 1);
    curl_setopt($curl_request, CURLOPT_SSL_VERIFYPEER, 0);
    curl_setopt($curl_request, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($curl_request, CURLOPT_FOLLOWLOCATION, 0);

    $jsonEncodedData = json_encode($parameters);

    $post = array(
    "method" => $method,
    "input_type" => "JSON",
    "response_type" => "JSON",
    "rest_data" => $jsonEncodedData
    );

    curl_setopt($curl_request, CURLOPT_POSTFIELDS, $post);
    $result = curl_exec($curl_request);
    curl_close($curl_request);

    $result = explode("\r\n\r\n", $result, 2);
    $response = json_decode($result[1]);
    ob_end_flush();

    return $response;
    }

    //login ------------------------------------------------

    $login_parameters = array(
    "user_auth"=>array(
    "user_name"=>$username,
    "password"=>md5($password),
    "version"=>"1"
    ),
    "application_name"=>"RestTest",
    "name_value_list"=>array(),
    );

    $login_result = call("login", $login_parameters, $url);

    /*
    echo "<pre>";
    print_r($login_result);
    echo "</pre>";
    */

    //get session id
    $session_id = $login_result->id;

    //create account ----------------------------------------

    $set_entry_parameters = array(
    //session id
    "session" => $session_id,

    //The name of the module from which to retrieve records.
    "module_name" => "Users",

    //Record attributes
    "name_value_list" => array(
    //to update a record, you will nee to pass in a record id as commented below
    //array("name" => "id", "value" => "<Record's ID Value>"),
    array("name" => "user_name", "value" => "jdoe"),
    array("name" => "user_hash", "value" => "839ba8d071c895fa34fee16d75c67634"),
    array("name" => "first_name", "value" => "John"),
    array("name" => "last_name", "value" => "Doe"),
    array("name" => "is_admin", "value" => "0"),
    array("name" => "default_team", "value" => "1"),
    array("name" => "status", "value" => "Active"),
    ),
    );

    $set_entry_result = call("set_entry", $set_entry_parameters, $url);

    echo "<pre>";
    print_r($set_entry_result);
    echo "</pre>";

    ?>

    This will create a Regular User, jdoe, John Doe, with the password Sugar123! (the password value was piped through an MD5 Hash generator), with an Active status, and their default team set to Global. Each of the 'name / value' pairs is a database value in the 'users' table so you can grab database column names and add them to the example as needed. For more examples definitely check out the Web Services section of the SugarCRM Support site - Web Services - SugarCRM Support Site

    Kind regards,

    Dan Kallish
    SugarCRM Technical Support Engineer

Thread Information

Users Browsing this Thread

There are currently 2 users browsing this thread. (0 members and 2 guests)

Similar Threads

  1. Replies: 4
    Last Post: 2013-09-16, 08:21 AM
  2. Adding New Soap Service
    By aspeno in forum Developer Help
    Replies: 2
    Last Post: 2012-02-02, 12:15 PM
  3. How fetch record using SOAP web service
    By shajiuddin in forum Developer Help
    Replies: 3
    Last Post: 2011-12-29, 04:42 AM
  4. SOAP web service endpoint
    By awara in forum Help
    Replies: 0
    Last Post: 2010-02-25, 07:07 PM
  5. Benefits of SOAP Web Service over ADO?
    By WizRider in forum Developer Help
    Replies: 3
    Last Post: 2007-06-21, 03:17 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •