Skip to main content
Question
FYERS API
Bhaveshkumar Bhavsar
Fyers Authorized Partner
Asked a question 2 years ago

I am trying to get authorization code in php by REST api post request on "https://api.fyers.in/api/v1/auth" but I am get an error "{"ERROR": "No JSON object could be decoded"}"

Join FYERS Community to pick others' brains on Trading/Investing

I don't know anything about cUrl I use Java HttpUrlConnection and Okhttp class but got a translation through post man check it works for me to get auth code

 

curl --location --request POST 'https://api.fyers.in/api/v1/auth30' \

--header 'sec-fetch-dest: empty' \

--header 'sec-fetch-mode: cors' \

--header 'sec-fetch-site: same-origin' \

--header 'Content-Type: application/json' \

--data-raw '{

"app_id":"XXXXX",

"secret_key":"XXXXXX",

"create_cookie": "False"

}'

I've had to add these extra curl options for it to work.

$curl = curl_init();

curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);

curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);

curl_setopt($curl, CURLOPT_HTTPHEADER, array('Content-Type:application/json'));

curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);

curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);

check them.

Encode using json function and use app_id/secret instead of http_build_query()

I don't know where you got button submit and why you are using it.

$step1 = array('app_id'=>'XXXXX', 'secret_key'=>'YYYYY');
$post_str = json_encode( $step1 );