curl https://api.kite.trade/session/token not working

karthikeyan17
Hi Zerodha,

Please tell me how to get access token using php curl.When i run below script, i get below error:

Actually i saw below sample code snippet in https://kite.trade/docs/connect/v3/user/ but it not working in POSTMAN application, please provide informations to fix this curl issue.

curl https://api.kite.trade/session/token \
-H "X-Kite-Version: 3" \
-d "api_key=xxx" \
-d "request_token=yyy" \
-d "checksum=zzz"


Error:
stdClass Object
(
[status] => error
[message] => `api_key` should be minimum 6 characters in length.
[data] =>
[error_type] => InputException
)


Code snippet:
if(isset($_GET["status"]) && $_GET["status"] == "success" && isset($_GET["request_token"]) && (($requestToken = $_GET["request_token"]) != "")) {

$postData = array();
$postData["api_key"] = APIKey;
$postData["request_token"] = $requestToken;
$postData["checksum"] = hash('sha256',APIKey.$requestToken.APISecret);

$headerData = array('Content-type: application/x-www-form-urlencoded','User-Agent: phpkiteconnect/3.2.0','X-Kite-Version: 3');


$cuObj = curl_init("https://api.kite.trade/session/token");
$payload = json_encode($postData);
//$payload1 = json_encode($headerData);
curl_setopt($cuObj, CURLOPT_POST, true);
curl_setopt($cuObj, CURLOPT_HTTPHEADER, $headerData);
curl_setopt($cuObj, CURLOPT_POSTFIELDS, $postData);
curl_setopt($cuObj, CURLOPT_RETURNTRANSFER, true);
curl_setopt($cuObj, CURLOPT_SSL_VERIFYPEER, false);
$result = json_decode(curl_exec($cuObj));

echo "
";
print_r($result);
echo "
";
curl_close($cuObj);

exit();
}
Sign In or Register to comment.