access token api request Unauthorized Bad credentials

hamzakhanhamzakhan Member Posts: 25

Please guide and help I am getting below response

{

  "timestamp": 1631098214245,

  "status": 401,

  "error": "Unauthorized",

  "message": "Bad credentials",

  "path": "/oauth/token"

}


my code


<?php

$authorization_code = "";

$client_id = "";

$clientSecret = "";

$redirect_uri = "";


$str = $client_id.":".$clientSecret; // combine and encode client_id:securet_id

$header = base64_encode($str);

$ch = curl_init();


curl_setopt($ch, CURLOPT_URL, 'https://api.lsk.lightspeed.app/oauth/token?code='.$authorization_code.'&grant_type=authorization_code&client_id='.$client_id.'&redirect_uri='.$redirect_uri);

curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

curl_setopt($ch, CURLOPT_POST, 1);


$headers = array();

$headers[] = 'Authorization: Basic '.$header;

curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);


$result = curl_exec($ch);

if (curl_errno($ch)) {

  echo 'Error:' . curl_error($ch);

}

curl_close($ch);



echo "<pre>";

var_dump($result);

Sign In or Register to comment.