Generating Postman preview from PHP

So i've been trying to use the suiteCRM REST API but i keep getting stuck every time i tried to authenticate to the API and everything i tried seems to fail, so now i been trying to reverse engineer a code snippet that i found 1 in PHP. the code works when i runt it, but now i'm trying to use it in postman but a i get "invalid login"...i would really appreciate it if you can see what i'm missing

The code

<?php

$url = "https://demo.suiteondemand.com/service/v4_1/rest.php";
$username = "will";
$password = "will";

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

What i've tried

enter image description here

any help on this is greatly appreciate it.

Answer

Answer

Answer

Answer

$login_parameters = array( "user_auth" => array( "user_name" => $username, "password" => md5($password), "version" => "1" ), "application_name" => "RestTest", "name_value_list" => array(), ); echo "++++++++++"; echo md5($password); $login_result = call("login", $login_parameters, $url); echo "<pre>"; print_r($login_result); //nothing echo "</pre>"; //get session id $session_id = $login_result->id; echo "<pre>"; echo "****************"; print_r($session_id); //nothing echo "</pre>";

Answer

Solution:

Send your data as JSON:

Postman Example

If this doesn't work, show your request and response header please.

Source