• Ismael Acevedo
  • NEWBIE
  • 0 Points
  • Member since 2017

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 3
    Replies
Can you help me ,the error that i get is Error: call to URL https://login.salesforce.com/services/oauth2/token failed with status 0
 
<?php

$id=$_POST["id"];
define("CLIENT_ID", "");
define("CLIENT_SECRET", '');
define("LOGIN_URI", "https://login.salesforce.com");

//define("SF_SECURITY_TOKEN", "");
define("USERNAME", "");
define("PASSWORD", "");

function salesforce_login($username, $password) {
    $params = "grant_type=password&client_id=".CLIENT_ID.
            "&client_secret=".CLIENT_SECRET.
            "&username=$username&password=$password";

    $token_url = LOGIN_URI . "/services/oauth2/token";

    $curl = curl_init($token_url);
    curl_setopt($curl, CURLOPT_HEADER, false);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($curl, CURLOPT_POST, true);
    curl_setopt($curl, CURLOPT_POSTFIELDS, $params);
    $json_response = curl_exec($curl);
    $status = curl_getinfo($curl, CURLINFO_HTTP_CODE);
    if ( $status != 200 ) {
        die("Error: call to URL $token_url failed with status $status");
    }

    return json_decode($json_response, true);
}

$response = salesforce_login(USERNAME, PASSWORD);
$access_token = $response["access_token"];
$instance_url = $response["instance_url"];

$user = $id;
$url = "$instance_url/services/data/v20.0/sobjects/User/$user";

$content = json_encode(array("IsActive" => false));

$curl = curl_init($url);
curl_setopt($curl, CURLOPT_HEADER, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HTTPHEADER,
        array("Authorization: OAuth $access_token",
            "Content-type: application/json"));
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "PATCH");
curl_setopt($curl, CURLOPT_POSTFIELDS, $content);

$response = curl_exec($curl);

$status = curl_getinfo($curl, CURLINFO_HTTP_CODE);

if ( $status != 204) {
    die("Error: call to URL $url failed with status $status, response $response\n");
}

echo "Successfully updated user $user\n";

// -------------------Send message to the ajax--------------------------
$response = array('status' => $status);
echo json_encode($response);

curl_close($curl);
?>

 
Can you help me ,the error that i get is Error: call to URL https://login.salesforce.com/services/oauth2/token failed with status 0
 
<?php

$id=$_POST["id"];
define("CLIENT_ID", "");
define("CLIENT_SECRET", '');
define("LOGIN_URI", "https://login.salesforce.com");

//define("SF_SECURITY_TOKEN", "");
define("USERNAME", "");
define("PASSWORD", "");

function salesforce_login($username, $password) {
    $params = "grant_type=password&client_id=".CLIENT_ID.
            "&client_secret=".CLIENT_SECRET.
            "&username=$username&password=$password";

    $token_url = LOGIN_URI . "/services/oauth2/token";

    $curl = curl_init($token_url);
    curl_setopt($curl, CURLOPT_HEADER, false);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($curl, CURLOPT_POST, true);
    curl_setopt($curl, CURLOPT_POSTFIELDS, $params);
    $json_response = curl_exec($curl);
    $status = curl_getinfo($curl, CURLINFO_HTTP_CODE);
    if ( $status != 200 ) {
        die("Error: call to URL $token_url failed with status $status");
    }

    return json_decode($json_response, true);
}

$response = salesforce_login(USERNAME, PASSWORD);
$access_token = $response["access_token"];
$instance_url = $response["instance_url"];

$user = $id;
$url = "$instance_url/services/data/v20.0/sobjects/User/$user";

$content = json_encode(array("IsActive" => false));

$curl = curl_init($url);
curl_setopt($curl, CURLOPT_HEADER, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HTTPHEADER,
        array("Authorization: OAuth $access_token",
            "Content-type: application/json"));
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "PATCH");
curl_setopt($curl, CURLOPT_POSTFIELDS, $content);

$response = curl_exec($curl);

$status = curl_getinfo($curl, CURLINFO_HTTP_CODE);

if ( $status != 204) {
    die("Error: call to URL $url failed with status $status, response $response\n");
}

echo "Successfully updated user $user\n";

// -------------------Send message to the ajax--------------------------
$response = array('status' => $status);
echo json_encode($response);

curl_close($curl);
?>

 

Hi,

 

I have also 2 other questions.

Using rest apis, how do I change and/or reset a user password? (Do you have a code sample showing which property to set, if password is sent plain text, encoded, hashed etc...)

 

Also, how do I "disable" an account using the REST apis?

 

Thank you very much for your help.