K
@Moderator_1 Hi Team, I am also getting the same error.
Response: {'success': False, 'message': 'Invalid API Key', 'errorCode': 'AG8004', 'data': ''}.
Below is the code I tried. Could you please help
import requests
Define the API endpoint
url = "https://apiconnect.angelbroking.com/rest/secure/angelbroking/marketData/v1/gainersLosers"
Define the headers (replace with actual values as required)
headers = {
"Authorization": "Bearer eyJhbGciOiJIUzxxxxxxx", #token
"Content-Type": "application/json",
"Accept": "application/json"
}
Define the request packet
payload = {
"datatype": "PercPriceGainers", # datatype
"expirytype": "NEAR" # expiry type
}
Send the POST request
response = requests.post(url, headers=headers, json=payload)
Check the response
if response.status_code == 200:
print("Request Successful")
print("Response:", response.json())
else:
print(f"Request Failed with status code {response.status_code}")
print("Response:", response.text)