You need to sign in to do that
Don't have an account?
Ismael Acevedo
Error Rest API
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); ?>
All Answers
Error: call to URL https://login.salesforce.com/services/oauth2/token failed with status 400, curl_error , curl_errno 0