Hashing Error: Please provide sha256 hash of appId and app secret Can someone suggest me am i correctly generating sha 256? from hashlib import sha256 import http.client import json api_id = 'QXXXY5PTC3-100' app_secret = '2MXXX7J1I4' appId_secret = a

Hashing Error: Please provide sha256 hash of appId and app secret

Can someone suggest me am i correctly generating sha 256?

from hashlib import sha256
import http.client
import json

api_id = ‘QXXXY5PTC3-100’
app_secret = ‘2MXXX7J1I4’

appId_secret = api_id+app_secret
h = sha256(appId_secret.encode(“utf-8”))
appIdHash = h.hexdigest()

conn = http.client.HTTPSConnection(“api.fyers.in”)
payload = json.dumps({
“grant_type”: “authorization_code”,
“appIdHash”: appIdHash,
“code”: auth_code
})
headers = {
‘Content-Type’: ‘application/json’
}
conn.request(“POST”, “/api/v2/validate-authcode”, payload, headers)
res = conn.getresponse()
data = res.read()
print(data.decode(“utf-8”))

{“s”: “error”, “code”: -371, “message”: “Please provide sha256 hash of appId and app secret”}

Hi Lohitha,
I would suggest to use this site - https://emn178.github.io/online-tools/sha256.html
enter the app_id:access_token in the input and check if it matches with the one you are generating.

Edit: Do check the given python script, comment/uncomment the function calls as needed,

from fyers_api import fyersModel
from fyers_api import accessToken
import webbrowser

def generate_auth_code(client_id, secret_key, redirect_uri, response_type):
	session = accessToken.SessionModel(client_id=client_id, secret_key=secret_key, redirect_uri=redirect_uri, response_type=response_type)
	auth_code_url = session.generate_authcode()
	[webbrowser.open](http://webbrowser.open)(auth_code_url,new=1)

def generate_access_token(auth_code, client_id, secret_key, redirect_uri, response_type, grant_type):
	session = accessToken.SessionModel(client_id=client_id, secret_key=secret_key, redirect_uri=redirect_uri, response_type=response_type, grant_type=grant_type)
	session.set_token(auth_code)
	response = session.generate_token()
	access_token = response["access_token"]
	print(access_token)

def data_api_call(client_id, access_token):
	fyers = fyersModel.FyersModel(token=access_token,is_async=False, log_path="/home/user/fyers/fyers-api/logs",client_id=client_id) # Enter you desired log path store the logs on your system
	
	print(fyers.get_profile())
	print()

	history_data = {"symbol":"NSE:SBIN-EQ","resolution":"D","date_format":"0","range_from":"1622097600","range_to":"1622097685","cont_flag":"1"}
	print(fyers.history(history_data))
	print()

	quotes_data = {"symbols": "NSE:SBIN-EQ"}
	print(fyers.quotes(quotes_data))

def main():	
	# enter your client ID (i.e., the app ID)
	client_id = ""

	# Enter the secret key of your app 
	secret_key = ""

	redirect_uri = "[https://trade.fyers.in/api-login/redirect-uri/index.html](https://trade.fyers.in/api-login/redirect-uri/index.html)"
	response_type = "code"

	generate_auth_code(client_id, secret_key, redirect_uri, response_type)

	auth_code = ""
	grant_type = "authorization_code"
	generate_access_token(auth_code, client_id, secret_key, redirect_uri, response_type, grant_type)

	access_token = ""
	data_api_call(client_id, access_token)

if __name__ == '__main__':
	main()

Thanks for the response @vikram_sri , checked both and are matching. Let me take one step back and check whether authorization step1 is correct or not ( https://myapi.fyers.in/docs/#tag/Authentication-and-Login-Flow-User-Apps/paths/~1Authentication%20&%20Login%20Flow%20-%20User%20Apps/patch )

In step1, I tried to convert below cURL with Postman but throwing “Error while importing: format not recognized” error. Can you help me with correct cURL or equalent python code.

https://api.fyers.in/api/v2/generate-authcode?client_id=sample_client_id& redirect_uri=sample_redirect_uri&response_type=code&state=sample_state

For example:
cURL: curl -H “Authorization:app_id:access_token” https://api.fyers.in/api/v2/profile
equalent Python code:

import http.client

conn = http.client.HTTPSConnection(“api.fyers.in”)
payload = ‘’
headers = {
‘Authorization’: ‘app_id:access_token’
}
conn.request(“GET”, “/api/v2/profile”, payload, headers)
res = conn.getresponse()
data = res.read()
print(data.decode(“utf-8”))

Hi Lohitha,
I’ll paste a python script in my answer, do have a look.

Thanks for the response @vikram_sri . I’m deploying my app in AWS. Facing challenges while installing fyers_api package in AWS, tried to upload manually but another issue, so decided to use light version of the API calls (only http client calls, this is default in AWS).

in simple, If i get python code for step1 in authorization will fixes all. (Actually this format from the official document is not correct).

https://api.fyers.in/api/v2/generate-authcode?client_id=sample_client_id& redirect_uri=sample_redirect_uri&response_type=code&state=sample_state

for AWS, have you tried installing the packing in this way,
python3 -m pip install fyers-apiv2
or with sudo,
sudo python3 -m pip install fyers-apiv2
I also used to face issues in the beginning while installing packages in AWS.

yes, @vikram_sri used the same.

Is it possible to valid format cURL for step1 in authorization?

https://api.fyers.in/api/v2/generate-authcode?client_id=sample_client_id& redirect_uri=sample_redirect_uri&response_type=code&state=sample_state

Ref:
https://myapi.fyers.in/docs/#tag/Authentication-and-Login-Flow-User-Apps/paths/~1Authentication%20&%20Login%20Flow%20-%20User%20Apps/post

@vikram_sri I spent 2hrs to install in AWS but some or other error. This is the road blocker for my app, pushing me to switch to another broker.

Since it is for all users, Can you check with corresponding team and get valid cURL for step1 in authorization?

@U7vAwty8xg and @vikram_sri I am also trying to migrate from v1 to v2 and I am also using the same tool which you have suggested. I am getting the same error. Do you have any sample code in node.js?

Did you find a fix for this? Their documentation is so poor, it doesn’t even show where to pass it as a parameter.