I’ve been trying to use Algolia’s rest-api with python request but even though im getting a status 200, my json always returns None ie: {‘countries’: None}. Here is the documentation Analytics REST API Reference | Algolia . The python api exists but for the analytics section you need to use the rest-api, here is the python api: algoliasearch-client-python/configs.py at master · algolia/algoliasearch-client-python · GitHub
I tried looking at the headers in the python api to see if it would help.
Here is an example curl requests from the documentation:
curl -X GET \
-H "X-Algolia-API-Key: ${API_KEY}" \
-H "X-Algolia-Application-Id: ${APPLICATION_ID}" \
"https://analytics.algolia.com/2/status?index=${index name}"
Here is my code using requests:
import requests
from datetime import date
import json
class AutoAlgolia():
def __init__(self, api_key, application_id, index_name):
self.api_key = api_key
self.application_id = application_id
self.index_name = index_name
def _headers(self):
header = {
'X-Algolia-API-Key': self.api_key,
'X-Algolia-Application-Id': self.application_id ,
"Content-Type": "application/json"
}
return header
def getsearches(self):
header = self._headers()
today = date.today().isoformat()
session = requests.Session()
url = "https://analytics.algolia.com/2/searches/noResults?index=" + self.index_name + "&startDate=" + today + "&endDate=" +"2022-09-03"
req = session.get(url, headers=header)
print(req.status_code)
data = req.json()
print(data)
if __name__ == "__main__":
algolia = AutoAlgolia(api_key="key
", application_id="id", index_name="si_SOLUTIONS")
a = algolia.getsearches()
print(a) `
I also checked using req.headers what could be wrong but i do not fully understand it:
{'Date': 'Thu, 01 Dec 2022 16:17:00 GMT', 'Content-Type': 'application/json', 'Content-Length': '17', 'Connection': 'keep-alive', 'Access-Control-Allow-Origin': '', 'Vary': 'Origin', 'X-Ratelimit-Limit': '100', 'X-Ratelimit-Remaining': '99', 'X-Ratelimit-Reset': '1669911480', 'Via': '1.1 google', 'CF-Cache-Status': 'DYNAMIC', 'Strict-Transport-Security': 'max-age=31536000; includeSubDomains; preload', 'Server': 'cloudflare', 'CF-RAY': '772d216aaf1001db-ZRH'} ```
Could it be the access-control-allow-origin which is empty?
Thank you, I greatly appreciate any help
Tried:
Using different headers, reading the python api doc to see if there could be any similarities to the rest api, tried urllib3 (same result), tried other webhooks from the rest api.