AnsweredAssumed Answered

How to insert an image using the set_entry method

Question asked by ivangomez on Sep 2, 2015
Latest reply on Oct 17, 2015 by Manuel Delgadillo
I need to insert an image when I create a new record. I know how to do it with fields of type varchar but not with image.

This is my code:

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;
}

function set_datos_crm($lista_valores) {
    //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);

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

    //retrieve fields --------------------------------
    $set_entry_parameters = array(
        //session id
        'session' => $session_id,

        //The name of the module from which to retrieve records
        'module_name' => 'Leads',

        //Record attributes
        'name_value_list' => array(
        array(
            'name'  => 'first_name',
            'value' => 'John'
        ),
        array(
            'name'  => 'last_name',
            'value' => 'Doe'
        ),
        ...
    );

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

Thanks.

Outcomes